[llvm] r301159 - [APInt] Make behavior of ashr by BitWidth consistent between single and multi word.
    Craig Topper via llvm-commits 
    llvm-commits at lists.llvm.org
       
    Sun Apr 23 22:38:26 PDT 2017
    
    
  
Author: ctopper
Date: Mon Apr 24 00:38:26 2017
New Revision: 301159
URL: http://llvm.org/viewvc/llvm-project?rev=301159&view=rev
Log:
[APInt] Make behavior of ashr by BitWidth consistent between single and multi word.
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.
Modified:
    llvm/trunk/lib/Support/APInt.cpp
    llvm/trunk/unittests/ADT/APIntTest.cpp
Modified: llvm/trunk/lib/Support/APInt.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/APInt.cpp?rev=301159&r1=301158&r2=301159&view=diff
==============================================================================
--- llvm/trunk/lib/Support/APInt.cpp (original)
+++ llvm/trunk/lib/Support/APInt.cpp Mon Apr 24 00:38:26 2017
@@ -1041,7 +1041,9 @@ APInt APInt::ashr(unsigned shiftAmt) con
   // 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);
   }
 
Modified: llvm/trunk/unittests/ADT/APIntTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ADT/APIntTest.cpp?rev=301159&r1=301158&r2=301159&view=diff
==============================================================================
--- llvm/trunk/unittests/ADT/APIntTest.cpp (original)
+++ llvm/trunk/unittests/ADT/APIntTest.cpp Mon Apr 24 00:38:26 2017
@@ -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));
    
    
More information about the llvm-commits
mailing list