diff options
-rw-r--r-- | llvm/lib/Support/APInt.cpp | 4 | ||||
-rw-r--r-- | llvm/unittests/ADT/APIntTest.cpp | 2 |
2 files changed, 4 insertions, 2 deletions
diff --git a/llvm/lib/Support/APInt.cpp b/llvm/lib/Support/APInt.cpp index 3f552db7963..e056f8ba853 100644 --- a/llvm/lib/Support/APInt.cpp +++ b/llvm/lib/Support/APInt.cpp @@ -1041,7 +1041,9 @@ APInt APInt::ashr(unsigned shiftAmt) const { // Handle single word shifts with built-in ashr if (isSingleWord()) { if (shiftAmt == BitWidth) - return APInt(BitWidth, 0); // undefined + // Undefined + return APInt(BitWidth, + SignExtend64(VAL, BitWidth) >> (APINT_BITS_PER_WORD - 1)); return APInt(BitWidth, SignExtend64(VAL, BitWidth) >> shiftAmt); } diff --git a/llvm/unittests/ADT/APIntTest.cpp b/llvm/unittests/ADT/APIntTest.cpp index 1e20ebb320c..e0a53a56455 100644 --- a/llvm/unittests/ADT/APIntTest.cpp +++ b/llvm/unittests/ADT/APIntTest.cpp @@ -288,7 +288,7 @@ TEST(APIntTest, i1) { EXPECT_EQ(zero, one.shl(1)); EXPECT_EQ(one, one.shl(0)); EXPECT_EQ(zero, one.lshr(1)); - EXPECT_EQ(zero, one.ashr(1)); + EXPECT_EQ(one, one.ashr(1)); // Rotates. EXPECT_EQ(one, one.rotl(0)); |