summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/ADT
diff options
context:
space:
mode:
authorCraig Topper <craig.topper@gmail.com>2017-04-23 17:16:24 +0000
committerCraig Topper <craig.topper@gmail.com>2017-04-23 17:16:24 +0000
commit652ca99622954c5373427bbd51257b7f23b61aed (patch)
tree18ca1c16ad7b858aecfa32df904f5800e4dd4120 /llvm/unittests/ADT
parentdd9a4b9ae80b12f93ca33620a3de0907e81dfe7b (diff)
downloadbcm5719-llvm-652ca99622954c5373427bbd51257b7f23b61aed.tar.gz
bcm5719-llvm-652ca99622954c5373427bbd51257b7f23b61aed.zip
[APInt] In sext single word case, use SignExtend64 and let the APInt constructor mask off any excess bits.
The current code is trying to be clever with shifts to avoid needing to clear unused bits. But it looks like the compiler is unable to optimize out the unused bit handling in the APInt constructor. Given this its better to just use SignExtend64 and have more readable code. llvm-svn: 301133
Diffstat (limited to 'llvm/unittests/ADT')
-rw-r--r--llvm/unittests/ADT/APIntTest.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/llvm/unittests/ADT/APIntTest.cpp b/llvm/unittests/ADT/APIntTest.cpp
index 5d3afe9a159..1e20ebb320c 100644
--- a/llvm/unittests/ADT/APIntTest.cpp
+++ b/llvm/unittests/ADT/APIntTest.cpp
@@ -2086,4 +2086,24 @@ TEST(APIntTest, isSubsetOf) {
EXPECT_TRUE(i128_3.isSubsetOf(i128_3));
}
+TEST(APIntTest, sext) {
+ EXPECT_EQ(0, APInt(1, 0).sext(64));
+ EXPECT_EQ(~uint64_t(0), APInt(1, 1).sext(64));
+
+ APInt i32_max(APInt::getSignedMaxValue(32).sext(63));
+ EXPECT_EQ(32U, i32_max.countLeadingZeros());
+ EXPECT_EQ(0U, i32_max.countTrailingZeros());
+ EXPECT_EQ(31U, i32_max.countPopulation());
+
+ APInt i32_min(APInt::getSignedMinValue(32).sext(63));
+ EXPECT_EQ(32U, i32_min.countLeadingOnes());
+ EXPECT_EQ(31U, i32_min.countTrailingZeros());
+ EXPECT_EQ(32U, i32_min.countPopulation());
+
+ APInt i32_neg1(APInt(32, ~uint64_t(0)).sext(63));
+ EXPECT_EQ(63U, i32_neg1.countLeadingOnes());
+ EXPECT_EQ(0U, i32_neg1.countTrailingZeros());
+ EXPECT_EQ(63U, i32_neg1.countPopulation());
+}
+
} // end anonymous namespace
OpenPOWER on IntegriCloud