summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Pilgrim <llvm-dev@redking.me.uk>2017-02-24 18:31:04 +0000
committerSimon Pilgrim <llvm-dev@redking.me.uk>2017-02-24 18:31:04 +0000
commitcdf2bd656a68b614a2224d69072f43690b5141d2 (patch)
treeabbb2a37bd01ef815b2976005c000bb2b4635f76
parentb078439250daafafa7e0ac01b11beed071566d5b (diff)
downloadbcm5719-llvm-cdf2bd656a68b614a2224d69072f43690b5141d2.tar.gz
bcm5719-llvm-cdf2bd656a68b614a2224d69072f43690b5141d2.zip
Revert: r296141 [APInt] Add APInt::extractBits() method to extract APInt subrange
The current pattern for extract bits in range is typically: Mask.lshr(BitOffset).trunc(SubSizeInBits); Which can be particularly slow for large APInts (MaskSizeInBits > 64) as they require the allocation of memory for the temporary variable. This is another of the compile time issues identified in PR32037 (see also D30265). This patch adds the APInt::extractBits() helper method which avoids the temporary memory allocation. Differential Revision: https://reviews.llvm.org/D30336 llvm-svn: 296147
-rw-r--r--llvm/include/llvm/ADT/APInt.h3
-rw-r--r--llvm/lib/Support/APInt.cpp32
-rw-r--r--llvm/lib/Target/X86/X86ISelLowering.cpp8
-rw-r--r--llvm/lib/Target/X86/X86ShuffleDecodeConstantPool.cpp7
-rw-r--r--llvm/unittests/ADT/APIntTest.cpp12
5 files changed, 8 insertions, 54 deletions
diff --git a/llvm/include/llvm/ADT/APInt.h b/llvm/include/llvm/ADT/APInt.h
index fa4233a0aa9..32fed77098c 100644
--- a/llvm/include/llvm/ADT/APInt.h
+++ b/llvm/include/llvm/ADT/APInt.h
@@ -1272,9 +1272,6 @@ public:
/// as "bitPosition".
void flipBit(unsigned bitPosition);
- /// Return an APInt with the extracted bits [bitPosition,bitPosition+numBits).
- APInt extractBits(unsigned numBits, unsigned bitPosition) const;
-
/// @}
/// \name Value Characterization Functions
/// @{
diff --git a/llvm/lib/Support/APInt.cpp b/llvm/lib/Support/APInt.cpp
index f0c8f6be433..8ddbbe3a70d 100644
--- a/llvm/lib/Support/APInt.cpp
+++ b/llvm/lib/Support/APInt.cpp
@@ -618,38 +618,6 @@ void APInt::flipBit(unsigned bitPosition) {
else setBit(bitPosition);
}
-APInt APInt::extractBits(unsigned numBits, unsigned bitPosition) const {
- assert(0 < numBits && "Can't extract zero bits");
- assert(bitPosition < BitWidth && (numBits + bitPosition) <= BitWidth &&
- "Illegal bit extraction");
-
- unsigned loBit = whichBit(bitPosition);
- if (isSingleWord())
- return APInt(numBits, VAL >> loBit);
-
- unsigned loWord = whichWord(bitPosition);
- unsigned hiWord = whichWord(bitPosition + numBits - 1);
-
- // Single word result extracting bits from a single word source.
- if (loWord == hiWord)
- return APInt(numBits, pVal[loWord] >> loBit);
-
- // Extracting bits that start on a source word boundary can be done
- // as a fast memory copy.
- if (loBit == 0)
- return APInt(numBits, makeArrayRef(pVal + loWord, 1 + hiWord - loWord));
-
- // General case - shift + copy source words into place.
- APInt Result(numBits, 0);
- uint64_t *pDst = Result.pVal;
- for (unsigned word = loWord; word < hiWord; ++word, ++pDst) {
- uint64_t w0 = pVal[word + 0];
- uint64_t w1 = pVal[word + 1];
- *pDst = (w0 >> loBit) | (w1 << (APINT_BITS_PER_WORD - loBit));
- }
- return Result.clearUnusedBits();
-}
-
unsigned APInt::getBitsNeeded(StringRef str, uint8_t radix) {
assert(!str.empty() && "Invalid string length");
assert((radix == 10 || radix == 8 || radix == 16 || radix == 2 ||
diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp
index 348f8308099..618d7a8c561 100644
--- a/llvm/lib/Target/X86/X86ISelLowering.cpp
+++ b/llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -5207,8 +5207,8 @@ static bool getTargetConstantBitsFromNode(SDValue Op, unsigned EltSizeInBits,
EltBits.resize(NumElts, APInt(EltSizeInBits, 0));
for (unsigned i = 0; i != NumElts; ++i) {
- unsigned BitOffset = i * EltSizeInBits;
- APInt UndefEltBits = UndefBits.extractBits(EltSizeInBits, BitOffset);
+ APInt UndefEltBits = UndefBits.lshr(i * EltSizeInBits);
+ UndefEltBits = UndefEltBits.zextOrTrunc(EltSizeInBits);
// Only treat an element as UNDEF if all bits are UNDEF.
if (UndefEltBits.isAllOnesValue()) {
@@ -5223,7 +5223,7 @@ static bool getTargetConstantBitsFromNode(SDValue Op, unsigned EltSizeInBits,
if (UndefEltBits.getBoolValue() && !AllowPartialUndefs)
return false;
- APInt Bits = MaskBits.extractBits(EltSizeInBits, BitOffset);
+ APInt Bits = MaskBits.lshr(i * EltSizeInBits).zextOrTrunc(EltSizeInBits);
EltBits[i] = Bits.getZExtValue();
}
return true;
@@ -6421,7 +6421,7 @@ static Constant *getConstantVector(MVT VT, const APInt &SplatValue,
SmallVector<Constant *, 32> ConstantVec;
for (unsigned i = 0; i < NumElm; i++) {
- APInt Val = SplatValue.extractBits(ScalarSize, ScalarSize * i);
+ APInt Val = SplatValue.lshr(ScalarSize * i).trunc(ScalarSize);
Constant *Const;
if (VT.isFloatingPoint()) {
assert((ScalarSize == 32 || ScalarSize == 64) &&
diff --git a/llvm/lib/Target/X86/X86ShuffleDecodeConstantPool.cpp b/llvm/lib/Target/X86/X86ShuffleDecodeConstantPool.cpp
index c24b74f7480..41ad0971461 100644
--- a/llvm/lib/Target/X86/X86ShuffleDecodeConstantPool.cpp
+++ b/llvm/lib/Target/X86/X86ShuffleDecodeConstantPool.cpp
@@ -77,8 +77,8 @@ static bool extractConstantMask(const Constant *C, unsigned MaskEltSizeInBits,
RawMask.resize(NumMaskElts, 0);
for (unsigned i = 0; i != NumMaskElts; ++i) {
- unsigned BitOffset = i * MaskEltSizeInBits;
- APInt EltUndef = UndefBits.extractBits(MaskEltSizeInBits, BitOffset);
+ APInt EltUndef = UndefBits.lshr(i * MaskEltSizeInBits);
+ EltUndef = EltUndef.zextOrTrunc(MaskEltSizeInBits);
// Only treat the element as UNDEF if all bits are UNDEF, otherwise
// treat it as zero.
@@ -88,7 +88,8 @@ static bool extractConstantMask(const Constant *C, unsigned MaskEltSizeInBits,
continue;
}
- APInt EltBits = MaskBits.extractBits(MaskEltSizeInBits, BitOffset);
+ APInt EltBits = MaskBits.lshr(i * MaskEltSizeInBits);
+ EltBits = EltBits.zextOrTrunc(MaskEltSizeInBits);
RawMask[i] = EltBits.getZExtValue();
}
diff --git a/llvm/unittests/ADT/APIntTest.cpp b/llvm/unittests/ADT/APIntTest.cpp
index e8923b6ac01..39a88cdca90 100644
--- a/llvm/unittests/ADT/APIntTest.cpp
+++ b/llvm/unittests/ADT/APIntTest.cpp
@@ -1434,18 +1434,6 @@ TEST(APIntTest, isMask) {
}
}
-TEST(APIntTest, extractBits) {
- APInt i32(32, 0x1234567);
- EXPECT_EQ(0x3456, i32.extractBits(16, 4));
-
- APInt i256(256, -16776961 /* 0xFFFFFFFFFFFFFFFFFFFFFFFFFF0000FF */, true);
- EXPECT_EQ(255, i256.extractBits(16, 0));
- EXPECT_EQ(127, i256.extractBits(16, 1));
- EXPECT_EQ(-1, i256.extractBits(32, 64).getSExtValue());
- EXPECT_EQ(-1, i256.extractBits(128, 128).getSExtValue());
- EXPECT_EQ(-8388481, i256.extractBits(128, 1).getSExtValue());
-}
-
#if defined(__clang__)
// Disable the pragma warning from versions of Clang without -Wself-move
#pragma clang diagnostic push
OpenPOWER on IntegriCloud