PR10267: Don't combine an equality compare with an AND into an inequality compare...
authorBenjamin Kramer <benny.kra@googlemail.com>
Mon, 4 Jul 2011 20:16:36 +0000 (20:16 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Mon, 4 Jul 2011 20:16:36 +0000 (20:16 +0000)
This can pessimize code, inequalities are generally more expensive.

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

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

index 42db444ff6d7926648669dc43e6777ca7755430c..5a1e2b0885307a21931b518e410a13d1c6f8eba4 100644 (file)
@@ -1454,7 +1454,11 @@ Instruction *InstCombiner::visitICmpInstWithInstAndIntCst(ICmpInst &ICI,
             return new ICmpInst(isICMP_NE ? ICmpInst::ICMP_EQ :
                                 ICmpInst::ICMP_NE, LHSI,
                                 Constant::getNullValue(RHS->getType()));
-          
+
+          // Don't perform the following transforms if the AND has multiple uses
+          if (!BO->hasOneUse())
+            break;
+
           // Replace (and X, (1 << size(X)-1) != 0) with x s< 0
           if (BOC->getValue().isSignBit()) {
             Value *X = BO->getOperand(0);
index c8f7f81468f0c06eab35ca218c88d5796bbe3f9e..77ca62cfec67d5c2d948fe169aa7da17ff5c885f 100644 (file)
@@ -547,3 +547,15 @@ define i1 @test56(i32 %a) {
   %cmp = icmp eq i32 %sub, 123
   ret i1 %cmp
 }
+
+; PR10267 Don't make icmps more expensive when no other inst is subsumed.
+declare void @foo(i32)
+; CHECK: @test57
+; CHECK: %and = and i32 %a, -2
+; CHECK: %cmp = icmp ne i32 %and, 0
+define i1 @test57(i32 %a) {
+  %and = and i32 %a, -2
+  %cmp = icmp ne i32 %and, 0
+  call void @foo(i32 %and)
+  ret i1 %cmp
+}