sparse, llvm: FP comparison op code generation
PATCH 1/1 sparse, llvm: FP comparison op code generation
This patch implements code generation for floating point versions of OP_BINCMP.
Cc Linus Torvalds <[email protected]>
Cc Christopher Li <[email protected]>
Cc Jeff Garzik <[email protected]>
Signed-off-by Pekka Enberg <[email protected]>
--- sparse-llvm.c | 29 +++++++++++++++++++++++++++-- validation/backend/cmp-ops.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 2 deletions(-)
sparse-llvm.c +27 -2
@@ -391,6 +391,25 @@ static LLVMTypeRef pseudo_type(struct function *fn, struct instruction *insn, psreturn result; } +static LLVMRealPredicate translate_fop (int opcode) +{ +static const LLVMRealPredicate trans_tbl[] = { + [OP_SET_EQ ] = LLVMRealOEQ, + [OP_SET_NE ] = LLVMRealUNE, + [OP_SET_LE ] = LLVMRealOLE, + [OP_SET_GE ] = LLVMRealOGE, + [OP_SET_LT ] = LLVMRealOLT, + [OP_SET_GT ] = LLVMRealOGT, +/* Are these used with FP? */ + [OP_SET_B ] = LLVMRealOLT, + [OP_SET_A ] = LLVMRealOGT, + [OP_SET_BE ] = LLVMRealOLE, + [OP_SET_AE ] = LLVMRealOGE, + }; + +return trans_tbl[opcode]; +} +static LLVMIntPredicate translate_op (int opcode) {static const LLVMIntPredicate trans_tbl[] = {
@@ -512,9 +531,15 @@ static void output_op_binary(struct function *fn, struct instruction *insn)/* Binary comparison */ case OP_BINCMP ... OP_BINCMP_END: { -LLVMIntPredicate op =translate_op (insn->opcode); +if (LLVMGetTypeKind (LLVMTypeOf (lhs)) == LLVMIntegerTypeKind) { +LLVMIntPredicate op =translate_op (insn->opcode); - target =LLVMBuildICmp (fn->builder, op, lhs, rhs, target_name); + target =LLVMBuildICmp (fn->builder, op, lhs, rhs, target_name); + }else { +LLVMRealPredicate op =translate_fop (insn->opcode); + + target =LLVMBuildFCmp (fn->builder, op, lhs, rhs, target_name); + }break ; }default :
validation/backend/cmp-ops.c +30 -0
@@ -48,6 +48,36 @@ static int setae(unsigned int x, unsigned int y)return x >= y; } +static int setfe (float x,float y) +{ +return x == y; +} + +static int setfne (float x,float y) +{ +return x != y; +} + +static int setfl (float x,float y) +{ +return x < y; +} + +static int setfg (float x,float y) +{ +return x > y; +} + +static int setfle (float x,float y) +{ +return x <= y; +} + +static int setfge (float x,float y) +{ +return x >= y; +} +/* * check-name: Comparison operator code generation * check-command: ./sparsec -c $file -o tmp.o
Signature · 1 line
1.7.6.4