diff options
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Support/APInt.cpp | 33 | ||||
-rw-r--r-- | llvm/lib/Target/X86/X86ISelLowering.cpp | 12 | ||||
-rw-r--r-- | llvm/lib/Target/X86/X86ShuffleDecodeConstantPool.cpp | 3 |
3 files changed, 39 insertions, 9 deletions
diff --git a/llvm/lib/Support/APInt.cpp b/llvm/lib/Support/APInt.cpp index 35c15e04bf0..8ddbbe3a70d 100644 --- a/llvm/lib/Support/APInt.cpp +++ b/llvm/lib/Support/APInt.cpp @@ -565,6 +565,39 @@ void APInt::setBit(unsigned bitPosition) { pVal[whichWord(bitPosition)] |= maskBit(bitPosition); } +void APInt::setBits(unsigned loBit, unsigned hiBit) { + assert(hiBit <= BitWidth && "hiBit out of range"); + assert(loBit <= hiBit && loBit <= BitWidth && "loBit out of range"); + + if (loBit == hiBit) + return; + + if (isSingleWord()) + *this |= APInt::getBitsSet(BitWidth, loBit, hiBit); + else { + unsigned hiBit1 = hiBit - 1; + unsigned loWord = whichWord(loBit); + unsigned hiWord = whichWord(hiBit1); + if (loWord == hiWord) { + // Set bits are all within the same word, create a [loBit,hiBit) mask. + uint64_t mask = UINT64_MAX; + mask >>= (APINT_BITS_PER_WORD - (hiBit - loBit)); + mask <<= whichBit(loBit); + pVal[loWord] |= mask; + } else { + // Set bits span multiple words, create a lo mask with set bits starting + // at loBit, a hi mask with set bits below hiBit and set all bits of the + // words in between. + uint64_t loMask = UINT64_MAX << whichBit(loBit); + uint64_t hiMask = UINT64_MAX >> (64 - whichBit(hiBit1) - 1); + pVal[loWord] |= loMask; + pVal[hiWord] |= hiMask; + for (unsigned word = loWord + 1; word < hiWord; ++word) + pVal[word] = UINT64_MAX; + } + } +} + /// Set the given bit to 0 whose position is given as "bitPosition". /// @brief Set a given bit to 0. void APInt::clearBit(unsigned bitPosition) { diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp index 720f93a4fbe..6b404a498e3 100644 --- a/llvm/lib/Target/X86/X86ISelLowering.cpp +++ b/llvm/lib/Target/X86/X86ISelLowering.cpp @@ -5236,8 +5236,7 @@ static bool getTargetConstantBitsFromNode(SDValue Op, unsigned EltSizeInBits, return false; unsigned CstSizeInBits = Cst->getType()->getPrimitiveSizeInBits(); if (isa<UndefValue>(Cst)) { - unsigned HiBits = BitOffset + CstSizeInBits; - Undefs |= APInt::getBitsSet(SizeInBits, BitOffset, HiBits); + Undefs.setBits(BitOffset, BitOffset + CstSizeInBits); return true; } if (auto *CInt = dyn_cast<ConstantInt>(Cst)) { @@ -5258,8 +5257,7 @@ static bool getTargetConstantBitsFromNode(SDValue Op, unsigned EltSizeInBits, const SDValue &Src = Op.getOperand(i); unsigned BitOffset = i * SrcEltSizeInBits; if (Src.isUndef()) { - unsigned HiBits = BitOffset + SrcEltSizeInBits; - UndefBits |= APInt::getBitsSet(SizeInBits, BitOffset, HiBits); + UndefBits.setBits(BitOffset, BitOffset + SrcEltSizeInBits); continue; } auto *Cst = cast<ConstantSDNode>(Src); @@ -26353,11 +26351,11 @@ void X86TargetLowering::computeKnownBitsForTargetNode(const SDValue Op, break; LLVM_FALLTHROUGH; case X86ISD::SETCC: - KnownZero |= APInt::getHighBitsSet(BitWidth, BitWidth - 1); + KnownZero.setBits(1, BitWidth); break; case X86ISD::MOVMSK: { unsigned NumLoBits = Op.getOperand(0).getValueType().getVectorNumElements(); - KnownZero = APInt::getHighBitsSet(BitWidth, BitWidth - NumLoBits); + KnownZero.setBits(NumLoBits, BitWidth); break; } case X86ISD::VZEXT: { @@ -26374,7 +26372,7 @@ void X86TargetLowering::computeKnownBitsForTargetNode(const SDValue Op, DAG.computeKnownBits(N0, KnownZero, KnownOne, DemandedSrcElts, Depth + 1); KnownOne = KnownOne.zext(BitWidth); KnownZero = KnownZero.zext(BitWidth); - KnownZero |= APInt::getHighBitsSet(BitWidth, BitWidth - InBitWidth); + KnownZero.setBits(InBitWidth, BitWidth); break; } } diff --git a/llvm/lib/Target/X86/X86ShuffleDecodeConstantPool.cpp b/llvm/lib/Target/X86/X86ShuffleDecodeConstantPool.cpp index 4d278d4b05a..41ad0971461 100644 --- a/llvm/lib/Target/X86/X86ShuffleDecodeConstantPool.cpp +++ b/llvm/lib/Target/X86/X86ShuffleDecodeConstantPool.cpp @@ -60,8 +60,7 @@ static bool extractConstantMask(const Constant *C, unsigned MaskEltSizeInBits, unsigned BitOffset = i * CstEltSizeInBits; if (isa<UndefValue>(COp)) { - unsigned HiBits = BitOffset + CstEltSizeInBits; - UndefBits |= APInt::getBitsSet(CstSizeInBits, BitOffset, HiBits); + UndefBits.setBits(BitOffset, BitOffset + CstEltSizeInBits); continue; } |