[llvm-commits] [llvm] r40870 - in /llvm/trunk: lib/Transforms/Scalar/InstructionCombining.cpp test/Transforms/InstCombine/not-fcmp.ll

Nick Lewycky nicholas at mxc.ca
Mon Aug 6 13:04:20 PDT 2007


Author: nicholas
Date: Mon Aug  6 15:04:16 2007
New Revision: 40870

URL: http://llvm.org/viewvc/llvm-project?rev=40870&view=rev
Log:
It's safe to fold not of fcmp.

Added:
    llvm/trunk/test/Transforms/InstCombine/not-fcmp.ll
Modified:
    llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp

Modified: llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp?rev=40870&r1=40869&r2=40870&view=diff

==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp Mon Aug  6 15:04:16 2007
@@ -4134,12 +4134,17 @@
   
   
   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())

Added: llvm/trunk/test/Transforms/InstCombine/not-fcmp.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/not-fcmp.ll?rev=40870&view=auto

==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/not-fcmp.ll (added)
+++ llvm/trunk/test/Transforms/InstCombine/not-fcmp.ll Mon Aug  6 15:04:16 2007
@@ -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
+}
+





More information about the llvm-commits mailing list