aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/IR/ConstantRangeTest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/unittests/IR/ConstantRangeTest.cpp')
-rw-r--r--llvm/unittests/IR/ConstantRangeTest.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/llvm/unittests/IR/ConstantRangeTest.cpp b/llvm/unittests/IR/ConstantRangeTest.cpp
index 474a94a..6962d34 100644
--- a/llvm/unittests/IR/ConstantRangeTest.cpp
+++ b/llvm/unittests/IR/ConstantRangeTest.cpp
@@ -641,6 +641,33 @@ TEST_F(ConstantRangeTest, SetDifference) {
EXPECT_EQ(E.difference(A), F);
}
+TEST_F(ConstantRangeTest, getActiveBits) {
+ unsigned Bits = 4;
+ EnumerateConstantRanges(Bits, [&](const ConstantRange &CR) {
+ unsigned Exact = 0;
+ ForeachNumInConstantRange(CR, [&](const APInt &N) {
+ Exact = std::max(Exact, N.getActiveBits());
+ });
+
+ unsigned ResultCR = CR.getActiveBits();
+ EXPECT_EQ(Exact, ResultCR);
+ });
+}
+TEST_F(ConstantRangeTest, losslessUnsignedTruncationZeroext) {
+ unsigned Bits = 4;
+ EnumerateConstantRanges(Bits, [&](const ConstantRange &CR) {
+ unsigned MinBitWidth = CR.getActiveBits();
+ if (MinBitWidth == 0) {
+ EXPECT_TRUE(CR.isEmptySet() || (CR.isSingleElement() &&
+ CR.getSingleElement()->isNullValue()));
+ return;
+ }
+ if (MinBitWidth == Bits)
+ return;
+ EXPECT_EQ(CR, CR.truncate(MinBitWidth).zeroExtend(Bits));
+ });
+}
+
TEST_F(ConstantRangeTest, SubtractAPInt) {
EXPECT_EQ(Full.subtract(APInt(16, 4)), Full);
EXPECT_EQ(Empty.subtract(APInt(16, 4)), Empty);