It's safe to fold not of fcmp.
authorNick Lewycky <nicholas@mxc.ca>
Mon, 6 Aug 2007 20:04:16 +0000 (20:04 +0000)
committerNick Lewycky <nicholas@mxc.ca>
Mon, 6 Aug 2007 20:04:16 +0000 (20:04 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@40870 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/InstructionCombining.cpp
test/Transforms/InstCombine/not-fcmp.ll [new file with mode: 0644]

index 15dec4fbcf9efbdc473aa251610eb7956d4a5612..d8df139efa3fabacba5bf3442506ccc977132d58 100644 (file)
@@ -4134,12 +4134,17 @@ Instruction *InstCombiner::visitXor(BinaryOperator &I) {
   
   
   if (ConstantInt *RHS = dyn_cast<ConstantInt>(Op1)) {
-    // xor (icmp A, B), true = not (icmp A, B) = !icmp A, B
-    if (ICmpInst *ICI = dyn_cast<ICmpInst>(Op0))
-      if (RHS == ConstantInt::getTrue() && ICI->hasOneUse())
+    // xor (cmp A, B), true = not (cmp A, B) = !cmp A, B
+    if (RHS == ConstantInt::getTrue() && Op0->hasOneUse()) {
+      if (ICmpInst *ICI = dyn_cast<ICmpInst>(Op0))
         return new ICmpInst(ICI->getInversePredicate(),
                             ICI->getOperand(0), ICI->getOperand(1));
 
+      if (FCmpInst *FCI = dyn_cast<FCmpInst>(Op0))
+        return new FCmpInst(FCI->getInversePredicate(),
+                            FCI->getOperand(0), FCI->getOperand(1));
+    }
+
     if (BinaryOperator *Op0I = dyn_cast<BinaryOperator>(Op0)) {
       // ~(c-X) == X-c-1 == X+(-c-1)
       if (Op0I->getOpcode() == Instruction::Sub && RHS->isAllOnesValue())
diff --git a/test/Transforms/InstCombine/not-fcmp.ll b/test/Transforms/InstCombine/not-fcmp.ll
new file mode 100644 (file)
index 0000000..4560419
--- /dev/null
@@ -0,0 +1,10 @@
+; RUN: llvm-as < %s | opt -instcombine | llvm-dis | grep "fcmp uge"
+; PR1570
+
+define i1 @f(float %X, float %Y) {
+entry:
+        %tmp3 = fcmp olt float %X, %Y           ; <i1> [#uses=1]
+        %toBoolnot5 = xor i1 %tmp3, true                ; <i1> [#uses=1]
+        ret i1 %toBoolnot5
+}
+