[llvm] [APInt] Added APInt::clearBits() method (PR #137098)

Jay Foad via llvm-commits llvm-commits at lists.llvm.org
Mon May 12 06:29:42 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) {
+      uint64_t mask = WORDTYPE_MAX >> (APINT_BITS_PER_WORD - (hiBit - loBit));
----------------
jayfoad wrote:

Sorry, you're right, I misunderstood the code.

https://github.com/llvm/llvm-project/pull/137098


More information about the llvm-commits mailing list