mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-25 20:23:11 +01:00
[KnownBits] Introduce anyext instead of passing a flag into zext
Summary: This was a very odd API, where you had to pass a flag into a zext function to say whether the extended bits really were zero or not. All callers passed in a literal true or false. I think it's much clearer to make the function name reflect the operation being performed on the value we're tracking (rather than on the KnownBits Zero and One fields), so zext means the value is being zero extended and new function anyext means the value is being extended with unknown bits. NFC. Subscribers: hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D74482
This commit is contained in:
parent
7208526d5c
commit
cb7a62d110
@ -122,39 +122,48 @@ public:
|
||||
return ~Zero;
|
||||
}
|
||||
|
||||
/// Truncate the underlying known Zero and One bits. This is equivalent
|
||||
/// to truncating the value we're tracking.
|
||||
/// Return known bits for a truncation of the value we're tracking.
|
||||
KnownBits trunc(unsigned BitWidth) const {
|
||||
return KnownBits(Zero.trunc(BitWidth), One.trunc(BitWidth));
|
||||
}
|
||||
|
||||
/// Extends the underlying known Zero and One bits.
|
||||
/// By setting ExtendedBitsAreKnownZero=true this will be equivalent to
|
||||
/// zero extending the value we're tracking.
|
||||
/// With ExtendedBitsAreKnownZero=false the extended bits are set to unknown.
|
||||
KnownBits zext(unsigned BitWidth, bool ExtendedBitsAreKnownZero) const {
|
||||
/// Return known bits for an "any" extension of the value we're tracking,
|
||||
/// where we don't know anything about the extended bits.
|
||||
KnownBits anyext(unsigned BitWidth) const {
|
||||
return KnownBits(Zero.zext(BitWidth), One.zext(BitWidth));
|
||||
}
|
||||
|
||||
/// Return known bits for a zero extension of the value we're tracking.
|
||||
KnownBits zext(unsigned BitWidth) const {
|
||||
unsigned OldBitWidth = getBitWidth();
|
||||
APInt NewZero = Zero.zext(BitWidth);
|
||||
if (ExtendedBitsAreKnownZero)
|
||||
NewZero.setBitsFrom(OldBitWidth);
|
||||
NewZero.setBitsFrom(OldBitWidth);
|
||||
return KnownBits(NewZero, One.zext(BitWidth));
|
||||
}
|
||||
|
||||
/// Sign extends the underlying known Zero and One bits. This is equivalent
|
||||
/// to sign extending the value we're tracking.
|
||||
/// Return known bits for a sign extension of the value we're tracking.
|
||||
KnownBits sext(unsigned BitWidth) const {
|
||||
return KnownBits(Zero.sext(BitWidth), One.sext(BitWidth));
|
||||
}
|
||||
|
||||
/// Extends or truncates the underlying known Zero and One bits. When
|
||||
/// extending the extended bits can either be set as known zero (if
|
||||
/// ExtendedBitsAreKnownZero=true) or as unknown (if
|
||||
/// ExtendedBitsAreKnownZero=false).
|
||||
KnownBits zextOrTrunc(unsigned BitWidth,
|
||||
bool ExtendedBitsAreKnownZero) const {
|
||||
/// Return known bits for an "any" extension or truncation of the value we're
|
||||
/// tracking.
|
||||
KnownBits anyextOrTrunc(unsigned BitWidth) const {
|
||||
if (BitWidth > getBitWidth())
|
||||
return zext(BitWidth, ExtendedBitsAreKnownZero);
|
||||
return KnownBits(Zero.zextOrTrunc(BitWidth), One.zextOrTrunc(BitWidth));
|
||||
return anyext(BitWidth);
|
||||
if (BitWidth < getBitWidth())
|
||||
return trunc(BitWidth);
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// Return known bits for a zero extension or truncation of the value we're
|
||||
/// tracking.
|
||||
KnownBits zextOrTrunc(unsigned BitWidth) const {
|
||||
if (BitWidth > getBitWidth())
|
||||
return zext(BitWidth);
|
||||
if (BitWidth < getBitWidth())
|
||||
return trunc(BitWidth);
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// Return a KnownBits with the extracted bits
|
||||
|
@ -5736,7 +5736,7 @@ ScalarEvolution::getRangeRef(const SCEV *S,
|
||||
// For a SCEVUnknown, ask ValueTracking.
|
||||
KnownBits Known = computeKnownBits(U->getValue(), DL, 0, &AC, nullptr, &DT);
|
||||
if (Known.getBitWidth() != BitWidth)
|
||||
Known = Known.zextOrTrunc(BitWidth, true);
|
||||
Known = Known.zextOrTrunc(BitWidth);
|
||||
// If Known does not result in full-set, intersect with it.
|
||||
if (Known.getMinValue() != Known.getMaxValue() + 1)
|
||||
ConservativeResult = ConservativeResult.intersectWith(
|
||||
|
@ -1254,9 +1254,9 @@ static void computeKnownBitsFromOperator(const Operator *I,
|
||||
Q.DL.getTypeSizeInBits(ScalarTy);
|
||||
|
||||
assert(SrcBitWidth && "SrcBitWidth can't be zero");
|
||||
Known = Known.zextOrTrunc(SrcBitWidth, false);
|
||||
Known = Known.anyextOrTrunc(SrcBitWidth);
|
||||
computeKnownBits(I->getOperand(0), Known, Depth + 1, Q);
|
||||
Known = Known.zextOrTrunc(BitWidth, true /* ExtendedBitsAreKnownZero */);
|
||||
Known = Known.zextOrTrunc(BitWidth);
|
||||
break;
|
||||
}
|
||||
case Instruction::BitCast: {
|
||||
|
@ -294,7 +294,7 @@ void GISelKnownBits::computeKnownBitsImpl(Register R, KnownBits &Known,
|
||||
case TargetOpcode::G_ANYEXT: {
|
||||
computeKnownBitsImpl(MI.getOperand(1).getReg(), Known, DemandedElts,
|
||||
Depth + 1);
|
||||
Known = Known.zext(BitWidth, true /* ExtendedBitsAreKnownZero */);
|
||||
Known = Known.zext(BitWidth);
|
||||
break;
|
||||
}
|
||||
case TargetOpcode::G_LOAD: {
|
||||
@ -360,9 +360,9 @@ void GISelKnownBits::computeKnownBitsImpl(Register R, KnownBits &Known,
|
||||
? DL.getIndexSizeInBits(SrcTy.getAddressSpace())
|
||||
: SrcTy.getSizeInBits();
|
||||
assert(SrcBitWidth && "SrcBitWidth can't be zero");
|
||||
Known = Known.zextOrTrunc(SrcBitWidth, true);
|
||||
Known = Known.zextOrTrunc(SrcBitWidth);
|
||||
computeKnownBitsImpl(SrcReg, Known, DemandedElts, Depth + 1);
|
||||
Known = Known.zextOrTrunc(BitWidth, true);
|
||||
Known = Known.zextOrTrunc(BitWidth);
|
||||
if (BitWidth > SrcBitWidth)
|
||||
Known.Zero.setBitsFrom(SrcBitWidth);
|
||||
break;
|
||||
|
@ -407,7 +407,7 @@ FunctionLoweringInfo::GetLiveOutRegInfo(unsigned Reg, unsigned BitWidth) {
|
||||
|
||||
if (BitWidth > LOI->Known.getBitWidth()) {
|
||||
LOI->NumSignBits = 1;
|
||||
LOI->Known = LOI->Known.zext(BitWidth, false /* => any extend */);
|
||||
LOI->Known = LOI->Known.anyext(BitWidth);
|
||||
}
|
||||
|
||||
return LOI;
|
||||
|
@ -3061,12 +3061,12 @@ KnownBits SelectionDAG::computeKnownBits(SDValue Op, const APInt &DemandedElts,
|
||||
EVT InVT = Op.getOperand(0).getValueType();
|
||||
APInt InDemandedElts = DemandedElts.zextOrSelf(InVT.getVectorNumElements());
|
||||
Known = computeKnownBits(Op.getOperand(0), InDemandedElts, Depth + 1);
|
||||
Known = Known.zext(BitWidth, true /* ExtendedBitsAreKnownZero */);
|
||||
Known = Known.zext(BitWidth);
|
||||
break;
|
||||
}
|
||||
case ISD::ZERO_EXTEND: {
|
||||
Known = computeKnownBits(Op.getOperand(0), DemandedElts, Depth + 1);
|
||||
Known = Known.zext(BitWidth, true /* ExtendedBitsAreKnownZero */);
|
||||
Known = Known.zext(BitWidth);
|
||||
break;
|
||||
}
|
||||
case ISD::SIGN_EXTEND_VECTOR_INREG: {
|
||||
@ -3089,12 +3089,12 @@ KnownBits SelectionDAG::computeKnownBits(SDValue Op, const APInt &DemandedElts,
|
||||
EVT InVT = Op.getOperand(0).getValueType();
|
||||
APInt InDemandedElts = DemandedElts.zextOrSelf(InVT.getVectorNumElements());
|
||||
Known = computeKnownBits(Op.getOperand(0), InDemandedElts, Depth + 1);
|
||||
Known = Known.zext(BitWidth, false /* ExtendedBitsAreKnownZero */);
|
||||
Known = Known.anyext(BitWidth);
|
||||
break;
|
||||
}
|
||||
case ISD::ANY_EXTEND: {
|
||||
Known = computeKnownBits(Op.getOperand(0), DemandedElts, Depth + 1);
|
||||
Known = Known.zext(BitWidth, false /* ExtendedBitsAreKnownZero */);
|
||||
Known = Known.anyext(BitWidth);
|
||||
break;
|
||||
}
|
||||
case ISD::TRUNCATE: {
|
||||
@ -3257,7 +3257,7 @@ KnownBits SelectionDAG::computeKnownBits(SDValue Op, const APInt &DemandedElts,
|
||||
|
||||
Known = computeKnownBits(InVec, DemandedSrcElts, Depth + 1);
|
||||
if (BitWidth > EltBitWidth)
|
||||
Known = Known.zext(BitWidth, false /* => any extend */);
|
||||
Known = Known.anyext(BitWidth);
|
||||
break;
|
||||
}
|
||||
case ISD::INSERT_VECTOR_ELT: {
|
||||
|
@ -864,7 +864,7 @@ bool TargetLowering::SimplifyDemandedBits(
|
||||
APInt SrcDemandedBits = DemandedBits.zextOrSelf(SrcBitWidth);
|
||||
if (SimplifyDemandedBits(Src, SrcDemandedBits, SrcKnown, TLO, Depth + 1))
|
||||
return true;
|
||||
Known = SrcKnown.zextOrTrunc(BitWidth, false);
|
||||
Known = SrcKnown.anyextOrTrunc(BitWidth);
|
||||
break;
|
||||
}
|
||||
case ISD::BUILD_VECTOR:
|
||||
@ -910,7 +910,7 @@ bool TargetLowering::SimplifyDemandedBits(
|
||||
if (SimplifyDemandedBits(Scl, DemandedSclBits, KnownScl, TLO, Depth + 1))
|
||||
return true;
|
||||
|
||||
Known = KnownScl.zextOrTrunc(BitWidth, false);
|
||||
Known = KnownScl.anyextOrTrunc(BitWidth);
|
||||
|
||||
KnownBits KnownVec;
|
||||
if (SimplifyDemandedBits(Vec, DemandedBits, DemandedVecElts, KnownVec, TLO,
|
||||
@ -1765,7 +1765,7 @@ bool TargetLowering::SimplifyDemandedBits(
|
||||
return true;
|
||||
assert(!Known.hasConflict() && "Bits known to be one AND zero?");
|
||||
assert(Known.getBitWidth() == InBits && "Src width has changed?");
|
||||
Known = Known.zext(BitWidth, true /* ExtendedBitsAreKnownZero */);
|
||||
Known = Known.zext(BitWidth);
|
||||
break;
|
||||
}
|
||||
case ISD::SIGN_EXTEND:
|
||||
@ -1838,7 +1838,7 @@ bool TargetLowering::SimplifyDemandedBits(
|
||||
return true;
|
||||
assert(!Known.hasConflict() && "Bits known to be one AND zero?");
|
||||
assert(Known.getBitWidth() == InBits && "Src width has changed?");
|
||||
Known = Known.zext(BitWidth, false /* => any extend */);
|
||||
Known = Known.anyext(BitWidth);
|
||||
|
||||
// Attempt to avoid multi-use ops if we don't need anything from them.
|
||||
if (SDValue NewSrc = SimplifyMultipleUseDemandedBits(
|
||||
@ -1952,7 +1952,7 @@ bool TargetLowering::SimplifyDemandedBits(
|
||||
|
||||
Known = Known2;
|
||||
if (BitWidth > EltBitWidth)
|
||||
Known = Known.zext(BitWidth, false /* => any extend */);
|
||||
Known = Known.anyext(BitWidth);
|
||||
break;
|
||||
}
|
||||
case ISD::BITCAST: {
|
||||
|
@ -15853,7 +15853,7 @@ void ARMTargetLowering::computeKnownBitsForTargetNode(const SDValue Op,
|
||||
if (Op.getOpcode() == ARMISD::VGETLANEs)
|
||||
Known = Known.sext(DstSz);
|
||||
else {
|
||||
Known = Known.zext(DstSz, true /* extended bits are known zero */);
|
||||
Known = Known.zext(DstSz);
|
||||
}
|
||||
assert(DstSz == Known.getBitWidth());
|
||||
break;
|
||||
|
@ -6607,7 +6607,7 @@ SystemZTargetLowering::computeKnownBitsForTargetNode(const SDValue Op,
|
||||
APInt SrcDemE = getDemandedSrcElements(Op, DemandedElts, 0);
|
||||
Known = DAG.computeKnownBits(SrcOp, SrcDemE, Depth + 1);
|
||||
if (IsLogical) {
|
||||
Known = Known.zext(BitWidth, true);
|
||||
Known = Known.zext(BitWidth);
|
||||
} else
|
||||
Known = Known.sext(BitWidth);
|
||||
break;
|
||||
@ -6636,7 +6636,7 @@ SystemZTargetLowering::computeKnownBitsForTargetNode(const SDValue Op,
|
||||
// Known has the width of the source operand(s). Adjust if needed to match
|
||||
// the passed bitwidth.
|
||||
if (Known.getBitWidth() != BitWidth)
|
||||
Known = Known.zextOrTrunc(BitWidth, false);
|
||||
Known = Known.anyextOrTrunc(BitWidth);
|
||||
}
|
||||
|
||||
static unsigned computeNumSignBitsBinOp(SDValue Op, const APInt &DemandedElts,
|
||||
|
@ -32945,7 +32945,7 @@ void X86TargetLowering::computeKnownBitsForTargetNode(const SDValue Op,
|
||||
APInt DemandedElt = APInt::getOneBitSet(SrcVT.getVectorNumElements(),
|
||||
Op.getConstantOperandVal(1));
|
||||
Known = DAG.computeKnownBits(Src, DemandedElt, Depth + 1);
|
||||
Known = Known.zextOrTrunc(BitWidth, false);
|
||||
Known = Known.anyextOrTrunc(BitWidth);
|
||||
Known.Zero.setBitsFrom(SrcVT.getScalarSizeInBits());
|
||||
break;
|
||||
}
|
||||
@ -33059,7 +33059,7 @@ void X86TargetLowering::computeKnownBitsForTargetNode(const SDValue Op,
|
||||
if ((Shift + Length) <= BitWidth) {
|
||||
Known = DAG.computeKnownBits(Op0, Depth + 1);
|
||||
Known = Known.extractBits(Length, Shift);
|
||||
Known = Known.zextOrTrunc(BitWidth, true /* ExtBitsAreKnownZero */);
|
||||
Known = Known.zextOrTrunc(BitWidth);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -36484,7 +36484,7 @@ bool X86TargetLowering::SimplifyDemandedBitsForTargetNode(
|
||||
return TLO.CombineTo(
|
||||
Op, TLO.DAG.getNode(Opc, SDLoc(Op), VT, V, Op.getOperand(1)));
|
||||
|
||||
Known = KnownVec.zext(BitWidth, true);
|
||||
Known = KnownVec.zext(BitWidth);
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
@ -396,8 +396,7 @@ Value *InstCombiner::SimplifyDemandedUseBits(Value *V, APInt DemandedMask,
|
||||
if (SimplifyDemandedBits(I, 0, InputDemandedMask, InputKnown, Depth + 1))
|
||||
return I;
|
||||
assert(InputKnown.getBitWidth() == SrcBitWidth && "Src width changed?");
|
||||
Known = InputKnown.zextOrTrunc(BitWidth,
|
||||
true /* ExtendedBitsAreKnownZero */);
|
||||
Known = InputKnown.zextOrTrunc(BitWidth);
|
||||
assert(!Known.hasConflict() && "Bits known to be one AND zero?");
|
||||
break;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user