forked from OSchip/llvm-project
[CodeGen] Use APInt::setLowBits/setHighBits/setBitsFrom in more places
This patch replaces ORs with getHighBits/getLowBits etc. with setLowBits/setHighBits/setBitsFrom. In a few of the places we weren't ORing, but the KnownZero/KnownOne vectors were already initialized to zero. We exploit this in most places already there were just some that were inconsistent. Differential Revision: https://reviews.llvm.org/D30965 llvm-svn: 297860
This commit is contained in:
parent
1a6deeefe0
commit
bcb6093610
|
@ -2251,10 +2251,9 @@ void SelectionDAG::computeKnownBits(SDValue Op, APInt &KnownZero,
|
|||
KnownZero2.countLeadingOnes(),
|
||||
BitWidth) - BitWidth;
|
||||
|
||||
TrailZ = std::min(TrailZ, BitWidth);
|
||||
LeadZ = std::min(LeadZ, BitWidth);
|
||||
KnownZero = APInt::getLowBitsSet(BitWidth, TrailZ) |
|
||||
APInt::getHighBitsSet(BitWidth, LeadZ);
|
||||
KnownZero.clearAllBits();
|
||||
KnownZero.setLowBits(std::min(TrailZ, BitWidth));
|
||||
KnownZero.setHighBits(std::min(LeadZ, BitWidth));
|
||||
break;
|
||||
}
|
||||
case ISD::UDIV: {
|
||||
|
@ -2272,7 +2271,7 @@ void SelectionDAG::computeKnownBits(SDValue Op, APInt &KnownZero,
|
|||
LeadZ = std::min(BitWidth,
|
||||
LeadZ + BitWidth - RHSUnknownLeadingOnes - 1);
|
||||
|
||||
KnownZero = APInt::getHighBitsSet(BitWidth, LeadZ);
|
||||
KnownZero.setHighBits(LeadZ);
|
||||
break;
|
||||
}
|
||||
case ISD::SELECT:
|
||||
|
@ -2345,13 +2344,12 @@ void SelectionDAG::computeKnownBits(SDValue Op, APInt &KnownZero,
|
|||
KnownOne = KnownOne.lshr(*ShAmt);
|
||||
// If we know the value of the sign bit, then we know it is copied across
|
||||
// the high bits by the shift amount.
|
||||
APInt HighBits = APInt::getHighBitsSet(BitWidth, ShAmt->getZExtValue());
|
||||
APInt SignBit = APInt::getSignBit(BitWidth);
|
||||
SignBit = SignBit.lshr(*ShAmt); // Adjust to where it is now in the mask.
|
||||
if (KnownZero.intersects(SignBit)) {
|
||||
KnownZero |= HighBits; // New bits are known zero.
|
||||
KnownZero.setHighBits(ShAmt->getZExtValue());// New bits are known zero.
|
||||
} else if (KnownOne.intersects(SignBit)) {
|
||||
KnownOne |= HighBits; // New bits are known one.
|
||||
KnownOne.setHighBits(ShAmt->getZExtValue()); // New bits are known one.
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -2396,9 +2394,7 @@ void SelectionDAG::computeKnownBits(SDValue Op, APInt &KnownZero,
|
|||
case ISD::CTLZ:
|
||||
case ISD::CTLZ_ZERO_UNDEF:
|
||||
case ISD::CTPOP: {
|
||||
unsigned LowBits = Log2_32(BitWidth)+1;
|
||||
KnownZero = APInt::getHighBitsSet(BitWidth, BitWidth - LowBits);
|
||||
KnownOne.clearAllBits();
|
||||
KnownZero.setBitsFrom(Log2_32(BitWidth)+1);
|
||||
break;
|
||||
}
|
||||
case ISD::LOAD: {
|
||||
|
@ -2407,7 +2403,7 @@ void SelectionDAG::computeKnownBits(SDValue Op, APInt &KnownZero,
|
|||
if (ISD::isZEXTLoad(Op.getNode()) && Op.getResNo() == 0) {
|
||||
EVT VT = LD->getMemoryVT();
|
||||
unsigned MemBits = VT.getScalarSizeInBits();
|
||||
KnownZero |= APInt::getHighBitsSet(BitWidth, BitWidth - MemBits);
|
||||
KnownZero.setBitsFrom(MemBits);
|
||||
} else if (const MDNode *Ranges = LD->getRanges()) {
|
||||
if (LD->getExtensionType() == ISD::NON_EXTLOAD)
|
||||
computeKnownBitsFromRangeMetadata(*Ranges, KnownZero, KnownOne);
|
||||
|
@ -2417,7 +2413,6 @@ void SelectionDAG::computeKnownBits(SDValue Op, APInt &KnownZero,
|
|||
case ISD::ZERO_EXTEND_VECTOR_INREG: {
|
||||
EVT InVT = Op.getOperand(0).getValueType();
|
||||
unsigned InBits = InVT.getScalarSizeInBits();
|
||||
APInt NewBits = APInt::getHighBitsSet(BitWidth, BitWidth - InBits);
|
||||
KnownZero = KnownZero.trunc(InBits);
|
||||
KnownOne = KnownOne.trunc(InBits);
|
||||
computeKnownBits(Op.getOperand(0), KnownZero, KnownOne,
|
||||
|
@ -2425,20 +2420,19 @@ void SelectionDAG::computeKnownBits(SDValue Op, APInt &KnownZero,
|
|||
Depth + 1);
|
||||
KnownZero = KnownZero.zext(BitWidth);
|
||||
KnownOne = KnownOne.zext(BitWidth);
|
||||
KnownZero |= NewBits;
|
||||
KnownZero.setBitsFrom(InBits);
|
||||
break;
|
||||
}
|
||||
case ISD::ZERO_EXTEND: {
|
||||
EVT InVT = Op.getOperand(0).getValueType();
|
||||
unsigned InBits = InVT.getScalarSizeInBits();
|
||||
APInt NewBits = APInt::getHighBitsSet(BitWidth, BitWidth - InBits);
|
||||
KnownZero = KnownZero.trunc(InBits);
|
||||
KnownOne = KnownOne.trunc(InBits);
|
||||
computeKnownBits(Op.getOperand(0), KnownZero, KnownOne, DemandedElts,
|
||||
Depth + 1);
|
||||
KnownZero = KnownZero.zext(BitWidth);
|
||||
KnownOne = KnownOne.zext(BitWidth);
|
||||
KnownZero |= NewBits;
|
||||
KnownZero.setBitsFrom(InBits);
|
||||
break;
|
||||
}
|
||||
// TODO ISD::SIGN_EXTEND_VECTOR_INREG
|
||||
|
@ -2488,7 +2482,7 @@ void SelectionDAG::computeKnownBits(SDValue Op, APInt &KnownZero,
|
|||
}
|
||||
case ISD::FGETSIGN:
|
||||
// All bits are zero except the low bit.
|
||||
KnownZero = APInt::getHighBitsSet(BitWidth, BitWidth - 1);
|
||||
KnownZero.setBitsFrom(1);
|
||||
break;
|
||||
case ISD::USUBO:
|
||||
case ISD::SSUBO:
|
||||
|
@ -2520,7 +2514,7 @@ void SelectionDAG::computeKnownBits(SDValue Op, APInt &KnownZero,
|
|||
if ((KnownZero2 & MaskV) == MaskV) {
|
||||
unsigned NLZ2 = CLHS->getAPIntValue().countLeadingZeros();
|
||||
// Top bits known zero.
|
||||
KnownZero = APInt::getHighBitsSet(BitWidth, NLZ2);
|
||||
KnownZero.setHighBits(NLZ2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2639,7 +2633,8 @@ void SelectionDAG::computeKnownBits(SDValue Op, APInt &KnownZero,
|
|||
uint32_t Leaders = std::max(KnownZero.countLeadingOnes(),
|
||||
KnownZero2.countLeadingOnes());
|
||||
KnownOne.clearAllBits();
|
||||
KnownZero = APInt::getHighBitsSet(BitWidth, Leaders);
|
||||
KnownZero.clearAllBits();
|
||||
KnownZero.setHighBits(Leaders);
|
||||
break;
|
||||
}
|
||||
case ISD::EXTRACT_ELEMENT: {
|
||||
|
@ -2784,7 +2779,7 @@ void SelectionDAG::computeKnownBits(SDValue Op, APInt &KnownZero,
|
|||
case ISD::TargetFrameIndex:
|
||||
if (unsigned Align = InferPtrAlignment(Op)) {
|
||||
// The low bits are known zero if the pointer is aligned.
|
||||
KnownZero = APInt::getLowBitsSet(BitWidth, Log2_32(Align));
|
||||
KnownZero.setLowBits(Log2_32(Align));
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -873,7 +873,7 @@ bool TargetLowering::SimplifyDemandedBits(SDValue Op,
|
|||
KnownZero <<= SA->getZExtValue();
|
||||
KnownOne <<= SA->getZExtValue();
|
||||
// low bits known zero.
|
||||
KnownZero |= APInt::getLowBitsSet(BitWidth, SA->getZExtValue());
|
||||
KnownZero.setLowBits(SA->getZExtValue());
|
||||
}
|
||||
break;
|
||||
case ISD::SRL:
|
||||
|
@ -892,7 +892,7 @@ bool TargetLowering::SimplifyDemandedBits(SDValue Op,
|
|||
// If the shift is exact, then it does demand the low bits (and knows that
|
||||
// they are zero).
|
||||
if (cast<BinaryWithFlagsSDNode>(Op)->Flags.hasExact())
|
||||
InDemandedMask |= APInt::getLowBitsSet(BitWidth, ShAmt);
|
||||
InDemandedMask.setLowBits(ShAmt);
|
||||
|
||||
// If this is ((X << C1) >>u ShAmt), see if we can simplify this into a
|
||||
// single shift. We can do this if the top bits (which are shifted out)
|
||||
|
@ -923,8 +923,7 @@ bool TargetLowering::SimplifyDemandedBits(SDValue Op,
|
|||
KnownZero = KnownZero.lshr(ShAmt);
|
||||
KnownOne = KnownOne.lshr(ShAmt);
|
||||
|
||||
APInt HighBits = APInt::getHighBitsSet(BitWidth, ShAmt);
|
||||
KnownZero |= HighBits; // High bits known zero.
|
||||
KnownZero.setHighBits(ShAmt); // High bits known zero.
|
||||
}
|
||||
break;
|
||||
case ISD::SRA:
|
||||
|
@ -950,7 +949,7 @@ bool TargetLowering::SimplifyDemandedBits(SDValue Op,
|
|||
// If the shift is exact, then it does demand the low bits (and knows that
|
||||
// they are zero).
|
||||
if (cast<BinaryWithFlagsSDNode>(Op)->Flags.hasExact())
|
||||
InDemandedMask |= APInt::getLowBitsSet(BitWidth, ShAmt);
|
||||
InDemandedMask.setLowBits(ShAmt);
|
||||
|
||||
// If any of the demanded bits are produced by the sign extension, we also
|
||||
// demand the input sign bit.
|
||||
|
|
Loading…
Reference in New Issue