[llvm-commits] [llvm] r130446 - /llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp

Benjamin Kramer benny.kra at googlemail.com
Thu Apr 28 14:38:51 PDT 2011


Author: d0k
Date: Thu Apr 28 16:38:51 2011
New Revision: 130446

URL: http://llvm.org/viewvc/llvm-project?rev=130446&view=rev
Log:
We require threse bits to be zero, too.

This shouldn't happen in practice because the icmp would be a constant.
Add a check so we don't miscompile code if something goes wrong.

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

Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp?rev=130446&r1=130445&r2=130446&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp Thu Apr 28 16:38:51 2011
@@ -772,7 +772,7 @@
 
   // (trunc x) == C1 & (and x, CA) == C2 -> (and x, CA|CMAX) == C1|C2
   // where CMAX is the all ones value for the truncated type,
-  // iff the lower bits of CA are zero.
+  // iff the lower bits of C2 and CA are zero.
   if (LHSCC == RHSCC && ICmpInst::isEquality(LHSCC) &&
       LHS->hasOneUse() && RHS->hasOneUse()) {
     Value *V;
@@ -797,7 +797,7 @@
 
       // Check that the low bits are zero.
       APInt Low = APInt::getLowBitsSet(BigBitSize, SmallBitSize);
-      if ((Low & AndCst->getValue()) == 0) {
+      if ((Low & AndCst->getValue()) == 0 && (Low & BigCst->getValue()) == 0) {
         Value *NewAnd = Builder->CreateAnd(V, Low | AndCst->getValue());
         APInt N = SmallCst->getValue().zext(BigBitSize) | BigCst->getValue();
         Value *NewVal = ConstantInt::get(AndCst->getType()->getContext(), N);





More information about the llvm-commits mailing list