diff options
-rw-r--r-- | include/llvm/ADT/APInt.h | 2 | ||||
-rw-r--r-- | include/llvm/Support/MathExtras.h | 6 |
2 files changed, 7 insertions, 1 deletions
diff --git a/include/llvm/ADT/APInt.h b/include/llvm/ADT/APInt.h index e03f63bebf..d398f8e3f6 100644 --- a/include/llvm/ADT/APInt.h +++ b/include/llvm/ADT/APInt.h @@ -348,7 +348,7 @@ public: return true; if (isSingleWord()) - return VAL == (VAL & (~0ULL >> (64 - N))); + return isUIntN(N, VAL); APInt Tmp(N, getNumWords(), pVal); Tmp.zext(getBitWidth()); return Tmp == (*this); diff --git a/include/llvm/Support/MathExtras.h b/include/llvm/Support/MathExtras.h index 3b907808dd..dafb479a99 100644 --- a/include/llvm/Support/MathExtras.h +++ b/include/llvm/Support/MathExtras.h @@ -71,6 +71,12 @@ inline bool isUInt<32>(uint64_t x) { return static_cast<uint32_t>(x) == x; } +/// isUIntN - Checks if an unsigned integer fits into the given (dynamic) +/// bit width. +inline bool isUIntN(unsigned N, uint64_t x) { + return x == (x & (~0ULL >> (64 - N))); +} + /// isMask_32 - This function returns true if the argument is a sequence of ones /// starting at the least significant bit with the remainder zero (32 bit /// version). Ex. isMask_32(0x0000FFFFU) == true. |