[llvm] [ADT] Add fshl/fshr operations to APSInt (PR #153790)

Chaitanya Koparkar via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 15 05:05:07 PDT 2025


================
@@ -285,4 +285,89 @@ TEST(APSIntTest, UnsignedHighBit) {
   EXPECT_TRUE(CharMax.isStrictlyPositive());
 }
 
+// Right shift of unsigned numbers translates to a logical shift.
+TEST(APSIntTest, RightShiftUnsigned) {
+  // Right shift of a negative number.
+  const APInt neg_one(128, static_cast<uint64_t>(-1), /*isSigned*/true);
+  const APSInt neg_one_unsigned(APSInt(neg_one, /*isUnsigned*/true));
+  EXPECT_EQ(0, neg_one_unsigned >> 128);
+
+  APSInt i256(APSInt(APInt::getHighBitsSet(256, 2)));
+  i256 >>= 1;
+  EXPECT_EQ(1U, i256.countl_zero());
----------------
ckoparkar wrote:

Doh, I took these from `APIntTest` and didn't notice that the expected-vs-actual is reversed. Fixed it.

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


More information about the llvm-commits mailing list