[InstCombine] Simplify the logic from r219067 using ValueTracking
authorHal Finkel <hfinkel@anl.gov>
Sun, 5 Oct 2014 00:53:02 +0000 (00:53 +0000)
committerHal Finkel <hfinkel@anl.gov>
Sun, 5 Oct 2014 00:53:02 +0000 (00:53 +0000)
Joerg suggested on IRC that I look at generalizing the logic from r219067 to
handle more general redundancies (like removing an assume(x > 3) dominated by
an assume(x > 5)). The way to do this would be to ask ValueTracking to
determine the value of the i1 argument. It turns out that ValueTracking is not
very good at this right now (although it does get the trivial redundancy case)
because it does not understand ICmps. Nevertheless, the resulting code in
InstCombine is simpler than r219067, so we might as well do it now.

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

lib/Transforms/InstCombine/InstCombineCalls.cpp

index 27a64d8bcdeb1e3745d1dbcc6812b48c26ce0b52..c2fecde39294396a0b9d2a5f3ce3c7cc88a15ce0 100644 (file)
@@ -1020,18 +1020,10 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
 
     // If there is a dominating assume with the same condition as this one,
     // then this one is redundant, and should be removed.
 
     // If there is a dominating assume with the same condition as this one,
     // then this one is redundant, and should be removed.
-    if (DT) {
-      for (User *U : IIOperand->users()) {
-        Instruction *User = dyn_cast<Instruction>(U);
-        if (!User || User == II)
-          continue;
-
-        if (match(User,
-                  m_Intrinsic<Intrinsic::assume>(m_Specific(IIOperand))) &&
-            DT->dominates(User, II))
-          return EraseInstFromFunction(*II);
-      }
-    }
+    APInt KnownZero(1, 0), KnownOne(1, 0);
+    computeKnownBits(IIOperand, KnownZero, KnownOne, 0, II);
+    if (KnownOne.isAllOnesValue())
+      return EraseInstFromFunction(*II);
 
     break;
   }
 
     break;
   }