mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-02-01 05:01:59 +01:00
[InstCombine] Don't fall back to only calling computeKnownBits if the upper bit of Add/Sub is demanded.
Just create an all 1s demanded mask and continue recursing like normal. The recursive calls should be able to handle an all 1s mask and do the right thing. The only time we should care about knowing whether the upper bit was demanded is when we need to know if we should clear the NSW/NUW flags. Now that we have a consistent path through the code for all cases, use KnownBits::computeForAddSub to compute the known bits at the end since we already have the LHS and RHS. My larger goal here is to move the code that turns add into xor if only 1 bit is demanded and no bits below it are non-zero from InstCombiner::OptAndOp to here. This will allow it to be more general instead of just looking for 'add' and 'and' with constant RHS. Differential Revision: https://reviews.llvm.org/D36486 llvm-svn: 311789
This commit is contained in:
parent
321f7d083a
commit
a3080591ad
@ -396,38 +396,39 @@ Value *InstCombiner::SimplifyDemandedUseBits(Value *V, APInt DemandedMask,
|
|||||||
/// If the high-bits of an ADD/SUB are not demanded, then we do not care
|
/// If the high-bits of an ADD/SUB are not demanded, then we do not care
|
||||||
/// about the high bits of the operands.
|
/// about the high bits of the operands.
|
||||||
unsigned NLZ = DemandedMask.countLeadingZeros();
|
unsigned NLZ = DemandedMask.countLeadingZeros();
|
||||||
if (NLZ > 0) {
|
// Right fill the mask of bits for this ADD/SUB to demand the most
|
||||||
// Right fill the mask of bits for this ADD/SUB to demand the most
|
// significant bit and all those below it.
|
||||||
// significant bit and all those below it.
|
APInt DemandedFromOps(APInt::getLowBitsSet(BitWidth, BitWidth-NLZ));
|
||||||
APInt DemandedFromOps(APInt::getLowBitsSet(BitWidth, BitWidth-NLZ));
|
if (ShrinkDemandedConstant(I, 0, DemandedFromOps) ||
|
||||||
if (ShrinkDemandedConstant(I, 0, DemandedFromOps) ||
|
SimplifyDemandedBits(I, 0, DemandedFromOps, LHSKnown, Depth + 1) ||
|
||||||
SimplifyDemandedBits(I, 0, DemandedFromOps, LHSKnown, Depth + 1) ||
|
ShrinkDemandedConstant(I, 1, DemandedFromOps) ||
|
||||||
ShrinkDemandedConstant(I, 1, DemandedFromOps) ||
|
SimplifyDemandedBits(I, 1, DemandedFromOps, RHSKnown, Depth + 1)) {
|
||||||
SimplifyDemandedBits(I, 1, DemandedFromOps, RHSKnown, Depth + 1)) {
|
if (NLZ > 0) {
|
||||||
// Disable the nsw and nuw flags here: We can no longer guarantee that
|
// Disable the nsw and nuw flags here: We can no longer guarantee that
|
||||||
// we won't wrap after simplification. Removing the nsw/nuw flags is
|
// we won't wrap after simplification. Removing the nsw/nuw flags is
|
||||||
// legal here because the top bit is not demanded.
|
// legal here because the top bit is not demanded.
|
||||||
BinaryOperator &BinOP = *cast<BinaryOperator>(I);
|
BinaryOperator &BinOP = *cast<BinaryOperator>(I);
|
||||||
BinOP.setHasNoSignedWrap(false);
|
BinOP.setHasNoSignedWrap(false);
|
||||||
BinOP.setHasNoUnsignedWrap(false);
|
BinOP.setHasNoUnsignedWrap(false);
|
||||||
return I;
|
|
||||||
}
|
}
|
||||||
|
return I;
|
||||||
// If we are known to be adding/subtracting zeros to every bit below
|
|
||||||
// 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, unless we are only
|
|
||||||
// demanding the LSB.
|
|
||||||
if ((I->getOpcode() == Instruction::Add ||
|
|
||||||
DemandedFromOps.isOneValue()) &&
|
|
||||||
DemandedFromOps.isSubsetOf(LHSKnown.Zero))
|
|
||||||
return I->getOperand(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise just hand the add/sub off to computeKnownBits to fill in
|
// If we are known to be adding/subtracting zeros to every bit below
|
||||||
// the known zeros and ones.
|
// the highest demanded bit, we just return the other side.
|
||||||
computeKnownBits(V, Known, Depth, CxtI);
|
if (DemandedFromOps.isSubsetOf(RHSKnown.Zero))
|
||||||
|
return I->getOperand(0);
|
||||||
|
// 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);
|
||||||
|
|
||||||
|
// Otherwise just compute the known bits of the result.
|
||||||
|
bool NSW = cast<OverflowingBinaryOperator>(I)->hasNoUnsignedWrap();
|
||||||
|
Known = KnownBits::computeForAddSub(I->getOpcode() == Instruction::Add,
|
||||||
|
NSW, LHSKnown, RHSKnown);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Instruction::Shl: {
|
case Instruction::Shl: {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user