aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/IR/ConstantRangeTest.cpp
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2021-10-15 21:25:39 +0200
committerNikita Popov <nikita.ppv@gmail.com>2021-10-15 23:44:41 +0200
commit587493b441ea87f132fec680933d3628050756b8 (patch)
tree5f36204a9eb93dbaf3f196e218b59da2a47b1dd5 /llvm/unittests/IR/ConstantRangeTest.cpp
parentf92db6d3fff13bdacdf9b24660eb3f3158c58a17 (diff)
downloadllvm-587493b441ea87f132fec680933d3628050756b8.zip
llvm-587493b441ea87f132fec680933d3628050756b8.tar.gz
llvm-587493b441ea87f132fec680933d3628050756b8.tar.bz2
[ConstantRange] Compute precise shl range for single elements
For the common case where the shift amount is constant (a single element range) we can easily compute a precise range (up to unsigned envelope), so do that.
Diffstat (limited to 'llvm/unittests/IR/ConstantRangeTest.cpp')
-rw-r--r--llvm/unittests/IR/ConstantRangeTest.cpp18
1 files changed, 17 insertions, 1 deletions
diff --git a/llvm/unittests/IR/ConstantRangeTest.cpp b/llvm/unittests/IR/ConstantRangeTest.cpp
index d220b70..bc78869 100644
--- a/llvm/unittests/IR/ConstantRangeTest.cpp
+++ b/llvm/unittests/IR/ConstantRangeTest.cpp
@@ -1400,7 +1400,8 @@ TEST_F(ConstantRangeTest, Shl) {
ConstantRange WrapNullMax(APInt(16, 0x1), APInt(16, 0x0));
EXPECT_EQ(Full.shl(Full), Full);
EXPECT_EQ(Full.shl(Empty), Empty);
- EXPECT_EQ(Full.shl(One), Full); // TODO: [0, (-1 << 0xa) + 1)
+ EXPECT_EQ(Full.shl(One), ConstantRange(APInt(16, 0),
+ APInt(16, 0xfc00) + 1));
EXPECT_EQ(Full.shl(Some), Full); // TODO: [0, (-1 << 0xa) + 1)
EXPECT_EQ(Full.shl(Wrap), Full);
EXPECT_EQ(Empty.shl(Empty), Empty);
@@ -1418,6 +1419,21 @@ TEST_F(ConstantRangeTest, Shl) {
Some2.shl(ConstantRange(APInt(16, 0x1))),
ConstantRange(APInt(16, 0xfff << 0x1), APInt(16, 0x7fff << 0x1) + 1));
EXPECT_EQ(One.shl(WrapNullMax), Full);
+
+ TestBinaryOpExhaustive(
+ [](const ConstantRange &CR1, const ConstantRange &CR2) {
+ return CR1.shl(CR2);
+ },
+ [](const APInt &N1, const APInt &N2) -> Optional<APInt> {
+ if (N2.uge(N2.getBitWidth()))
+ return None;
+ return N1.shl(N2);
+ },
+ PreferSmallestUnsigned,
+ [](const ConstantRange &, const ConstantRange &CR2) {
+ // We currently only produce precise results for single element RHS.
+ return CR2.isSingleElement();
+ });
}
TEST_F(ConstantRangeTest, Lshr) {