summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/IR/ConstantRangeTest.cpp
diff options
context:
space:
mode:
authorJames Molloy <james.molloy@arm.com>2015-03-06 15:50:47 +0000
committerJames Molloy <james.molloy@arm.com>2015-03-06 15:50:47 +0000
commitdcc78ec386d4d83293da2ecd23ca85395655e3a7 (patch)
tree022b5430555d7efe7625d86cf589484c883ef24b /llvm/unittests/IR/ConstantRangeTest.cpp
parent6ad63744b337892c119c5dbefcb85eef8fc22415 (diff)
downloadbcm5719-llvm-dcc78ec386d4d83293da2ecd23ca85395655e3a7.tar.gz
bcm5719-llvm-dcc78ec386d4d83293da2ecd23ca85395655e3a7.zip
[ConstantRange] Teach multiply to be cleverer about signed ranges.
Multiplication is not dependent on signedness, so just treating all input ranges as unsigned is not incorrect. However it will cause overly pessimistic ranges (such as full-set) when used with signed negative values. Teach multiply to try to interpret its inputs as both signed and unsigned, and then to take the most specific (smallest population) as its result. llvm-svn: 231483
Diffstat (limited to 'llvm/unittests/IR/ConstantRangeTest.cpp')
-rw-r--r--llvm/unittests/IR/ConstantRangeTest.cpp7
1 files changed, 7 insertions, 0 deletions
diff --git a/llvm/unittests/IR/ConstantRangeTest.cpp b/llvm/unittests/IR/ConstantRangeTest.cpp
index fa03302ad2b..fe95b0db9c5 100644
--- a/llvm/unittests/IR/ConstantRangeTest.cpp
+++ b/llvm/unittests/IR/ConstantRangeTest.cpp
@@ -400,6 +400,13 @@ TEST_F(ConstantRangeTest, Multiply) {
EXPECT_EQ(ConstantRange(APInt(4, 1), APInt(4, 6)).multiply(
ConstantRange(APInt(4, 6), APInt(4, 2))),
ConstantRange(4, /*isFullSet=*/true));
+
+ EXPECT_EQ(ConstantRange(APInt(8, 254), APInt(8, 0)).multiply(
+ ConstantRange(APInt(8, 252), APInt(8, 4))),
+ ConstantRange(APInt(8, 250), APInt(8, 9)));
+ EXPECT_EQ(ConstantRange(APInt(8, 254), APInt(8, 255)).multiply(
+ ConstantRange(APInt(8, 2), APInt(8, 4))),
+ ConstantRange(APInt(8, 250), APInt(8, 253)));
}
TEST_F(ConstantRangeTest, UMax) {
OpenPOWER on IntegriCloud