PR5207: Rename overloaded APInt methods set(), clear(), flip() to

setAllBits(), setBit(unsigned), etc.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120564 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Jay Foad 2010-12-01 08:53:58 +00:00
parent ce2b68fb54
commit 7a874ddda0
11 changed files with 66 additions and 66 deletions

View File

@ -380,15 +380,15 @@ public:
/// @brief Gets maximum unsigned value of APInt for specific bit width. /// @brief Gets maximum unsigned value of APInt for specific bit width.
static APInt getMaxValue(unsigned numBits) { static APInt getMaxValue(unsigned numBits) {
APInt API(numBits, 0); APInt API(numBits, 0);
API.set(); API.setAllBits();
return API; return API;
} }
/// @brief Gets maximum signed value of APInt for a specific bit width. /// @brief Gets maximum signed value of APInt for a specific bit width.
static APInt getSignedMaxValue(unsigned numBits) { static APInt getSignedMaxValue(unsigned numBits) {
APInt API(numBits, 0); APInt API(numBits, 0);
API.set(); API.setAllBits();
API.clear(numBits - 1); API.clearBit(numBits - 1);
return API; return API;
} }
@ -400,7 +400,7 @@ public:
/// @brief Gets minimum signed value of APInt for a specific bit width. /// @brief Gets minimum signed value of APInt for a specific bit width.
static APInt getSignedMinValue(unsigned numBits) { static APInt getSignedMinValue(unsigned numBits) {
APInt API(numBits, 0); APInt API(numBits, 0);
API.set(numBits - 1); API.setBit(numBits - 1);
return API; return API;
} }
@ -415,7 +415,7 @@ public:
/// @brief Get the all-ones value. /// @brief Get the all-ones value.
static APInt getAllOnesValue(unsigned numBits) { static APInt getAllOnesValue(unsigned numBits) {
APInt API(numBits, 0); APInt API(numBits, 0);
API.set(); API.setAllBits();
return API; return API;
} }
@ -533,7 +533,7 @@ public:
/// @brief Unary bitwise complement operator. /// @brief Unary bitwise complement operator.
APInt operator~() const { APInt operator~() const {
APInt Result(*this); APInt Result(*this);
Result.flip(); Result.flipAllBits();
return Result; return Result;
} }
@ -1044,7 +1044,7 @@ public:
/// @name Bit Manipulation Operators /// @name Bit Manipulation Operators
/// @{ /// @{
/// @brief Set every bit to 1. /// @brief Set every bit to 1.
void set() { void setAllBits() {
if (isSingleWord()) if (isSingleWord())
VAL = -1ULL; VAL = -1ULL;
else { else {
@ -1058,10 +1058,10 @@ public:
/// Set the given bit to 1 whose position is given as "bitPosition". /// Set the given bit to 1 whose position is given as "bitPosition".
/// @brief Set a given bit to 1. /// @brief Set a given bit to 1.
void set(unsigned bitPosition); void setBit(unsigned bitPosition);
/// @brief Set every bit to 0. /// @brief Set every bit to 0.
void clear() { void clearAllBits() {
if (isSingleWord()) if (isSingleWord())
VAL = 0; VAL = 0;
else else
@ -1070,10 +1070,10 @@ public:
/// Set the given bit to 0 whose position is given as "bitPosition". /// Set the given bit to 0 whose position is given as "bitPosition".
/// @brief Set a given bit to 0. /// @brief Set a given bit to 0.
void clear(unsigned bitPosition); void clearBit(unsigned bitPosition);
/// @brief Toggle every bit to its opposite value. /// @brief Toggle every bit to its opposite value.
void flip() { void flipAllBits() {
if (isSingleWord()) if (isSingleWord())
VAL ^= -1ULL; VAL ^= -1ULL;
else { else {
@ -1086,7 +1086,7 @@ public:
/// Toggle a given bit to its opposite value whose position is given /// Toggle a given bit to its opposite value whose position is given
/// as "bitPosition". /// as "bitPosition".
/// @brief Toggles a given bit to its opposite value. /// @brief Toggles a given bit to its opposite value.
void flip(unsigned bitPosition); void flipBit(unsigned bitPosition);
/// @} /// @}
/// @name Value Characterization Functions /// @name Value Characterization Functions

View File

@ -4602,7 +4602,7 @@ static const SCEV *SolveLinEquationWithOverflow(const APInt &A, const APInt &B,
// bit width during computations. // bit width during computations.
APInt AD = A.lshr(Mult2).zext(BW + 1); // AD = A / D APInt AD = A.lshr(Mult2).zext(BW + 1); // AD = A / D
APInt Mod(BW + 1, 0); APInt Mod(BW + 1, 0);
Mod.set(BW - Mult2); // Mod = N / D Mod.setBit(BW - Mult2); // Mod = N / D
APInt I = AD.multiplicativeInverse(Mod); APInt I = AD.multiplicativeInverse(Mod);
// 4. Compute the minimum unsigned root of the equation: // 4. Compute the minimum unsigned root of the equation:

View File

@ -69,14 +69,14 @@ void llvm::ComputeMaskedBits(Value *V, const APInt &Mask,
// Null and aggregate-zero are all-zeros. // Null and aggregate-zero are all-zeros.
if (isa<ConstantPointerNull>(V) || if (isa<ConstantPointerNull>(V) ||
isa<ConstantAggregateZero>(V)) { isa<ConstantAggregateZero>(V)) {
KnownOne.clear(); KnownOne.clearAllBits();
KnownZero = Mask; KnownZero = Mask;
return; return;
} }
// Handle a constant vector by taking the intersection of the known bits of // Handle a constant vector by taking the intersection of the known bits of
// each element. // each element.
if (ConstantVector *CV = dyn_cast<ConstantVector>(V)) { if (ConstantVector *CV = dyn_cast<ConstantVector>(V)) {
KnownZero.set(); KnownOne.set(); KnownZero.setAllBits(); KnownOne.setAllBits();
for (unsigned i = 0, e = CV->getNumOperands(); i != e; ++i) { for (unsigned i = 0, e = CV->getNumOperands(); i != e; ++i) {
APInt KnownZero2(BitWidth, 0), KnownOne2(BitWidth, 0); APInt KnownZero2(BitWidth, 0), KnownOne2(BitWidth, 0);
ComputeMaskedBits(CV->getOperand(i), Mask, KnownZero2, KnownOne2, ComputeMaskedBits(CV->getOperand(i), Mask, KnownZero2, KnownOne2,
@ -103,15 +103,15 @@ void llvm::ComputeMaskedBits(Value *V, const APInt &Mask,
KnownZero = Mask & APInt::getLowBitsSet(BitWidth, KnownZero = Mask & APInt::getLowBitsSet(BitWidth,
CountTrailingZeros_32(Align)); CountTrailingZeros_32(Align));
else else
KnownZero.clear(); KnownZero.clearAllBits();
KnownOne.clear(); KnownOne.clearAllBits();
return; return;
} }
// A weak GlobalAlias is totally unknown. A non-weak GlobalAlias has // A weak GlobalAlias is totally unknown. A non-weak GlobalAlias has
// the bits of its aliasee. // the bits of its aliasee.
if (GlobalAlias *GA = dyn_cast<GlobalAlias>(V)) { if (GlobalAlias *GA = dyn_cast<GlobalAlias>(V)) {
if (GA->mayBeOverridden()) { if (GA->mayBeOverridden()) {
KnownZero.clear(); KnownOne.clear(); KnownZero.clearAllBits(); KnownOne.clearAllBits();
} else { } else {
ComputeMaskedBits(GA->getAliasee(), Mask, KnownZero, KnownOne, ComputeMaskedBits(GA->getAliasee(), Mask, KnownZero, KnownOne,
TD, Depth+1); TD, Depth+1);
@ -119,7 +119,7 @@ void llvm::ComputeMaskedBits(Value *V, const APInt &Mask,
return; return;
} }
KnownZero.clear(); KnownOne.clear(); // Start out not knowing anything. KnownZero.clearAllBits(); KnownOne.clearAllBits(); // Start out not knowing anything.
if (Depth == MaxDepth || Mask == 0) if (Depth == MaxDepth || Mask == 0)
return; // Limit search depth. return; // Limit search depth.
@ -185,7 +185,7 @@ void llvm::ComputeMaskedBits(Value *V, const APInt &Mask,
// Also compute a conserative estimate for high known-0 bits. // Also compute a conserative estimate for high known-0 bits.
// More trickiness is possible, but this is sufficient for the // More trickiness is possible, but this is sufficient for the
// interesting case of alignment computation. // interesting case of alignment computation.
KnownOne.clear(); KnownOne.clearAllBits();
unsigned TrailZ = KnownZero.countTrailingOnes() + unsigned TrailZ = KnownZero.countTrailingOnes() +
KnownZero2.countTrailingOnes(); KnownZero2.countTrailingOnes();
unsigned LeadZ = std::max(KnownZero.countLeadingOnes() + unsigned LeadZ = std::max(KnownZero.countLeadingOnes() +
@ -208,8 +208,8 @@ void llvm::ComputeMaskedBits(Value *V, const APInt &Mask,
AllOnes, KnownZero2, KnownOne2, TD, Depth+1); AllOnes, KnownZero2, KnownOne2, TD, Depth+1);
unsigned LeadZ = KnownZero2.countLeadingOnes(); unsigned LeadZ = KnownZero2.countLeadingOnes();
KnownOne2.clear(); KnownOne2.clearAllBits();
KnownZero2.clear(); KnownZero2.clearAllBits();
ComputeMaskedBits(I->getOperand(1), ComputeMaskedBits(I->getOperand(1),
AllOnes, KnownZero2, KnownOne2, TD, Depth+1); AllOnes, KnownZero2, KnownOne2, TD, Depth+1);
unsigned RHSUnknownLeadingOnes = KnownOne2.countLeadingZeros(); unsigned RHSUnknownLeadingOnes = KnownOne2.countLeadingZeros();
@ -474,7 +474,7 @@ void llvm::ComputeMaskedBits(Value *V, const APInt &Mask,
unsigned Leaders = std::max(KnownZero.countLeadingOnes(), unsigned Leaders = std::max(KnownZero.countLeadingOnes(),
KnownZero2.countLeadingOnes()); KnownZero2.countLeadingOnes());
KnownOne.clear(); KnownOne.clearAllBits();
KnownZero = APInt::getHighBitsSet(BitWidth, Leaders) & Mask; KnownZero = APInt::getHighBitsSet(BitWidth, Leaders) & Mask;
break; break;
} }
@ -876,7 +876,7 @@ bool llvm::ComputeMultiple(Value *V, unsigned Base, Value *&Multiple,
APInt Op1Int = Op1CI->getValue(); APInt Op1Int = Op1CI->getValue();
uint64_t BitToSet = Op1Int.getLimitedValue(Op1Int.getBitWidth() - 1); uint64_t BitToSet = Op1Int.getLimitedValue(Op1Int.getBitWidth() - 1);
APInt API(Op1Int.getBitWidth(), 0); APInt API(Op1Int.getBitWidth(), 0);
API.set(BitToSet); API.setBit(BitToSet);
Op1 = ConstantInt::get(V->getContext(), API); Op1 = ConstantInt::get(V->getContext(), API);
} }

View File

@ -134,7 +134,7 @@ SDValue DAGTypeLegalizer::SoftenFloatRes_FABS(SDNode *N) {
// Mask = ~(1 << (Size-1)) // Mask = ~(1 << (Size-1))
APInt API = APInt::getAllOnesValue(Size); APInt API = APInt::getAllOnesValue(Size);
API.clear(Size-1); API.clearBit(Size-1);
SDValue Mask = DAG.getConstant(API, NVT); SDValue Mask = DAG.getConstant(API, NVT);
SDValue Op = GetSoftenedFloat(N->getOperand(0)); SDValue Op = GetSoftenedFloat(N->getOperand(0));
return DAG.getNode(ISD::AND, N->getDebugLoc(), NVT, Op, Mask); return DAG.getNode(ISD::AND, N->getDebugLoc(), NVT, Op, Mask);

View File

@ -292,7 +292,7 @@ SDValue DAGTypeLegalizer::PromoteIntRes_CTTZ(SDNode *N) {
// value was zero. This can be handled by setting the bit just off // value was zero. This can be handled by setting the bit just off
// the top of the original type. // the top of the original type.
APInt TopBit(NVT.getSizeInBits(), 0); APInt TopBit(NVT.getSizeInBits(), 0);
TopBit.set(OVT.getSizeInBits()); TopBit.setBit(OVT.getSizeInBits());
Op = DAG.getNode(ISD::OR, dl, NVT, Op, DAG.getConstant(TopBit, NVT)); Op = DAG.getNode(ISD::OR, dl, NVT, Op, DAG.getConstant(TopBit, NVT));
return DAG.getNode(ISD::CTTZ, dl, NVT, Op); return DAG.getNode(ISD::CTTZ, dl, NVT, Op);
} }

View File

@ -1654,7 +1654,7 @@ void SelectionDAG::ComputeMaskedBits(SDValue Op, const APInt &Mask,
// Also compute a conserative estimate for high known-0 bits. // Also compute a conserative estimate for high known-0 bits.
// More trickiness is possible, but this is sufficient for the // More trickiness is possible, but this is sufficient for the
// interesting case of alignment computation. // interesting case of alignment computation.
KnownOne.clear(); KnownOne.clearAllBits();
unsigned TrailZ = KnownZero.countTrailingOnes() + unsigned TrailZ = KnownZero.countTrailingOnes() +
KnownZero2.countTrailingOnes(); KnownZero2.countTrailingOnes();
unsigned LeadZ = std::max(KnownZero.countLeadingOnes() + unsigned LeadZ = std::max(KnownZero.countLeadingOnes() +
@ -1677,8 +1677,8 @@ void SelectionDAG::ComputeMaskedBits(SDValue Op, const APInt &Mask,
AllOnes, KnownZero2, KnownOne2, Depth+1); AllOnes, KnownZero2, KnownOne2, Depth+1);
unsigned LeadZ = KnownZero2.countLeadingOnes(); unsigned LeadZ = KnownZero2.countLeadingOnes();
KnownOne2.clear(); KnownOne2.clearAllBits();
KnownZero2.clear(); KnownZero2.clearAllBits();
ComputeMaskedBits(Op.getOperand(1), ComputeMaskedBits(Op.getOperand(1),
AllOnes, KnownZero2, KnownOne2, Depth+1); AllOnes, KnownZero2, KnownOne2, Depth+1);
unsigned RHSUnknownLeadingOnes = KnownOne2.countLeadingZeros(); unsigned RHSUnknownLeadingOnes = KnownOne2.countLeadingZeros();
@ -1833,7 +1833,7 @@ void SelectionDAG::ComputeMaskedBits(SDValue Op, const APInt &Mask,
case ISD::CTPOP: { case ISD::CTPOP: {
unsigned LowBits = Log2_32(BitWidth)+1; unsigned LowBits = Log2_32(BitWidth)+1;
KnownZero = APInt::getHighBitsSet(BitWidth, BitWidth - LowBits); KnownZero = APInt::getHighBitsSet(BitWidth, BitWidth - LowBits);
KnownOne.clear(); KnownOne.clearAllBits();
return; return;
} }
case ISD::LOAD: { case ISD::LOAD: {
@ -2032,7 +2032,7 @@ void SelectionDAG::ComputeMaskedBits(SDValue Op, const APInt &Mask,
uint32_t Leaders = std::max(KnownZero.countLeadingOnes(), uint32_t Leaders = std::max(KnownZero.countLeadingOnes(),
KnownZero2.countLeadingOnes()); KnownZero2.countLeadingOnes());
KnownOne.clear(); KnownOne.clearAllBits();
KnownZero = APInt::getHighBitsSet(BitWidth, Leaders) & Mask; KnownZero = APInt::getHighBitsSet(BitWidth, Leaders) & Mask;
return; return;
} }

View File

@ -361,7 +361,7 @@ APInt& APInt::operator*=(const APInt& RHS) {
unsigned rhsWords = !rhsBits ? 0 : whichWord(rhsBits - 1) + 1; unsigned rhsWords = !rhsBits ? 0 : whichWord(rhsBits - 1) + 1;
if (!rhsWords) { if (!rhsWords) {
// X * 0 ===> 0 // X * 0 ===> 0
clear(); clearAllBits();
return *this; return *this;
} }
@ -373,7 +373,7 @@ APInt& APInt::operator*=(const APInt& RHS) {
mul(dest, pVal, lhsWords, RHS.pVal, rhsWords); mul(dest, pVal, lhsWords, RHS.pVal, rhsWords);
// Copy result back into *this // Copy result back into *this
clear(); clearAllBits();
unsigned wordsToCopy = destWords >= getNumWords() ? getNumWords() : destWords; unsigned wordsToCopy = destWords >= getNumWords() ? getNumWords() : destWords;
memcpy(pVal, dest, wordsToCopy * APINT_WORD_SIZE); memcpy(pVal, dest, wordsToCopy * APINT_WORD_SIZE);
@ -562,12 +562,12 @@ bool APInt::slt(const APInt& RHS) const {
bool rhsNeg = rhs.isNegative(); bool rhsNeg = rhs.isNegative();
if (lhsNeg) { if (lhsNeg) {
// Sign bit is set so perform two's complement to make it positive // Sign bit is set so perform two's complement to make it positive
lhs.flip(); lhs.flipAllBits();
lhs++; lhs++;
} }
if (rhsNeg) { if (rhsNeg) {
// Sign bit is set so perform two's complement to make it positive // Sign bit is set so perform two's complement to make it positive
rhs.flip(); rhs.flipAllBits();
rhs++; rhs++;
} }
@ -584,7 +584,7 @@ bool APInt::slt(const APInt& RHS) const {
return lhs.ult(rhs); return lhs.ult(rhs);
} }
void APInt::set(unsigned bitPosition) { void APInt::setBit(unsigned bitPosition) {
if (isSingleWord()) if (isSingleWord())
VAL |= maskBit(bitPosition); VAL |= maskBit(bitPosition);
else else
@ -593,7 +593,7 @@ void APInt::set(unsigned bitPosition) {
/// Set the given bit to 0 whose position is given as "bitPosition". /// Set the given bit to 0 whose position is given as "bitPosition".
/// @brief Set a given bit to 0. /// @brief Set a given bit to 0.
void APInt::clear(unsigned bitPosition) { void APInt::clearBit(unsigned bitPosition) {
if (isSingleWord()) if (isSingleWord())
VAL &= ~maskBit(bitPosition); VAL &= ~maskBit(bitPosition);
else else
@ -605,10 +605,10 @@ void APInt::clear(unsigned bitPosition) {
/// Toggle a given bit to its opposite value whose position is given /// Toggle a given bit to its opposite value whose position is given
/// as "bitPosition". /// as "bitPosition".
/// @brief Toggles a given bit to its opposite value. /// @brief Toggles a given bit to its opposite value.
void APInt::flip(unsigned bitPosition) { void APInt::flipBit(unsigned bitPosition) {
assert(bitPosition < BitWidth && "Out of the bit-width range!"); assert(bitPosition < BitWidth && "Out of the bit-width range!");
if ((*this)[bitPosition]) clear(bitPosition); if ((*this)[bitPosition]) clearBit(bitPosition);
else set(bitPosition); else setBit(bitPosition);
} }
unsigned APInt::getBitsNeeded(StringRef str, uint8_t radix) { unsigned APInt::getBitsNeeded(StringRef str, uint8_t radix) {
@ -1871,7 +1871,7 @@ void APInt::divide(const APInt LHS, unsigned lhsWords,
if (!Quotient->isSingleWord()) if (!Quotient->isSingleWord())
Quotient->pVal = getClearedMemory(Quotient->getNumWords()); Quotient->pVal = getClearedMemory(Quotient->getNumWords());
} else } else
Quotient->clear(); Quotient->clearAllBits();
// The quotient is in Q. Reconstitute the quotient into Quotient's low // The quotient is in Q. Reconstitute the quotient into Quotient's low
// order words. // order words.
@ -1902,7 +1902,7 @@ void APInt::divide(const APInt LHS, unsigned lhsWords,
if (!Remainder->isSingleWord()) if (!Remainder->isSingleWord())
Remainder->pVal = getClearedMemory(Remainder->getNumWords()); Remainder->pVal = getClearedMemory(Remainder->getNumWords());
} else } else
Remainder->clear(); Remainder->clearAllBits();
// The remainder is in R. Reconstitute the remainder into Remainder's low // The remainder is in R. Reconstitute the remainder into Remainder's low
// order words. // order words.
@ -2157,7 +2157,7 @@ void APInt::fromString(unsigned numbits, StringRef str, uint8_t radix) {
// If its negative, put it in two's complement form // If its negative, put it in two's complement form
if (isNeg) { if (isNeg) {
(*this)--; (*this)--;
this->flip(); this->flipAllBits();
} }
} }
@ -2205,7 +2205,7 @@ void APInt::toString(SmallVectorImpl<char> &Str, unsigned Radix,
// They want to print the signed version and it is a negative value // They want to print the signed version and it is a negative value
// Flip the bits and add one to turn it into the equivalent positive // Flip the bits and add one to turn it into the equivalent positive
// value and put a '-' in the result. // value and put a '-' in the result.
Tmp.flip(); Tmp.flipAllBits();
Tmp++; Tmp++;
Str.push_back('-'); Str.push_back('-');
} }

View File

@ -160,8 +160,8 @@ static void ComputeSignedMinMaxValuesFromKnownBits(const APInt& KnownZero,
Max = KnownOne|UnknownBits; Max = KnownOne|UnknownBits;
if (UnknownBits.isNegative()) { // Sign bit is unknown if (UnknownBits.isNegative()) { // Sign bit is unknown
Min.set(Min.getBitWidth()-1); Min.setBit(Min.getBitWidth()-1);
Max.clear(Max.getBitWidth()-1); Max.clearBit(Max.getBitWidth()-1);
} }
} }

View File

@ -121,13 +121,13 @@ Value *InstCombiner::SimplifyDemandedUseBits(Value *V, APInt DemandedMask,
} }
if (isa<ConstantPointerNull>(V)) { if (isa<ConstantPointerNull>(V)) {
// We know all of the bits for a constant! // We know all of the bits for a constant!
KnownOne.clear(); KnownOne.clearAllBits();
KnownZero = DemandedMask; KnownZero = DemandedMask;
return 0; return 0;
} }
KnownZero.clear(); KnownZero.clearAllBits();
KnownOne.clear(); KnownOne.clearAllBits();
if (DemandedMask == 0) { // Not demanding any bits from V. if (DemandedMask == 0) { // Not demanding any bits from V.
if (isa<UndefValue>(V)) if (isa<UndefValue>(V))
return 0; return 0;
@ -451,7 +451,7 @@ Value *InstCombiner::SimplifyDemandedUseBits(Value *V, APInt DemandedMask,
// 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 & DemandedMask) != 0) if ((NewBits & DemandedMask) != 0)
InputDemandedBits.set(SrcBitWidth-1); InputDemandedBits.setBit(SrcBitWidth-1);
InputDemandedBits.trunc(SrcBitWidth); InputDemandedBits.trunc(SrcBitWidth);
KnownZero.trunc(SrcBitWidth); KnownZero.trunc(SrcBitWidth);
@ -634,7 +634,7 @@ Value *InstCombiner::SimplifyDemandedUseBits(Value *V, APInt DemandedMask,
// If any of the "high bits" are demanded, we should set the sign bit as // If any of the "high bits" are demanded, we should set the sign bit as
// demanded. // demanded.
if (DemandedMask.countLeadingZeros() <= ShiftAmt) if (DemandedMask.countLeadingZeros() <= ShiftAmt)
DemandedMaskIn.set(BitWidth-1); DemandedMaskIn.setBit(BitWidth-1);
if (SimplifyDemandedBits(I->getOperandUse(0), DemandedMaskIn, if (SimplifyDemandedBits(I->getOperandUse(0), DemandedMaskIn,
KnownZero, KnownOne, Depth+1)) KnownZero, KnownOne, Depth+1))
return I; return I;
@ -793,10 +793,10 @@ Value *InstCombiner::SimplifyDemandedVectorElts(Value *V, APInt DemandedElts,
for (unsigned i = 0; i != VWidth; ++i) for (unsigned i = 0; i != VWidth; ++i)
if (!DemandedElts[i]) { // If not demanded, set to undef. if (!DemandedElts[i]) { // If not demanded, set to undef.
Elts.push_back(Undef); Elts.push_back(Undef);
UndefElts.set(i); UndefElts.setBit(i);
} else if (isa<UndefValue>(CV->getOperand(i))) { // Already undef. } else if (isa<UndefValue>(CV->getOperand(i))) { // Already undef.
Elts.push_back(Undef); Elts.push_back(Undef);
UndefElts.set(i); UndefElts.setBit(i);
} else { // Otherwise, defined. } else { // Otherwise, defined.
Elts.push_back(CV->getOperand(i)); Elts.push_back(CV->getOperand(i));
} }
@ -879,13 +879,13 @@ Value *InstCombiner::SimplifyDemandedVectorElts(Value *V, APInt DemandedElts,
// Otherwise, the element inserted overwrites whatever was there, so the // Otherwise, the element inserted overwrites whatever was there, so the
// input demanded set is simpler than the output set. // input demanded set is simpler than the output set.
APInt DemandedElts2 = DemandedElts; APInt DemandedElts2 = DemandedElts;
DemandedElts2.clear(IdxNo); DemandedElts2.clearBit(IdxNo);
TmpV = SimplifyDemandedVectorElts(I->getOperand(0), DemandedElts2, TmpV = SimplifyDemandedVectorElts(I->getOperand(0), DemandedElts2,
UndefElts, Depth+1); UndefElts, Depth+1);
if (TmpV) { I->setOperand(0, TmpV); MadeChange = true; } if (TmpV) { I->setOperand(0, TmpV); MadeChange = true; }
// The inserted element is defined. // The inserted element is defined.
UndefElts.clear(IdxNo); UndefElts.clearBit(IdxNo);
break; break;
} }
case Instruction::ShuffleVector: { case Instruction::ShuffleVector: {
@ -900,9 +900,9 @@ Value *InstCombiner::SimplifyDemandedVectorElts(Value *V, APInt DemandedElts,
assert(MaskVal < LHSVWidth * 2 && assert(MaskVal < LHSVWidth * 2 &&
"shufflevector mask index out of range!"); "shufflevector mask index out of range!");
if (MaskVal < LHSVWidth) if (MaskVal < LHSVWidth)
LeftDemanded.set(MaskVal); LeftDemanded.setBit(MaskVal);
else else
RightDemanded.set(MaskVal - LHSVWidth); RightDemanded.setBit(MaskVal - LHSVWidth);
} }
} }
} }
@ -921,16 +921,16 @@ Value *InstCombiner::SimplifyDemandedVectorElts(Value *V, APInt DemandedElts,
for (unsigned i = 0; i < VWidth; i++) { for (unsigned i = 0; i < VWidth; i++) {
unsigned MaskVal = Shuffle->getMaskValue(i); unsigned MaskVal = Shuffle->getMaskValue(i);
if (MaskVal == -1u) { if (MaskVal == -1u) {
UndefElts.set(i); UndefElts.setBit(i);
} else if (MaskVal < LHSVWidth) { } else if (MaskVal < LHSVWidth) {
if (UndefElts4[MaskVal]) { if (UndefElts4[MaskVal]) {
NewUndefElts = true; NewUndefElts = true;
UndefElts.set(i); UndefElts.setBit(i);
} }
} else { } else {
if (UndefElts3[MaskVal - LHSVWidth]) { if (UndefElts3[MaskVal - LHSVWidth]) {
NewUndefElts = true; NewUndefElts = true;
UndefElts.set(i); UndefElts.setBit(i);
} }
} }
} }
@ -973,7 +973,7 @@ Value *InstCombiner::SimplifyDemandedVectorElts(Value *V, APInt DemandedElts,
Ratio = VWidth/InVWidth; Ratio = VWidth/InVWidth;
for (unsigned OutIdx = 0; OutIdx != VWidth; ++OutIdx) { for (unsigned OutIdx = 0; OutIdx != VWidth; ++OutIdx) {
if (DemandedElts[OutIdx]) if (DemandedElts[OutIdx])
InputDemandedElts.set(OutIdx/Ratio); InputDemandedElts.setBit(OutIdx/Ratio);
} }
} else { } else {
// Untested so far. // Untested so far.
@ -985,7 +985,7 @@ Value *InstCombiner::SimplifyDemandedVectorElts(Value *V, APInt DemandedElts,
Ratio = InVWidth/VWidth; Ratio = InVWidth/VWidth;
for (unsigned InIdx = 0; InIdx != InVWidth; ++InIdx) for (unsigned InIdx = 0; InIdx != InVWidth; ++InIdx)
if (DemandedElts[InIdx/Ratio]) if (DemandedElts[InIdx/Ratio])
InputDemandedElts.set(InIdx); InputDemandedElts.setBit(InIdx);
} }
// div/rem demand all inputs, because they don't want divide by zero. // div/rem demand all inputs, because they don't want divide by zero.
@ -1004,7 +1004,7 @@ Value *InstCombiner::SimplifyDemandedVectorElts(Value *V, APInt DemandedElts,
// undef. // undef.
for (unsigned OutIdx = 0; OutIdx != VWidth; ++OutIdx) for (unsigned OutIdx = 0; OutIdx != VWidth; ++OutIdx)
if (UndefElts2[OutIdx/Ratio]) if (UndefElts2[OutIdx/Ratio])
UndefElts.set(OutIdx); UndefElts.setBit(OutIdx);
} else if (VWidth < InVWidth) { } else if (VWidth < InVWidth) {
llvm_unreachable("Unimp"); llvm_unreachable("Unimp");
// If there are more elements in the source than there are in the result, // If there are more elements in the source than there are in the result,
@ -1013,7 +1013,7 @@ Value *InstCombiner::SimplifyDemandedVectorElts(Value *V, APInt DemandedElts,
UndefElts = ~0ULL >> (64-VWidth); // Start out all undef. UndefElts = ~0ULL >> (64-VWidth); // Start out all undef.
for (unsigned InIdx = 0; InIdx != InVWidth; ++InIdx) for (unsigned InIdx = 0; InIdx != InVWidth; ++InIdx)
if (!UndefElts2[InIdx]) // Not undef? if (!UndefElts2[InIdx]) // Not undef?
UndefElts.clear(InIdx/Ratio); // Clear undef bit. UndefElts.clearBit(InIdx/Ratio); // Clear undef bit.
} }
break; break;
} }

View File

@ -160,7 +160,7 @@ Instruction *InstCombiner::visitExtractElementInst(ExtractElementInst &EI) {
if (EI.getOperand(0)->hasOneUse() && VectorWidth != 1) { if (EI.getOperand(0)->hasOneUse() && VectorWidth != 1) {
APInt UndefElts(VectorWidth, 0); APInt UndefElts(VectorWidth, 0);
APInt DemandedMask(VectorWidth, 0); APInt DemandedMask(VectorWidth, 0);
DemandedMask.set(IndexVal); DemandedMask.setBit(IndexVal);
if (Value *V = SimplifyDemandedVectorElts(EI.getOperand(0), if (Value *V = SimplifyDemandedVectorElts(EI.getOperand(0),
DemandedMask, UndefElts)) { DemandedMask, UndefElts)) {
EI.setOperand(0, V); EI.setOperand(0, V);

View File

@ -57,7 +57,7 @@ TEST(APIntTest, i33_Count) {
TEST(APIntTest, i65_Count) { TEST(APIntTest, i65_Count) {
APInt i65minus(65, 0, true); APInt i65minus(65, 0, true);
i65minus.set(64); i65minus.setBit(64);
EXPECT_EQ(0u, i65minus.countLeadingZeros()); EXPECT_EQ(0u, i65minus.countLeadingZeros());
EXPECT_EQ(1u, i65minus.countLeadingOnes()); EXPECT_EQ(1u, i65minus.countLeadingOnes());
EXPECT_EQ(65u, i65minus.getActiveBits()); EXPECT_EQ(65u, i65minus.getActiveBits());