Refine the FCMP_ORD and FCMP_UNO.
authorYang Rong <rong.r.yang@intel.com>
Mon, 24 Mar 2014 09:21:40 +0000 (17:21 +0800)
committerZhigang Gong <zhigang.gong@intel.com>
Tue, 25 Mar 2014 05:21:29 +0000 (13:21 +0800)
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 <rong.r.yang@intel.com>
Reviewed-by: "Song, Ruiling" <ruiling.song@intel.com>
Reviewed-by: Zhigang Gong <zhigang.gong@linux.intel.com>
backend/src/llvm/llvm_gen_backend.cpp

index 1090f97..94e5ad2 100644 (file)
@@ -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<ConstantFP>(I.getOperand(0)))
+          ctx.EQ(type, dst, src1, src1);
+        else if(isa<ConstantFP>(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<ConstantFP>(I.getOperand(0)))
+          ctx.NE(type, dst, src1, src1);
+        else if(isa<ConstantFP>(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);