summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/ADT/APIntTest.cpp
diff options
context:
space:
mode:
authorCraig Topper <craig.topper@gmail.com>2017-04-24 17:18:47 +0000
committerCraig Topper <craig.topper@gmail.com>2017-04-24 17:18:47 +0000
commit8b37326ae2363c51ca33362cd49b28b9d624750e (patch)
tree5ca7f1a0c09b0fa553c37dc71ae1dd8cc56f6706 /llvm/unittests/ADT/APIntTest.cpp
parent5dea6451389b97186760db15c3b1c3fc033d5ad1 (diff)
downloadbcm5719-llvm-8b37326ae2363c51ca33362cd49b28b9d624750e.tar.gz
bcm5719-llvm-8b37326ae2363c51ca33362cd49b28b9d624750e.zip
[APInt] Add ashrInPlace method and rewrite ashr to make a copy and then call ashrInPlace.
This patch adds an in place version of ashr to match lshr and shl which were recently added. I've tried to make this similar to the lshr code with additions to handle the sign extension. I've also tried to do this with less if checks than the current ashr code by sign extending the original result to a word boundary before doing any of the shifting. This removes a lot of the complexity of determining where to fill in sign bits after the shifting. Differential Revision: https://reviews.llvm.org/D32415 llvm-svn: 301198
Diffstat (limited to 'llvm/unittests/ADT/APIntTest.cpp')
-rw-r--r--llvm/unittests/ADT/APIntTest.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/llvm/unittests/ADT/APIntTest.cpp b/llvm/unittests/ADT/APIntTest.cpp
index e0a53a56455..2235f271658 100644
--- a/llvm/unittests/ADT/APIntTest.cpp
+++ b/llvm/unittests/ADT/APIntTest.cpp
@@ -2024,6 +2024,42 @@ TEST(APIntTest, LogicalRightShift) {
EXPECT_EQ(0, neg_one.lshr(128));
}
+TEST(APIntTest, ArithmeticRightShift) {
+ APInt i72(APInt::getHighBitsSet(72, 1));
+ i72.ashrInPlace(46);
+ EXPECT_EQ(47U, i72.countLeadingOnes());
+ EXPECT_EQ(25U, i72.countTrailingZeros());
+ EXPECT_EQ(47U, i72.countPopulation());
+
+ i72 = APInt::getHighBitsSet(72, 1);
+ i72.ashrInPlace(64);
+ EXPECT_EQ(65U, i72.countLeadingOnes());
+ EXPECT_EQ(7U, i72.countTrailingZeros());
+ EXPECT_EQ(65U, i72.countPopulation());
+
+ APInt i128(APInt::getHighBitsSet(128, 1));
+ i128.ashrInPlace(64);
+ EXPECT_EQ(65U, i128.countLeadingOnes());
+ EXPECT_EQ(63U, i128.countTrailingZeros());
+ EXPECT_EQ(65U, i128.countPopulation());
+
+ // 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