[llvm-commits] [llvm] r119988 - in /llvm/trunk: lib/Transforms/InstCombine/InstCombineCompares.cpp test/Transforms/InstCombine/icmp.ll

Chris Lattner sabre at nondot.org
Mon Nov 22 18:42:04 PST 2010


Author: lattner
Date: Mon Nov 22 20:42:04 2010
New Revision: 119988

URL: http://llvm.org/viewvc/llvm-project?rev=119988&view=rev
Log:
duncan's spider sense was right, I completely reversed the condition
on this instcombine xform.  This fixes a miscompilation of 403.gcc.

Modified:
    llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp
    llvm/trunk/test/Transforms/InstCombine/icmp.ll

Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp?rev=119988&r1=119987&r2=119988&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp Mon Nov 22 20:42:04 2010
@@ -1761,22 +1761,22 @@
           LHS = Op0;
         
         // If the LHS is 1 << x, and we know the result is a power of 2 like 8,
-        // then turn "((1 << x)&8) == 0" into "x == 3".
+        // then turn "((1 << x)&8) == 0" into "x != 3".
         Value *X = 0;
         if (match(LHS, m_Shl(m_One(), m_Value(X)))) {
           unsigned CmpVal = Op0KnownZeroInverted.countTrailingZeros();
-          return new ICmpInst(ICmpInst::ICMP_EQ, X,
+          return new ICmpInst(ICmpInst::ICMP_NE, X,
                               ConstantInt::get(X->getType(), CmpVal));
         }
         
         // If the LHS is 8 >>u x, and we know the result is a power of 2 like 1,
-        // then turn "((8 >>u x)&1) == 0" into "x == 3".
+        // then turn "((8 >>u x)&1) == 0" into "x != 3".
         ConstantInt *CI = 0;
         if (Op0KnownZeroInverted == 1 &&
             match(LHS, m_LShr(m_ConstantInt(CI), m_Value(X))) &&
             CI->getValue().isPowerOf2()) {
           unsigned CmpVal = CI->getValue().countTrailingZeros();
-          return new ICmpInst(ICmpInst::ICMP_EQ, X,
+          return new ICmpInst(ICmpInst::ICMP_NE, X,
                               ConstantInt::get(X->getType(), CmpVal));
         }
       }
@@ -1800,22 +1800,22 @@
           LHS = Op0;
         
         // If the LHS is 1 << x, and we know the result is a power of 2 like 8,
-        // then turn "((1 << x)&8) != 0" into "x != 3".
+        // then turn "((1 << x)&8) != 0" into "x == 3".
         Value *X = 0;
         if (match(LHS, m_Shl(m_One(), m_Value(X)))) {
           unsigned CmpVal = Op0KnownZeroInverted.countTrailingZeros();
-          return new ICmpInst(ICmpInst::ICMP_NE, X,
+          return new ICmpInst(ICmpInst::ICMP_EQ, X,
                               ConstantInt::get(X->getType(), CmpVal));
         }
         
         // If the LHS is 8 >>u x, and we know the result is a power of 2 like 1,
-        // then turn "((8 >>u x)&1) != 0" into "x != 3".
+        // then turn "((8 >>u x)&1) != 0" into "x == 3".
         ConstantInt *CI = 0;
         if (Op0KnownZeroInverted == 1 &&
             match(LHS, m_LShr(m_ConstantInt(CI), m_Value(X))) &&
             CI->getValue().isPowerOf2()) {
           unsigned CmpVal = CI->getValue().countTrailingZeros();
-          return new ICmpInst(ICmpInst::ICMP_NE, X,
+          return new ICmpInst(ICmpInst::ICMP_EQ, X,
                               ConstantInt::get(X->getType(), CmpVal));
         }
       }

Modified: llvm/trunk/test/Transforms/InstCombine/icmp.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/icmp.ll?rev=119988&r1=119987&r2=119988&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/icmp.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/icmp.ll Mon Nov 22 20:42:04 2010
@@ -161,7 +161,7 @@
   %cmp = icmp eq i32 %and, 0
   ret i1 %cmp
 ; CHECK: @test17
-; CHECK-NEXT: %cmp = icmp eq i32 %x, 3
+; CHECK-NEXT: %cmp = icmp ne i32 %x, 3
 }
 
 
@@ -171,7 +171,7 @@
   %cmp = icmp eq i32 %and, 0
   ret i1 %cmp
 ; CHECK: @test18
-; CHECK-NEXT: %cmp = icmp eq i32 %x, 3
+; CHECK-NEXT: %cmp = icmp ne i32 %x, 3
 }
 
 define i1 @test19(i32 %x) nounwind {
@@ -180,7 +180,7 @@
   %cmp = icmp eq i32 %and, 8
   ret i1 %cmp
 ; CHECK: @test19
-; CHECK-NEXT: %cmp = icmp ne i32 %x, 3
+; CHECK-NEXT: %cmp = icmp eq i32 %x, 3
 }
 
 define i1 @test20(i32 %x) nounwind {
@@ -189,6 +189,6 @@
   %cmp = icmp ne i32 %and, 0
   ret i1 %cmp
 ; CHECK: @test20
-; CHECK-NEXT: %cmp = icmp ne i32 %x, 3
+; CHECK-NEXT: %cmp = icmp eq i32 %x, 3
 }
 





More information about the llvm-commits mailing list