[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.
llvm-svn: 301159
diff --git a/llvm/lib/Support/APInt.cpp b/llvm/lib/Support/APInt.cpp
index 3f552db..e056f8b 100644
--- a/llvm/lib/Support/APInt.cpp
+++ b/llvm/lib/Support/APInt.cpp
@@ -1041,7 +1041,9 @@
// 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);
}