Convert SelectionDAG::ComputeMaskedBits to use APInt instead of uint64_t.

Add an overload that supports the uint64_t interface for use by clients
that haven't been updated yet.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@47039 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Dan Gohman
2008-02-13 00:35:47 +00:00
parent 3006c39e3a
commit fd29e0eb06
13 changed files with 166 additions and 132 deletions

View File

@@ -556,6 +556,12 @@ public:
/// bitsets. This code only analyzes bits in Mask, in order to short-circuit /// bitsets. This code only analyzes bits in Mask, in order to short-circuit
/// processing. Targets can implement the computeMaskedBitsForTargetNode /// processing. Targets can implement the computeMaskedBitsForTargetNode
/// method in the TargetLowering class to allow target nodes to be understood. /// method in the TargetLowering class to allow target nodes to be understood.
void ComputeMaskedBits(SDOperand Op, APInt Mask, APInt &KnownZero,
APInt &KnownOne, unsigned Depth = 0) const;
/// ComputeMaskedBits - This is a wrapper around the APInt-using
/// form of ComputeMaskedBits for use by clients that haven't been converted
/// to APInt yet.
void ComputeMaskedBits(SDOperand Op, uint64_t Mask, uint64_t &KnownZero, void ComputeMaskedBits(SDOperand Op, uint64_t Mask, uint64_t &KnownZero,
uint64_t &KnownOne, unsigned Depth = 0) const; uint64_t &KnownOne, unsigned Depth = 0) const;

View File

@@ -627,9 +627,9 @@ public:
/// Mask are known to be either zero or one and return them in the /// Mask are known to be either zero or one and return them in the
/// KnownZero/KnownOne bitsets. /// KnownZero/KnownOne bitsets.
virtual void computeMaskedBitsForTargetNode(const SDOperand Op, virtual void computeMaskedBitsForTargetNode(const SDOperand Op,
uint64_t Mask, APInt Mask,
uint64_t &KnownZero, APInt &KnownZero,
uint64_t &KnownOne, APInt &KnownOne,
const SelectionDAG &DAG, const SelectionDAG &DAG,
unsigned Depth = 0) const; unsigned Depth = 0) const;

View File

@@ -1130,10 +1130,11 @@ bool SelectionDAG::MaskedValueIsZero(SDOperand Op, uint64_t Mask,
/// known to be either zero or one and return them in the KnownZero/KnownOne /// known to be either zero or one and return them in the KnownZero/KnownOne
/// bitsets. This code only analyzes bits in Mask, in order to short-circuit /// bitsets. This code only analyzes bits in Mask, in order to short-circuit
/// processing. /// processing.
void SelectionDAG::ComputeMaskedBits(SDOperand Op, uint64_t Mask, void SelectionDAG::ComputeMaskedBits(SDOperand Op, APInt Mask,
uint64_t &KnownZero, uint64_t &KnownOne, APInt &KnownZero, APInt &KnownOne,
unsigned Depth) const { unsigned Depth) const {
KnownZero = KnownOne = 0; // Don't know anything. unsigned BitWidth = Mask.getBitWidth();
KnownZero = KnownOne = APInt(BitWidth, 0); // Don't know anything.
if (Depth == 6 || Mask == 0) if (Depth == 6 || Mask == 0)
return; // Limit search depth. return; // Limit search depth.
@@ -1141,12 +1142,12 @@ void SelectionDAG::ComputeMaskedBits(SDOperand Op, uint64_t Mask,
if (Op.getValueType() == MVT::i128) if (Op.getValueType() == MVT::i128)
return; return;
uint64_t KnownZero2, KnownOne2; APInt KnownZero2, KnownOne2;
switch (Op.getOpcode()) { switch (Op.getOpcode()) {
case ISD::Constant: case ISD::Constant:
// We know all of the bits for a constant! // We know all of the bits for a constant!
KnownOne = cast<ConstantSDNode>(Op)->getValue() & Mask; KnownOne = cast<ConstantSDNode>(Op)->getAPIntValue() & Mask;
KnownZero = ~KnownOne & Mask; KnownZero = ~KnownOne & Mask;
return; return;
case ISD::AND: case ISD::AND:
@@ -1181,7 +1182,7 @@ void SelectionDAG::ComputeMaskedBits(SDOperand Op, uint64_t Mask,
assert((KnownZero2 & KnownOne2) == 0 && "Bits known to be one AND zero?"); assert((KnownZero2 & KnownOne2) == 0 && "Bits known to be one AND zero?");
// Output known-0 bits are known if clear or set in both the LHS & RHS. // Output known-0 bits are known if clear or set in both the LHS & RHS.
uint64_t KnownZeroOut = (KnownZero & KnownZero2) | (KnownOne & KnownOne2); APInt KnownZeroOut = (KnownZero & KnownZero2) | (KnownOne & KnownOne2);
// Output known-1 are known to be set if set in only one of the LHS, RHS. // Output known-1 are known to be set if set in only one of the LHS, RHS.
KnownOne = (KnownZero & KnownOne2) | (KnownOne & KnownZero2); KnownOne = (KnownZero & KnownOne2) | (KnownOne & KnownZero2);
KnownZero = KnownZeroOut; KnownZero = KnownZeroOut;
@@ -1209,71 +1210,61 @@ void SelectionDAG::ComputeMaskedBits(SDOperand Op, uint64_t Mask,
return; return;
case ISD::SETCC: case ISD::SETCC:
// If we know the result of a setcc has the top bits zero, use this info. // If we know the result of a setcc has the top bits zero, use this info.
if (TLI.getSetCCResultContents() == TargetLowering::ZeroOrOneSetCCResult) if (TLI.getSetCCResultContents() == TargetLowering::ZeroOrOneSetCCResult &&
KnownZero |= (MVT::getIntVTBitMask(Op.getValueType()) ^ 1ULL); BitWidth > 1)
KnownZero |= APInt::getHighBitsSet(BitWidth, BitWidth - 1);
return; return;
case ISD::SHL: case ISD::SHL:
// (shl X, C1) & C2 == 0 iff (X & C2 >>u C1) == 0 // (shl X, C1) & C2 == 0 iff (X & C2 >>u C1) == 0
if (ConstantSDNode *SA = dyn_cast<ConstantSDNode>(Op.getOperand(1))) { if (ConstantSDNode *SA = dyn_cast<ConstantSDNode>(Op.getOperand(1))) {
ComputeMaskedBits(Op.getOperand(0), Mask >> SA->getValue(), ComputeMaskedBits(Op.getOperand(0), Mask.lshr(SA->getValue()),
KnownZero, KnownOne, Depth+1); KnownZero, KnownOne, Depth+1);
assert((KnownZero & KnownOne) == 0 && "Bits known to be one AND zero?"); assert((KnownZero & KnownOne) == 0 && "Bits known to be one AND zero?");
KnownZero <<= SA->getValue(); KnownZero <<= SA->getValue();
KnownOne <<= SA->getValue(); KnownOne <<= SA->getValue();
KnownZero |= (1ULL << SA->getValue())-1; // low bits known zero. // low bits known zero.
KnownZero |= APInt::getLowBitsSet(BitWidth, SA->getValue());
} }
return; return;
case ISD::SRL: case ISD::SRL:
// (ushr X, C1) & C2 == 0 iff (-1 >> C1) & C2 == 0 // (ushr X, C1) & C2 == 0 iff (-1 >> C1) & C2 == 0
if (ConstantSDNode *SA = dyn_cast<ConstantSDNode>(Op.getOperand(1))) { if (ConstantSDNode *SA = dyn_cast<ConstantSDNode>(Op.getOperand(1))) {
MVT::ValueType VT = Op.getValueType();
unsigned ShAmt = SA->getValue(); unsigned ShAmt = SA->getValue();
uint64_t TypeMask = MVT::getIntVTBitMask(VT); ComputeMaskedBits(Op.getOperand(0), (Mask << ShAmt),
ComputeMaskedBits(Op.getOperand(0), (Mask << ShAmt) & TypeMask,
KnownZero, KnownOne, Depth+1); KnownZero, KnownOne, Depth+1);
assert((KnownZero & KnownOne) == 0 && "Bits known to be one AND zero?"); assert((KnownZero & KnownOne) == 0 && "Bits known to be one AND zero?");
KnownZero &= TypeMask; KnownZero = KnownZero.lshr(ShAmt);
KnownOne &= TypeMask; KnownOne = KnownOne.lshr(ShAmt);
KnownZero >>= ShAmt;
KnownOne >>= ShAmt;
uint64_t HighBits = (1ULL << ShAmt)-1; APInt HighBits = APInt::getHighBitsSet(BitWidth, ShAmt);
HighBits <<= MVT::getSizeInBits(VT)-ShAmt;
KnownZero |= HighBits; // High bits known zero. KnownZero |= HighBits; // High bits known zero.
} }
return; return;
case ISD::SRA: case ISD::SRA:
if (ConstantSDNode *SA = dyn_cast<ConstantSDNode>(Op.getOperand(1))) { if (ConstantSDNode *SA = dyn_cast<ConstantSDNode>(Op.getOperand(1))) {
MVT::ValueType VT = Op.getValueType();
unsigned ShAmt = SA->getValue(); unsigned ShAmt = SA->getValue();
// Compute the new bits that are at the top now. APInt InDemandedMask = (Mask << ShAmt);
uint64_t TypeMask = MVT::getIntVTBitMask(VT);
uint64_t InDemandedMask = (Mask << ShAmt) & TypeMask;
// If any of the demanded bits are produced by the sign extension, we also // If any of the demanded bits are produced by the sign extension, we also
// demand the input sign bit. // demand the input sign bit.
uint64_t HighBits = (1ULL << ShAmt)-1; APInt HighBits = APInt::getHighBitsSet(BitWidth, ShAmt);
HighBits <<= MVT::getSizeInBits(VT) - ShAmt; if (!!(HighBits & Mask))
if (HighBits & Mask) InDemandedMask |= APInt::getSignBit(BitWidth);
InDemandedMask |= MVT::getIntVTSignBit(VT);
ComputeMaskedBits(Op.getOperand(0), InDemandedMask, KnownZero, KnownOne, ComputeMaskedBits(Op.getOperand(0), InDemandedMask, KnownZero, KnownOne,
Depth+1); Depth+1);
assert((KnownZero & KnownOne) == 0 && "Bits known to be one AND zero?"); assert((KnownZero & KnownOne) == 0 && "Bits known to be one AND zero?");
KnownZero &= TypeMask; KnownZero = KnownZero.lshr(ShAmt);
KnownOne &= TypeMask; KnownOne = KnownOne.lshr(ShAmt);
KnownZero >>= ShAmt;
KnownOne >>= ShAmt;
// Handle the sign bits. // Handle the sign bits.
uint64_t SignBit = MVT::getIntVTSignBit(VT); APInt SignBit = APInt::getSignBit(BitWidth);
SignBit >>= ShAmt; // Adjust to where it is now in the mask. SignBit = SignBit.lshr(ShAmt); // Adjust to where it is now in the mask.
if (KnownZero & SignBit) { if (!!(KnownZero & SignBit)) {
KnownZero |= HighBits; // New bits are known zero. KnownZero |= HighBits; // New bits are known zero.
} else if (KnownOne & SignBit) { } else if (!!(KnownOne & SignBit)) {
KnownOne |= HighBits; // New bits are known one. KnownOne |= HighBits; // New bits are known one.
} }
} }
@@ -1283,14 +1274,18 @@ void SelectionDAG::ComputeMaskedBits(SDOperand Op, uint64_t Mask,
// Sign extension. Compute the demanded bits in the result that are not // Sign extension. Compute the demanded bits in the result that are not
// present in the input. // present in the input.
uint64_t NewBits = ~MVT::getIntVTBitMask(EVT) & Mask; APInt NewBits = ~APInt::getLowBitsSet(BitWidth,
MVT::getSizeInBits(EVT)) & Mask;
uint64_t InSignBit = MVT::getIntVTSignBit(EVT); APInt InSignBit = APInt::getSignBit(MVT::getSizeInBits(EVT));
int64_t InputDemandedBits = Mask & MVT::getIntVTBitMask(EVT); APInt InputDemandedBits =
Mask & APInt::getLowBitsSet(BitWidth,
MVT::getSizeInBits(EVT));
// If the sign extended bits are demanded, we know that the sign // If the sign extended bits are demanded, we know that the sign
// bit is demanded. // bit is demanded.
if (NewBits) InSignBit.zext(BitWidth);
if (!!NewBits)
InputDemandedBits |= InSignBit; InputDemandedBits |= InSignBit;
ComputeMaskedBits(Op.getOperand(0), InputDemandedBits, ComputeMaskedBits(Op.getOperand(0), InputDemandedBits,
@@ -1299,10 +1294,10 @@ void SelectionDAG::ComputeMaskedBits(SDOperand Op, uint64_t Mask,
// If the sign bit of the input is known set or clear, then we know the // If the sign bit of the input is known set or clear, then we know the
// top bits of the result. // top bits of the result.
if (KnownZero & InSignBit) { // Input sign bit known clear if (!!(KnownZero & InSignBit)) { // Input sign bit known clear
KnownZero |= NewBits; KnownZero |= NewBits;
KnownOne &= ~NewBits; KnownOne &= ~NewBits;
} else if (KnownOne & InSignBit) { // Input sign bit known set } else if (!!(KnownOne & InSignBit)) { // Input sign bit known set
KnownOne |= NewBits; KnownOne |= NewBits;
KnownZero &= ~NewBits; KnownZero &= ~NewBits;
} else { // Input sign bit unknown } else { // Input sign bit unknown
@@ -1314,49 +1309,58 @@ void SelectionDAG::ComputeMaskedBits(SDOperand Op, uint64_t Mask,
case ISD::CTTZ: case ISD::CTTZ:
case ISD::CTLZ: case ISD::CTLZ:
case ISD::CTPOP: { case ISD::CTPOP: {
MVT::ValueType VT = Op.getValueType(); unsigned LowBits = Log2_32(BitWidth)+1;
unsigned LowBits = Log2_32(MVT::getSizeInBits(VT))+1; KnownZero = APInt::getHighBitsSet(BitWidth, BitWidth - LowBits);
KnownZero = ~((1ULL << LowBits)-1) & MVT::getIntVTBitMask(VT); KnownOne = APInt(BitWidth, 0);
KnownOne = 0;
return; return;
} }
case ISD::LOAD: { case ISD::LOAD: {
if (ISD::isZEXTLoad(Op.Val)) { if (ISD::isZEXTLoad(Op.Val)) {
LoadSDNode *LD = cast<LoadSDNode>(Op); LoadSDNode *LD = cast<LoadSDNode>(Op);
MVT::ValueType VT = LD->getMemoryVT(); MVT::ValueType VT = LD->getMemoryVT();
KnownZero |= ~MVT::getIntVTBitMask(VT) & Mask; KnownZero |= ~APInt::getLowBitsSet(BitWidth, MVT::getSizeInBits(VT)) & Mask;
} }
return; return;
} }
case ISD::ZERO_EXTEND: { case ISD::ZERO_EXTEND: {
uint64_t InMask = MVT::getIntVTBitMask(Op.getOperand(0).getValueType()); MVT::ValueType InVT = Op.getOperand(0).getValueType();
uint64_t NewBits = (~InMask) & Mask; unsigned InBits = MVT::getSizeInBits(InVT);
ComputeMaskedBits(Op.getOperand(0), Mask & InMask, KnownZero, APInt InMask = APInt::getLowBitsSet(BitWidth, InBits);
KnownOne, Depth+1); APInt NewBits = (~InMask) & Mask;
KnownZero |= NewBits & Mask; Mask.trunc(InBits);
KnownOne &= ~NewBits; KnownZero.trunc(InBits);
KnownOne.trunc(InBits);
ComputeMaskedBits(Op.getOperand(0), Mask, KnownZero, KnownOne, Depth+1);
KnownZero.zext(BitWidth);
KnownOne.zext(BitWidth);
KnownZero |= NewBits;
return; return;
} }
case ISD::SIGN_EXTEND: { case ISD::SIGN_EXTEND: {
MVT::ValueType InVT = Op.getOperand(0).getValueType(); MVT::ValueType InVT = Op.getOperand(0).getValueType();
unsigned InBits = MVT::getSizeInBits(InVT); unsigned InBits = MVT::getSizeInBits(InVT);
uint64_t InMask = MVT::getIntVTBitMask(InVT); APInt InMask = APInt::getLowBitsSet(BitWidth, InBits);
uint64_t InSignBit = 1ULL << (InBits-1); APInt InSignBit = APInt::getSignBit(InBits);
uint64_t NewBits = (~InMask) & Mask; APInt NewBits = (~InMask) & Mask;
uint64_t InDemandedBits = Mask & InMask;
// If any of the sign extended bits are demanded, we know that the sign // If any of the sign extended bits are demanded, we know that the sign
// bit is demanded. // bit is demanded.
if (NewBits & Mask) InSignBit.zext(BitWidth);
InDemandedBits |= InSignBit; if (!!(NewBits & Mask))
Mask |= InSignBit;
ComputeMaskedBits(Op.getOperand(0), InDemandedBits, KnownZero,
KnownOne, Depth+1); Mask.trunc(InBits);
KnownZero.trunc(InBits);
KnownOne.trunc(InBits);
ComputeMaskedBits(Op.getOperand(0), Mask, KnownZero, KnownOne, Depth+1);
KnownZero.zext(BitWidth);
KnownOne.zext(BitWidth);
// If the sign bit is known zero or one, the top bits match. // If the sign bit is known zero or one, the top bits match.
if (KnownZero & InSignBit) { if (!!(KnownZero & InSignBit)) {
KnownZero |= NewBits; KnownZero |= NewBits;
KnownOne &= ~NewBits; KnownOne &= ~NewBits;
} else if (KnownOne & InSignBit) { } else if (!!(KnownOne & InSignBit)) {
KnownOne |= NewBits; KnownOne |= NewBits;
KnownZero &= ~NewBits; KnownZero &= ~NewBits;
} else { // Otherwise, top bits aren't known. } else { // Otherwise, top bits aren't known.
@@ -1366,22 +1370,31 @@ void SelectionDAG::ComputeMaskedBits(SDOperand Op, uint64_t Mask,
return; return;
} }
case ISD::ANY_EXTEND: { case ISD::ANY_EXTEND: {
MVT::ValueType VT = Op.getOperand(0).getValueType(); MVT::ValueType InVT = Op.getOperand(0).getValueType();
ComputeMaskedBits(Op.getOperand(0), Mask & MVT::getIntVTBitMask(VT), unsigned InBits = MVT::getSizeInBits(InVT);
KnownZero, KnownOne, Depth+1); Mask.trunc(InBits);
KnownZero.trunc(InBits);
KnownOne.trunc(InBits);
ComputeMaskedBits(Op.getOperand(0), Mask, KnownZero, KnownOne, Depth+1);
KnownZero.zext(BitWidth);
KnownOne.zext(BitWidth);
return; return;
} }
case ISD::TRUNCATE: { case ISD::TRUNCATE: {
MVT::ValueType InVT = Op.getOperand(0).getValueType();
unsigned InBits = MVT::getSizeInBits(InVT);
Mask.zext(InBits);
KnownZero.zext(InBits);
KnownOne.zext(InBits);
ComputeMaskedBits(Op.getOperand(0), Mask, KnownZero, KnownOne, Depth+1); ComputeMaskedBits(Op.getOperand(0), Mask, KnownZero, KnownOne, Depth+1);
assert((KnownZero & KnownOne) == 0 && "Bits known to be one AND zero?"); assert((KnownZero & KnownOne) == 0 && "Bits known to be one AND zero?");
uint64_t OutMask = MVT::getIntVTBitMask(Op.getValueType()); KnownZero.trunc(BitWidth);
KnownZero &= OutMask; KnownOne.trunc(BitWidth);
KnownOne &= OutMask;
break; break;
} }
case ISD::AssertZext: { case ISD::AssertZext: {
MVT::ValueType VT = cast<VTSDNode>(Op.getOperand(1))->getVT(); MVT::ValueType VT = cast<VTSDNode>(Op.getOperand(1))->getVT();
uint64_t InMask = MVT::getIntVTBitMask(VT); APInt InMask = APInt::getLowBitsSet(BitWidth, MVT::getSizeInBits(VT));
ComputeMaskedBits(Op.getOperand(0), Mask & InMask, KnownZero, ComputeMaskedBits(Op.getOperand(0), Mask & InMask, KnownZero,
KnownOne, Depth+1); KnownOne, Depth+1);
KnownZero |= (~InMask) & Mask; KnownZero |= (~InMask) & Mask;
@@ -1389,7 +1402,7 @@ void SelectionDAG::ComputeMaskedBits(SDOperand Op, uint64_t Mask,
} }
case ISD::FGETSIGN: case ISD::FGETSIGN:
// All bits are zero except the low bit. // All bits are zero except the low bit.
KnownZero = MVT::getIntVTBitMask(Op.getValueType()) ^ 1; KnownZero = APInt::getHighBitsSet(BitWidth, BitWidth - 1);
return; return;
case ISD::ADD: { case ISD::ADD: {
@@ -1402,11 +1415,11 @@ void SelectionDAG::ComputeMaskedBits(SDOperand Op, uint64_t Mask,
// Output known-0 bits are known if clear or set in both the low clear bits // Output known-0 bits are known if clear or set in both the low clear bits
// common to both LHS & RHS. For example, 8+(X<<3) is known to have the // common to both LHS & RHS. For example, 8+(X<<3) is known to have the
// low 3 bits clear. // low 3 bits clear.
uint64_t KnownZeroOut = std::min(CountTrailingZeros_64(~KnownZero), unsigned KnownZeroOut = std::min((~KnownZero).countTrailingZeros(),
CountTrailingZeros_64(~KnownZero2)); (~KnownZero2).countTrailingZeros());
KnownZero = (1ULL << KnownZeroOut) - 1; KnownZero = APInt::getLowBitsSet(BitWidth, KnownZeroOut);
KnownOne = 0; KnownOne = APInt(BitWidth, 0);
return; return;
} }
case ISD::SUB: { case ISD::SUB: {
@@ -1416,21 +1429,23 @@ void SelectionDAG::ComputeMaskedBits(SDOperand Op, uint64_t Mask,
// We know that the top bits of C-X are clear if X contains less bits // We know that the top bits of C-X are clear if X contains less bits
// than C (i.e. no wrap-around can happen). For example, 20-X is // than C (i.e. no wrap-around can happen). For example, 20-X is
// positive if we can prove that X is >= 0 and < 16. // positive if we can prove that X is >= 0 and < 16.
MVT::ValueType VT = CLHS->getValueType(0);
if ((CLHS->getValue() & MVT::getIntVTSignBit(VT)) == 0) { // sign bit clear // sign bit clear
unsigned NLZ = CountLeadingZeros_64(CLHS->getValue()+1); if (!(CLHS->getAPIntValue() & APInt::getSignBit(BitWidth))) {
uint64_t MaskV = (1ULL << (63-NLZ))-1; // NLZ can't be 64 with no sign bit unsigned NLZ = (CLHS->getAPIntValue()+1).countLeadingZeros();
MaskV = ~MaskV & MVT::getIntVTBitMask(VT); // NLZ can't be BitWidth with no sign bit
APInt MaskV = APInt::getHighBitsSet(BitWidth, NLZ);
ComputeMaskedBits(Op.getOperand(1), MaskV, KnownZero, KnownOne, Depth+1); ComputeMaskedBits(Op.getOperand(1), MaskV, KnownZero, KnownOne, Depth+1);
// If all of the MaskV bits are known to be zero, then we know the output // If all of the MaskV bits are known to be zero, then we know the output
// top bits are zero, because we now know that the output is from [0-C]. // top bits are zero, because we now know that the output is from [0-C].
if ((KnownZero & MaskV) == MaskV) { if ((KnownZero & MaskV) == MaskV) {
unsigned NLZ2 = CountLeadingZeros_64(CLHS->getValue()); unsigned NLZ2 = CLHS->getAPIntValue().countLeadingZeros();
KnownZero = ~((1ULL << (64-NLZ2))-1) & Mask; // Top bits known zero. // Top bits known zero.
KnownOne = 0; // No one bits known. KnownZero = APInt::getHighBitsSet(BitWidth, NLZ2) & Mask;
KnownOne = APInt(BitWidth, 0); // No one bits known.
} else { } else {
KnownZero = KnownOne = 0; // Otherwise, nothing known. KnownZero = KnownOne = APInt(BitWidth, 0); // Otherwise, nothing known.
} }
} }
return; return;
@@ -1447,6 +1462,21 @@ void SelectionDAG::ComputeMaskedBits(SDOperand Op, uint64_t Mask,
} }
} }
/// ComputeMaskedBits - This is a wrapper around the APInt-using
/// form of ComputeMaskedBits for use by clients that haven't been converted
/// to APInt yet.
void SelectionDAG::ComputeMaskedBits(SDOperand Op, uint64_t Mask,
uint64_t &KnownZero, uint64_t &KnownOne,
unsigned Depth) const {
unsigned NumBits = MVT::getSizeInBits(Op.getValueType());
APInt APIntMask(NumBits, Mask);
APInt APIntKnownZero(NumBits, 0);
APInt APIntKnownOne(NumBits, 0);
ComputeMaskedBits(Op, APIntMask, APIntKnownZero, APIntKnownOne, Depth);
KnownZero = APIntKnownZero.getZExtValue();
KnownOne = APIntKnownOne.getZExtValue();
}
/// ComputeNumSignBits - Return the number of times the sign bit of the /// ComputeNumSignBits - Return the number of times the sign bit of the
/// register is replicated into the other bits. We know that at least 1 bit /// register is replicated into the other bits. We know that at least 1 bit
/// is always equal to the sign bit (itself), but other cases can give us /// is always equal to the sign bit (itself), but other cases can give us

View File

@@ -1008,9 +1008,9 @@ bool TargetLowering::SimplifyDemandedBits(SDOperand Op, uint64_t DemandedMask,
/// in Mask are known to be either zero or one and return them in the /// in Mask are known to be either zero or one and return them in the
/// KnownZero/KnownOne bitsets. /// KnownZero/KnownOne bitsets.
void TargetLowering::computeMaskedBitsForTargetNode(const SDOperand Op, void TargetLowering::computeMaskedBitsForTargetNode(const SDOperand Op,
uint64_t Mask, APInt Mask,
uint64_t &KnownZero, APInt &KnownZero,
uint64_t &KnownOne, APInt &KnownOne,
const SelectionDAG &DAG, const SelectionDAG &DAG,
unsigned Depth) const { unsigned Depth) const {
assert((Op.getOpcode() >= ISD::BUILTIN_OP_END || assert((Op.getOpcode() >= ISD::BUILTIN_OP_END ||

View File

@@ -1769,13 +1769,12 @@ bool ARMTargetLowering::getPostIndexedAddressParts(SDNode *N, SDNode *Op,
} }
void ARMTargetLowering::computeMaskedBitsForTargetNode(const SDOperand Op, void ARMTargetLowering::computeMaskedBitsForTargetNode(const SDOperand Op,
uint64_t Mask, APInt Mask,
uint64_t &KnownZero, APInt &KnownZero,
uint64_t &KnownOne, APInt &KnownOne,
const SelectionDAG &DAG, const SelectionDAG &DAG,
unsigned Depth) const { unsigned Depth) const {
KnownZero = 0; KnownZero = KnownOne = APInt(Mask.getBitWidth(), 0);
KnownOne = 0;
switch (Op.getOpcode()) { switch (Op.getOpcode()) {
default: break; default: break;
case ARMISD::CMOV: { case ARMISD::CMOV: {
@@ -1783,7 +1782,7 @@ void ARMTargetLowering::computeMaskedBitsForTargetNode(const SDOperand Op,
DAG.ComputeMaskedBits(Op.getOperand(0), Mask, KnownZero, KnownOne, Depth+1); DAG.ComputeMaskedBits(Op.getOperand(0), Mask, KnownZero, KnownOne, Depth+1);
if (KnownZero == 0 && KnownOne == 0) return; if (KnownZero == 0 && KnownOne == 0) return;
uint64_t KnownZeroRHS, KnownOneRHS; APInt KnownZeroRHS, KnownOneRHS;
DAG.ComputeMaskedBits(Op.getOperand(1), Mask, DAG.ComputeMaskedBits(Op.getOperand(1), Mask,
KnownZeroRHS, KnownOneRHS, Depth+1); KnownZeroRHS, KnownOneRHS, Depth+1);
KnownZero &= KnownZeroRHS; KnownZero &= KnownZeroRHS;

View File

@@ -106,9 +106,9 @@ namespace llvm {
SelectionDAG &DAG); SelectionDAG &DAG);
virtual void computeMaskedBitsForTargetNode(const SDOperand Op, virtual void computeMaskedBitsForTargetNode(const SDOperand Op,
uint64_t Mask, APInt Mask,
uint64_t &KnownZero, APInt &KnownZero,
uint64_t &KnownOne, APInt &KnownOne,
const SelectionDAG &DAG, const SelectionDAG &DAG,
unsigned Depth) const; unsigned Depth) const;
ConstraintType getConstraintType(const std::string &Constraint) const; ConstraintType getConstraintType(const std::string &Constraint) const;

View File

@@ -2676,13 +2676,12 @@ SPUTargetLowering::getRegForInlineAsmConstraint(const std::string &Constraint,
void void
SPUTargetLowering::computeMaskedBitsForTargetNode(const SDOperand Op, SPUTargetLowering::computeMaskedBitsForTargetNode(const SDOperand Op,
uint64_t Mask, APInt Mask,
uint64_t &KnownZero, APInt &KnownZero,
uint64_t &KnownOne, APInt &KnownOne,
const SelectionDAG &DAG, const SelectionDAG &DAG,
unsigned Depth ) const { unsigned Depth ) const {
KnownZero = 0; KnownZero = KnownOne = APInt(Mask.getBitWidth(), 0);
KnownOne = 0;
} }
// LowerAsmOperandForConstraint // LowerAsmOperandForConstraint

View File

@@ -108,9 +108,9 @@ namespace llvm {
virtual SDOperand PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const; virtual SDOperand PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const;
virtual void computeMaskedBitsForTargetNode(const SDOperand Op, virtual void computeMaskedBitsForTargetNode(const SDOperand Op,
uint64_t Mask, APInt Mask,
uint64_t &KnownZero, APInt &KnownZero,
uint64_t &KnownOne, APInt &KnownOne,
const SelectionDAG &DAG, const SelectionDAG &DAG,
unsigned Depth = 0) const; unsigned Depth = 0) const;

View File

@@ -3458,13 +3458,12 @@ SDOperand PPCTargetLowering::PerformDAGCombine(SDNode *N,
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
void PPCTargetLowering::computeMaskedBitsForTargetNode(const SDOperand Op, void PPCTargetLowering::computeMaskedBitsForTargetNode(const SDOperand Op,
uint64_t Mask, APInt Mask,
uint64_t &KnownZero, APInt &KnownZero,
uint64_t &KnownOne, APInt &KnownOne,
const SelectionDAG &DAG, const SelectionDAG &DAG,
unsigned Depth) const { unsigned Depth) const {
KnownZero = 0; KnownZero = KnownOne = APInt(Mask.getBitWidth(), 0);
KnownOne = 0;
switch (Op.getOpcode()) { switch (Op.getOpcode()) {
default: break; default: break;
case PPCISD::LBRX: { case PPCISD::LBRX: {

View File

@@ -254,9 +254,9 @@ namespace llvm {
virtual SDOperand PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const; virtual SDOperand PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const;
virtual void computeMaskedBitsForTargetNode(const SDOperand Op, virtual void computeMaskedBitsForTargetNode(const SDOperand Op,
uint64_t Mask, APInt Mask,
uint64_t &KnownZero, APInt &KnownZero,
uint64_t &KnownOne, APInt &KnownOne,
const SelectionDAG &DAG, const SelectionDAG &DAG,
unsigned Depth = 0) const; unsigned Depth = 0) const;

View File

@@ -110,9 +110,9 @@ namespace {
/// in Mask are known to be either zero or one and return them in the /// in Mask are known to be either zero or one and return them in the
/// KnownZero/KnownOne bitsets. /// KnownZero/KnownOne bitsets.
virtual void computeMaskedBitsForTargetNode(const SDOperand Op, virtual void computeMaskedBitsForTargetNode(const SDOperand Op,
uint64_t Mask, APInt Mask,
uint64_t &KnownZero, APInt &KnownZero,
uint64_t &KnownOne, APInt &KnownOne,
const SelectionDAG &DAG, const SelectionDAG &DAG,
unsigned Depth = 0) const; unsigned Depth = 0) const;
@@ -270,13 +270,13 @@ const char *SparcTargetLowering::getTargetNodeName(unsigned Opcode) const {
/// be zero. Op is expected to be a target specific node. Used by DAG /// be zero. Op is expected to be a target specific node. Used by DAG
/// combiner. /// combiner.
void SparcTargetLowering::computeMaskedBitsForTargetNode(const SDOperand Op, void SparcTargetLowering::computeMaskedBitsForTargetNode(const SDOperand Op,
uint64_t Mask, APInt Mask,
uint64_t &KnownZero, APInt &KnownZero,
uint64_t &KnownOne, APInt &KnownOne,
const SelectionDAG &DAG, const SelectionDAG &DAG,
unsigned Depth) const { unsigned Depth) const {
uint64_t KnownZero2, KnownOne2; APInt KnownZero2, KnownOne2;
KnownZero = KnownOne = 0; // Don't know anything. KnownZero = KnownOne = APInt(Mask.getBitWidth(), 0); // Don't know anything.
switch (Op.getOpcode()) { switch (Op.getOpcode()) {
default: break; default: break;

View File

@@ -5640,9 +5640,9 @@ X86TargetLowering::EmitInstrWithCustomInserter(MachineInstr *MI,
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
void X86TargetLowering::computeMaskedBitsForTargetNode(const SDOperand Op, void X86TargetLowering::computeMaskedBitsForTargetNode(const SDOperand Op,
uint64_t Mask, APInt Mask,
uint64_t &KnownZero, APInt &KnownZero,
uint64_t &KnownOne, APInt &KnownOne,
const SelectionDAG &DAG, const SelectionDAG &DAG,
unsigned Depth) const { unsigned Depth) const {
unsigned Opc = Op.getOpcode(); unsigned Opc = Op.getOpcode();
@@ -5657,7 +5657,8 @@ void X86TargetLowering::computeMaskedBitsForTargetNode(const SDOperand Op,
switch (Opc) { switch (Opc) {
default: break; default: break;
case X86ISD::SETCC: case X86ISD::SETCC:
KnownZero |= (MVT::getIntVTBitMask(Op.getValueType()) ^ 1ULL); KnownZero |= APInt::getHighBitsSet(Mask.getBitWidth(),
Mask.getBitWidth() - 1);
break; break;
} }
} }

View File

@@ -379,9 +379,9 @@ namespace llvm {
/// in Mask are known to be either zero or one and return them in the /// in Mask are known to be either zero or one and return them in the
/// KnownZero/KnownOne bitsets. /// KnownZero/KnownOne bitsets.
virtual void computeMaskedBitsForTargetNode(const SDOperand Op, virtual void computeMaskedBitsForTargetNode(const SDOperand Op,
uint64_t Mask, APInt Mask,
uint64_t &KnownZero, APInt &KnownZero,
uint64_t &KnownOne, APInt &KnownOne,
const SelectionDAG &DAG, const SelectionDAG &DAG,
unsigned Depth = 0) const; unsigned Depth = 0) const;