diff options
Diffstat (limited to 'contrib/llvm-project/llvm/lib/Support/APInt.cpp')
-rw-r--r-- | contrib/llvm-project/llvm/lib/Support/APInt.cpp | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/contrib/llvm-project/llvm/lib/Support/APInt.cpp b/contrib/llvm-project/llvm/lib/Support/APInt.cpp index 9a6f93feaa29..12ceb2df112e 100644 --- a/contrib/llvm-project/llvm/lib/Support/APInt.cpp +++ b/contrib/llvm-project/llvm/lib/Support/APInt.cpp @@ -338,8 +338,7 @@ void APInt::flipAllBitsSlowCase() { /// Toggles a given bit to its opposite value. void APInt::flipBit(unsigned bitPosition) { assert(bitPosition < BitWidth && "Out of the bit-width range!"); - if ((*this)[bitPosition]) clearBit(bitPosition); - else setBit(bitPosition); + setBitVal(bitPosition, !(*this)[bitPosition]); } void APInt::insertBits(const APInt &subBits, unsigned bitPosition) { @@ -393,12 +392,8 @@ void APInt::insertBits(const APInt &subBits, unsigned bitPosition) { // General case - set/clear individual bits in dst based on src. // TODO - there is scope for optimization here, but at the moment this code // path is barely used so prefer readability over performance. - for (unsigned i = 0; i != subBitWidth; ++i) { - if (subBits[i]) - setBit(bitPosition + i); - else - clearBit(bitPosition + i); - } + for (unsigned i = 0; i != subBitWidth; ++i) + setBitVal(bitPosition + i, subBits[i]); } void APInt::insertBits(uint64_t subBits, unsigned bitPosition, unsigned numBits) { @@ -966,6 +961,12 @@ APInt APInt::sextOrTrunc(unsigned width) const { return *this; } +APInt APInt::truncOrSelf(unsigned width) const { + if (BitWidth > width) + return trunc(width); + return *this; +} + APInt APInt::zextOrSelf(unsigned width) const { if (BitWidth < width) return zext(width); |