Revert r170020, "Simplify negated bit test", for now.
authorNAKAMURA Takumi <geek4civic@gmail.com>
Thu, 13 Dec 2012 14:28:16 +0000 (14:28 +0000)
committerNAKAMURA Takumi <geek4civic@gmail.com>
Thu, 13 Dec 2012 14:28:16 +0000 (14:28 +0000)
This assumes (1 << n) is always not zero. Consider n is greater than word size.
Although I know it is undefined, this transforms undefined behavior hidden.

This led clang unexpected behavior with some failures. I will investigate to fix undefined shl in clang.

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

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

index 00807a391a9a52f669d32845e7a18d2b1bb287e6..1b96c3cca4ee30142a8106e8f588de9676dea23a 100644 (file)
@@ -2034,15 +2034,6 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
                                                CI->countTrailingZeros()));
       }
 
-      // Turn x&~y == 0 into x&y != 0 if x is a power of 2.
-      Value *X = 0, *Y = 0;
-      if (match(Op0, m_And(m_Value(X), m_Not(m_Value(Y)))) &&
-          match(Op1, m_Zero()) && isKnownToBeAPowerOfTwo(X, TD)) {
-        return new ICmpInst(ICmpInst::ICMP_NE,
-                            Builder->CreateAnd(X, Y),
-                            Op1);
-      }
-
       break;
     }
     case ICmpInst::ICMP_NE: {
@@ -2080,15 +2071,6 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
                                                CI->countTrailingZeros()));
       }
 
-      // Turn x&~y != 0 into x&y == 0 if x is a power of 2.
-      Value *X = 0, *Y = 0;
-      if (match(Op0, m_And(m_Value(X), m_Not(m_Value(Y)))) &&
-          match(Op1, m_Zero()) && isKnownToBeAPowerOfTwo(X, TD)) {
-        return new ICmpInst(ICmpInst::ICMP_EQ,
-                            Builder->CreateAnd(X, Y),
-                            Op1);
-      }
-
       break;
     }
     case ICmpInst::ICMP_ULT:
index d11b6cc756f37869d64183f4a3c75d82358bd26a..8e064a4f2fc940e2fb49c406a952b556fb2ec187 100644 (file)
@@ -677,29 +677,3 @@ define i1 @test66(i64 %A, i64 %B) {
 ; CHECK-NEXT: ret i1 true
   ret i1 %cmp
 }
-
-define i1 @test67(i32 %A, i32 %B) {
-  %neg = xor i32 %A, -1
-  %shl = shl i32 1, %B
-  %and = and i32 %shl, %neg
-  %cmp = icmp ne i32 %and, 0
-; CHECK: @test67
-; CHECK-NEXT: %shl = shl i32 1, %B
-; CHECK-NEXT: %1 = and i32 %shl, %A
-; CHECK-NEXT: %cmp = icmp eq i32 %1, 0
-; CHECK-NEXT: ret i1 %cmp
-  ret i1 %cmp
-}
-
-define i1 @test68(i32 %A, i32 %B) {
-  %neg = xor i32 %A, -1
-  %shl = shl i32 1, %B
-  %and = and i32 %shl, %neg
-  %cmp = icmp eq i32 %and, 0
-; CHECK: @test68
-; CHECK-NEXT: %shl = shl i32 1, %B
-; CHECK-NEXT: %1 = and i32 %shl, %A
-; CHECK-NEXT: %cmp = icmp ne i32 %1, 0
-; CHECK-NEXT: ret i1 %cmp
-  ret i1 %cmp
-}