]> granicus.if.org Git - llvm/commitdiff
[InstCombine] Move (0 - x) & 1 --> x & 1 to SimplifyDemandedUseBits.
authorCraig Topper <craig.topper@intel.com>
Sun, 16 Jul 2017 05:37:58 +0000 (05:37 +0000)
committerCraig Topper <craig.topper@intel.com>
Sun, 16 Jul 2017 05:37:58 +0000 (05:37 +0000)
This removes a dedicated matcher and allows us to support more than just an AND masking the lower bit.

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

lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp

index f2f174e5c24079a0171f34c04815db98ba60bee3..fdc9c373b95e6d1a8aa00a9433d476482e14145c 100644 (file)
@@ -1285,13 +1285,9 @@ Instruction *InstCombiner::visitAnd(BinaryOperator &I) {
     return replaceInstUsesWith(I, V);
 
   if (match(Op1, m_One())) {
-    Value *X;
-    // (0 - x) & 1 --> x & 1
-    if (match(Op0, m_Sub(m_Zero(), m_Value(X))))
-      return BinaryOperator::CreateAnd(X, Op1);
-
     // (1 << x) & 1 --> zext(x == 0)
     // (1 >> x) & 1 --> zext(x == 0)
+    Value *X;
     if (match(Op0, m_OneUse(m_LogicalShift(m_One(), m_Value(X))))) {
       Value *IsZero = Builder.CreateICmpEQ(X, ConstantInt::get(I.getType(), 0));
       return new ZExtInst(IsZero, I.getType());
index 5689c060423913b7a921d13d8e273e18832583eb..a20f474cbf40dea67744b2b9e8332a9a3c6c769d 100644 (file)
@@ -417,8 +417,10 @@ Value *InstCombiner::SimplifyDemandedUseBits(Value *V, APInt DemandedMask,
       // the highest demanded bit, we just return the other side.
       if (DemandedFromOps.isSubsetOf(RHSKnown.Zero))
         return I->getOperand(0);
-      // We can't do this with the LHS for subtraction.
-      if (I->getOpcode() == Instruction::Add &&
+      // We can't do this with the LHS for subtraction, unless we are only
+      // demanding the LSB.
+      if ((I->getOpcode() == Instruction::Add ||
+           DemandedFromOps.isOneValue()) &&
           DemandedFromOps.isSubsetOf(LHSKnown.Zero))
         return I->getOperand(1);
     }