[llvm] r308124 - [InstCombine] Move (0 - x) & 1 --> x & 1 to SimplifyDemandedUseBits.
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Sat Jul 15 22:37:58 PDT 2017
Author: ctopper
Date: Sat Jul 15 22:37:58 2017
New Revision: 308124
URL: http://llvm.org/viewvc/llvm-project?rev=308124&view=rev
Log:
[InstCombine] Move (0 - x) & 1 --> x & 1 to SimplifyDemandedUseBits.
This removes a dedicated matcher and allows us to support more than just an AND masking the lower bit.
Modified:
llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
llvm/trunk/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp?rev=308124&r1=308123&r2=308124&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp Sat Jul 15 22:37:58 2017
@@ -1285,13 +1285,9 @@ Instruction *InstCombiner::visitAnd(Bina
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());
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp?rev=308124&r1=308123&r2=308124&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp Sat Jul 15 22:37:58 2017
@@ -417,8 +417,10 @@ Value *InstCombiner::SimplifyDemandedUse
// 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);
}
More information about the llvm-commits
mailing list