[llvm-commits] [llvm] r128777 - /llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp

Benjamin Kramer benny.kra at googlemail.com
Sat Apr 2 11:50:58 PDT 2011


Author: d0k
Date: Sat Apr  2 13:50:58 2011
New Revision: 128777

URL: http://llvm.org/viewvc/llvm-project?rev=128777&view=rev
Log:
While SimplifyDemandedBits constant folds this, we can't rely on it here.

It's possible to craft an input that hits the recursion limits in a way
that SimplifyDemandedBits doesn't simplify the icmp but ComputeMaskedBits
can infer which bits are zero.

No test case as it depends on too many other things. Fixes PR9609.

Modified:
    llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp

Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp?rev=128777&r1=128776&r2=128777&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp Sat Apr  2 13:50:58 2011
@@ -913,8 +913,13 @@
       if (KnownZeroMask.isPowerOf2()) {
         Value *In = ICI->getOperand(0);
 
-        assert((Op1C->isZero() || Op1C->getValue() == KnownZeroMask) &&
-               "Constant icmp not folded?");
+        // If the icmp tests for a known zero bit we can constant fold it.
+        if (!Op1C->isZero() && Op1C->getValue() != KnownZeroMask) {
+          Value *V = Pred == ICmpInst::ICMP_NE ?
+                       ConstantInt::getAllOnesValue(CI.getType()) :
+                       ConstantInt::getNullValue(CI.getType());
+          return ReplaceInstUsesWith(CI, V);
+        }
 
         if (!Op1C->isZero() == (Pred == ICmpInst::ICMP_NE)) {
           // sext ((x & 2^n) == 0)   -> (x >> n) - 1





More information about the llvm-commits mailing list