InstCombine: Fix a thinko where transform an icmp under the assumption that it's...
authorBenjamin Kramer <benny.kra@googlemail.com>
Fri, 11 Mar 2011 11:37:40 +0000 (11:37 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Fri, 11 Mar 2011 11:37:40 +0000 (11:37 +0000)
Fixes PR9454.

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

lib/Transforms/InstCombine/InstCombineSelect.cpp
test/Transforms/InstCombine/select.ll

index 97abc769ae5ff81de4361d4ab42da38ea60b5201..8b9261b8fe00564eb3a6889344563860dacea456 100644 (file)
@@ -503,9 +503,8 @@ static Value *foldSelectICmpAnd(const SelectInst &SI, ConstantInt *TrueVal,
   if (!IC || !IC->isEquality())
     return 0;
 
-  if (ConstantInt *C = dyn_cast<ConstantInt>(IC->getOperand(1)))
-    if (!C->isZero())
-      return 0;
+  if (!match(IC->getOperand(1), m_Zero()))
+    return 0;
 
   ConstantInt *AndRHS;
   Value *LHS = IC->getOperand(0);
index ba9d99c97dd51e7bb87e2016b1a83c68ec22d3a1..e9981a523d5afbfb9a186f17967dd872e509722c 100644 (file)
@@ -714,3 +714,13 @@ define i32 @test52(i32 %n, i32 %m) nounwind {
   ret i32 %storemerge
 }
 
+; PR9454
+define i32 @test53(i32 %x) nounwind {
+  %and = and i32 %x, 2
+  %cmp = icmp eq i32 %and, %x
+  %sel = select i1 %cmp, i32 2, i32 1
+  ret i32 %sel
+; CHECK: @test53
+; CHECK: select i1 %cmp
+; CHECK: ret
+}