]> granicus.if.org Git - llvm/commitdiff
[APInt] Make behavior of ashr by BitWidth consistent between single and multi word.
authorCraig Topper <craig.topper@gmail.com>
Mon, 24 Apr 2017 05:38:26 +0000 (05:38 +0000)
committerCraig Topper <craig.topper@gmail.com>
Mon, 24 Apr 2017 05:38:26 +0000 (05:38 +0000)
Previously single word would always return 0 regardless of the original sign. Multi word would return all 0s or all 1s based on the original sign. Now single word takes into account the sign as well.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@301159 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Support/APInt.cpp
unittests/ADT/APIntTest.cpp

index 3f552db796393a7a399ad96122c207ae780ef6c1..e056f8ba853dd44ff2b76af610c8a83efecfda0b 100644 (file)
@@ -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);
   }
 
index 1e20ebb320c9c717827b2969bc5d8610629db4ca..e0a53a56455f746746b6b3491fee6a94ab737870 100644 (file)
@@ -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));