summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/ADT/APIntTest.cpp
diff options
context:
space:
mode:
authorCraig Topper <craig.topper@gmail.com>2017-04-22 22:00:03 +0000
committerCraig Topper <craig.topper@gmail.com>2017-04-22 22:00:03 +0000
commit26af2a993a63e00ba5908121ff001c915e917289 (patch)
treebc2cc6a544f1ac6278ebfd7f3d7d0f9e08edacfc /llvm/unittests/ADT/APIntTest.cpp
parenta2d25ac14a9555eb23207a7b4007302de9182d04 (diff)
downloadbcm5719-llvm-26af2a993a63e00ba5908121ff001c915e917289.tar.gz
bcm5719-llvm-26af2a993a63e00ba5908121ff001c915e917289.zip
[APInt] Add ashrInPlace method and implement ashr using it. Also fix a bug in the shift by BitWidth handling.
For single word, shift by BitWidth was always returning 0, but for multiword it was based on original sign. Now single word matches multi word. llvm-svn: 301094
Diffstat (limited to 'llvm/unittests/ADT/APIntTest.cpp')
-rw-r--r--llvm/unittests/ADT/APIntTest.cpp20
1 files changed, 19 insertions, 1 deletions
diff --git a/llvm/unittests/ADT/APIntTest.cpp b/llvm/unittests/ADT/APIntTest.cpp
index 5d3afe9a159..6b889bf2dfd 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));
@@ -2024,6 +2024,24 @@ TEST(APIntTest, LogicalRightShift) {
EXPECT_EQ(0, neg_one.lshr(128));
}
+TEST(APIntTest, ArithmeticRightShift) {
+ // Ensure we handle large shifts of multi-word.
+ const APInt signmin32(APInt::getSignedMinValue(32));
+ EXPECT_TRUE(signmin32.ashr(32).isAllOnesValue());
+
+ // Ensure we handle large shifts of multi-word.
+ const APInt umax32(APInt::getSignedMaxValue(32));
+ EXPECT_EQ(0, umax32.ashr(32));
+
+ // Ensure we handle large shifts of multi-word.
+ const APInt signmin128(APInt::getSignedMinValue(128));
+ EXPECT_TRUE(signmin128.ashr(128).isAllOnesValue());
+
+ // Ensure we handle large shifts of multi-word.
+ const APInt umax128(APInt::getSignedMaxValue(128));
+ EXPECT_EQ(0, umax128.ashr(128));
+}
+
TEST(APIntTest, LeftShift) {
APInt i256(APInt::getLowBitsSet(256, 2));
OpenPOWER on IntegriCloud