diff options
author | Roman Lebedev <lebedev.ri@gmail.com> | 2020-09-22 15:51:25 +0300 |
---|---|---|
committer | Roman Lebedev <lebedev.ri@gmail.com> | 2020-09-22 21:37:30 +0300 |
commit | 7465da2077c2b8def7440094e15ac1199226bc25 (patch) | |
tree | f5eaea5aabfd7146e93691447fa3b045101d1e93 /llvm/unittests/IR/ConstantRangeTest.cpp | |
parent | b85395f309890bac5f2d3296ce08dc46c24ef77f (diff) | |
download | llvm-7465da2077c2b8def7440094e15ac1199226bc25.zip llvm-7465da2077c2b8def7440094e15ac1199226bc25.tar.gz llvm-7465da2077c2b8def7440094e15ac1199226bc25.tar.bz2 |
[ConstantRange] Introduce getMinSignedBits() method
Similar to the ConstantRange::getActiveBits(), and to similarly-named
methods in APInt, returns the bitwidth needed to represent
the given signed constant range
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); |