From 3255c789eb904c11279de40326d2ec9c7b43cb13 Mon Sep 17 00:00:00 2001 From: Yang Rong Date: Mon, 24 Mar 2014 17:21:40 +0800 Subject: [PATCH] Refine the FCMP_ORD and FCMP_UNO. If there is a constant between src0 and src1 of FCMP_ORD/FCMP_UNO, the constant value must be ordered, otherwise, llvm will optimize the instruction to ture/false. So discard this constant value, only compare the other src. Signed-off-by: Yang Rong Reviewed-by: "Song, Ruiling" Reviewed-by: Zhigang Gong --- backend/src/llvm/llvm_gen_backend.cpp | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/backend/src/llvm/llvm_gen_backend.cpp b/backend/src/llvm/llvm_gen_backend.cpp index 1090f97..94e5ad2 100644 --- a/backend/src/llvm/llvm_gen_backend.cpp +++ b/backend/src/llvm/llvm_gen_backend.cpp @@ -1654,10 +1654,26 @@ namespace gbe case ICmpInst::FCMP_OGE: ctx.GE(type, dst, src0, src1); break; case ICmpInst::FCMP_OLT: ctx.LT(type, dst, src0, src1); break; case ICmpInst::FCMP_OGT: ctx.GT(type, dst, src0, src1); break; - case ICmpInst::FCMP_ORD: ctx.ORD(type, dst, src0, src1); break; + case ICmpInst::FCMP_ORD: + //If there is a constant between src0 and src1, this constant value + //must ordered, otherwise, llvm will optimize the instruction to ture. + //So discard this constant value, only compare the other src. + if(isa(I.getOperand(0))) + ctx.EQ(type, dst, src1, src1); + else if(isa(I.getOperand(1))) + ctx.EQ(type, dst, src0, src0); + else + ctx.ORD(type, dst, src0, src1); + break; case ICmpInst::FCMP_UNO: - ctx.ORD(type, tmp, src0, src1); - ctx.XOR(insnType, dst, tmp, getRegister(cv)); //TODO: Use NOT directly + if(isa(I.getOperand(0))) + ctx.NE(type, dst, src1, src1); + else if(isa(I.getOperand(1))) + ctx.NE(type, dst, src0, src0); + else { + ctx.ORD(type, tmp, src0, src1); + ctx.XOR(insnType, dst, tmp, getRegister(cv)); //TODO: Use NOT directly + } break; case ICmpInst::FCMP_UEQ: ctx.NE(type, tmp, src0, src1); -- 2.7.4