[llvm] [APInt] Added APInt::clearBits() method (PR #137098)
Jay Foad via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 25 06:22:37 PDT 2025
================
@@ -1413,6 +1413,26 @@ class [[nodiscard]] APInt {
U.pVal[whichWord(BitPosition)] &= Mask;
}
+ /// Clear the bits from loBit (inclusive) to hiBit (exclusive) to 0.
+ /// This function handles case when \p loBit <= \p hiBit.
+ void clearBits(unsigned loBit, unsigned hiBit) {
+ assert(hiBit <= BitWidth && "hiBit out of range");
+ assert(loBit <= BitWidth && "loBit out of range");
+ assert(loBit <= hiBit && "loBit greater than hiBit");
+ if (loBit == hiBit)
+ return;
+ if (loBit < APINT_BITS_PER_WORD && hiBit <= APINT_BITS_PER_WORD) {
----------------
jayfoad wrote:
Simplify this to:
```suggestion
if (hiBit <= APINT_BITS_PER_WORD) {
```
https://github.com/llvm/llvm-project/pull/137098
More information about the llvm-commits
mailing list