diff options
Diffstat (limited to 'llvm/unittests/IR/ConstantRangeTest.cpp')
-rw-r--r-- | llvm/unittests/IR/ConstantRangeTest.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/llvm/unittests/IR/ConstantRangeTest.cpp b/llvm/unittests/IR/ConstantRangeTest.cpp index 6962d34..19474ee 100644 --- a/llvm/unittests/IR/ConstantRangeTest.cpp +++ b/llvm/unittests/IR/ConstantRangeTest.cpp @@ -668,6 +668,32 @@ TEST_F(ConstantRangeTest, losslessUnsignedTruncationZeroext) { }); } +TEST_F(ConstantRangeTest, getMinSignedBits) { + unsigned Bits = 4; + EnumerateConstantRanges(Bits, [&](const ConstantRange &CR) { + unsigned Exact = 0; + ForeachNumInConstantRange(CR, [&](const APInt &N) { + Exact = std::max(Exact, N.getMinSignedBits()); + }); + + unsigned ResultCR = CR.getMinSignedBits(); + EXPECT_EQ(Exact, ResultCR); + }); +} +TEST_F(ConstantRangeTest, losslessSignedTruncationSignext) { + unsigned Bits = 4; + EnumerateConstantRanges(Bits, [&](const ConstantRange &CR) { + unsigned MinBitWidth = CR.getMinSignedBits(); + if (MinBitWidth == 0) { + EXPECT_TRUE(CR.isEmptySet()); + return; + } + if (MinBitWidth == Bits) + return; + EXPECT_EQ(CR, CR.truncate(MinBitWidth).signExtend(Bits)); + }); +} + TEST_F(ConstantRangeTest, SubtractAPInt) { EXPECT_EQ(Full.subtract(APInt(16, 4)), Full); EXPECT_EQ(Empty.subtract(APInt(16, 4)), Empty); |