duncan's spider sense was right, I completely reversed the condition
authorChris Lattner <sabre@nondot.org>
Tue, 23 Nov 2010 02:42:04 +0000 (02:42 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 23 Nov 2010 02:42:04 +0000 (02:42 +0000)
on this instcombine xform.  This fixes a miscompilation of 403.gcc.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119988 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/InstCombine/InstCombineCompares.cpp
test/Transforms/InstCombine/icmp.ll

index 8a35a5fcf396a9027ad9090697e33331c1fc908c..084c28c6b79d8689ca5e1079ccedca2147790d7d 100644 (file)
@@ -1761,22 +1761,22 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
           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 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
           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));
         }
       }
index 96038ca56b260e64c024a0351c369a0d17aafa88..e33463dbe50f02050604460f31ff628026012fb9 100644 (file)
@@ -161,7 +161,7 @@ define i1 @test17(i32 %x) nounwind {
   %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 @@ define i1 @test18(i32 %x) nounwind {
   %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 @@ define i1 @test19(i32 %x) nounwind {
   %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 @@ define i1 @test20(i32 %x) nounwind {
   %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
 }