diff options
Diffstat (limited to 'llvm/include/llvm/Support/KnownBits.h')
-rw-r--r-- | llvm/include/llvm/Support/KnownBits.h | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/llvm/include/llvm/Support/KnownBits.h b/llvm/include/llvm/Support/KnownBits.h index 1f32760a6fd1..5ef0ba31f785 100644 --- a/llvm/include/llvm/Support/KnownBits.h +++ b/llvm/include/llvm/Support/KnownBits.h @@ -249,7 +249,17 @@ public: return countMinLeadingZeros(); if (isNegative()) return countMinLeadingOnes(); - return 0; + // Every value has at least 1 sign bit. + return 1; + } + + /// Returns the maximum number of bits needed to represent all possible + /// signed values with these known bits. This is the inverse of the minimum + /// number of known sign bits. Examples for bitwidth 5: + /// 110?? --> 4 + /// 0000? --> 2 + unsigned countMaxSignificantBits() const { + return getBitWidth() - countMinSignBits() + 1; } /// Returns the maximum number of trailing zero bits possible. @@ -282,6 +292,9 @@ public: return getBitWidth() - Zero.countPopulation(); } + /// Returns the maximum number of bits needed to represent all possible + /// unsigned values with these known bits. This is the inverse of the + /// minimum number of leading zeros. unsigned countMaxActiveBits() const { return getBitWidth() - countMinLeadingZeros(); } |