aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/IR/ConstantRangeTest.cpp
diff options
context:
space:
mode:
authorNikita Popov <npopov@redhat.com>2023-06-23 12:15:02 +0200
committerNikita Popov <npopov@redhat.com>2023-06-23 12:17:48 +0200
commit7cf567d46121f4aa8f659554b5e8584cd0fac056 (patch)
tree901efb30a2c2bb9366264d1e6aacbe575a5157bc /llvm/unittests/IR/ConstantRangeTest.cpp
parent04a8070b46da2bcd47d0a134922409dc16bb9d57 (diff)
downloadllvm-7cf567d46121f4aa8f659554b5e8584cd0fac056.zip
llvm-7cf567d46121f4aa8f659554b5e8584cd0fac056.tar.gz
llvm-7cf567d46121f4aa8f659554b5e8584cd0fac056.tar.bz2
[ConstantRange] Calculate precise range for multiply by -1
These are pretty common in SCEV, so make sure we get a precise result by mapping to the sub() operation.
Diffstat (limited to 'llvm/unittests/IR/ConstantRangeTest.cpp')
-rw-r--r--llvm/unittests/IR/ConstantRangeTest.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/llvm/unittests/IR/ConstantRangeTest.cpp b/llvm/unittests/IR/ConstantRangeTest.cpp
index f405283..38d1119 100644
--- a/llvm/unittests/IR/ConstantRangeTest.cpp
+++ b/llvm/unittests/IR/ConstantRangeTest.cpp
@@ -997,6 +997,26 @@ TEST_F(ConstantRangeTest, Multiply) {
EXPECT_EQ(ConstantRange(APInt(8, -2)).multiply(
ConstantRange(APInt(8, 0), APInt(8, 2))),
ConstantRange(APInt(8, -2), APInt(8, 1)));
+
+ // Multiplication by -1 should give precise results.
+ EXPECT_EQ(ConstantRange(APInt(8, 3), APInt(8, -11))
+ .multiply(ConstantRange(APInt(8, -1))),
+ ConstantRange(APInt(8, 12), APInt(8, -2)));
+ EXPECT_EQ(ConstantRange(APInt(8, -1))
+ .multiply(ConstantRange(APInt(8, 3), APInt(8, -11))),
+ ConstantRange(APInt(8, 12), APInt(8, -2)));
+
+ TestBinaryOpExhaustive(
+ [](const ConstantRange &CR1, const ConstantRange &CR2) {
+ return CR1.multiply(CR2);
+ },
+ [](const APInt &N1, const APInt &N2) {
+ return N1 * N2;
+ },
+ PreferSmallest,
+ [](const ConstantRange &, const ConstantRange &) {
+ return false; // Check correctness only.
+ });
}
TEST_F(ConstantRangeTest, smul_fast) {