[llvm] 23f0fbf - [APInt] APInt::clearBitsSlowCase - fix cut+paste typo when merging lo/himasks (#141108)
via llvm-commits
llvm-commits at lists.llvm.org
Thu May 22 13:53:03 PDT 2025
Author: Simon Pilgrim
Date: 2025-05-22T21:52:59+01:00
New Revision: 23f0fbf8fff563c77f770f83096b522c3c99a82d
URL: https://github.com/llvm/llvm-project/commit/23f0fbf8fff563c77f770f83096b522c3c99a82d
DIFF: https://github.com/llvm/llvm-project/commit/23f0fbf8fff563c77f770f83096b522c3c99a82d.diff
LOG: [APInt] APInt::clearBitsSlowCase - fix cut+paste typo when merging lo/himasks (#141108)
Fixes #141098
Added:
Modified:
llvm/lib/Support/APInt.cpp
llvm/unittests/ADT/APIntTest.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Support/APInt.cpp b/llvm/lib/Support/APInt.cpp
index 4743a039a9eb6..954af7fff92a8 100644
--- a/llvm/lib/Support/APInt.cpp
+++ b/llvm/lib/Support/APInt.cpp
@@ -349,9 +349,9 @@ void APInt::clearBitsSlowCase(unsigned LoBit, unsigned HiBit) {
// Create a high mask with ones above HiBit.
uint64_t HiMask = ~(WORDTYPE_MAX >> (APINT_BITS_PER_WORD - HiShiftAmt));
// If LoWord and HiWord are equal, then we combine the masks. Otherwise,
- // set the bits in HiWord.
+ // clear the bits in HiWord.
if (HiWord == LoWord)
- LoMask &= HiMask;
+ LoMask |= HiMask;
else
U.pVal[HiWord] &= HiMask;
}
diff --git a/llvm/unittests/ADT/APIntTest.cpp b/llvm/unittests/ADT/APIntTest.cpp
index a58fbd6deffa5..4741c7bcc140f 100644
--- a/llvm/unittests/ADT/APIntTest.cpp
+++ b/llvm/unittests/ADT/APIntTest.cpp
@@ -2556,6 +2556,15 @@ TEST(APIntTest, clearBits) {
EXPECT_EQ(6u, i256.countl_one());
EXPECT_EQ(16u, i256.popcount());
+ APInt i299 = APInt::getAllOnes(299);
+ i299.clearBits(240, 250);
+ EXPECT_EQ(240u, i299.countr_one());
+ EXPECT_EQ(0u, i299.countr_zero());
+ EXPECT_EQ(299u, i299.getActiveBits());
+ EXPECT_EQ(0u, i299.countl_zero());
+ EXPECT_EQ(49u, i299.countl_one());
+ EXPECT_EQ(289u, i299.popcount());
+
APInt i311 = APInt::getAllOnes(311);
i311.clearBits(33, 99);
EXPECT_EQ(33u, i311.countr_one());
More information about the llvm-commits
mailing list