Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit b97a02c

Browse files
committed
[ConstantRange] Fix the early out in ConstantRange::multiply for positive numbers to really do what the comment says
r271020 added an early out to skip the signed multiply portion of ConstantRange::multiply. The comment says we don't need to do signed multiply if the range is only positive numbers, but the implemented check only ensures that the start of the range is positive. It doesn't look at the end of the range. This patch checks the end of the range instead. Because Upper is one more than the end we have to see if its positive or if its one past the last positive number. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@302717 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent d53f653 commit b97a02c

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

lib/IR/ConstantRange.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,8 @@ ConstantRange::multiply(const ConstantRange &Other) const {
757757
// from one positive number to another which is as good as we can generate.
758758
// In this case, skip the extra work of generating signed ranges which aren't
759759
// going to be better than this range.
760-
if (!UR.isWrappedSet() && UR.getLower().isNonNegative())
760+
if (!UR.isWrappedSet() &&
761+
(UR.getUpper().isNonNegative() || UR.getUpper().isMinSignedValue()))
761762
return UR;
762763

763764
// Now the signed range. Because we could be dealing with negative numbers

unittests/IR/ConstantRangeTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ TEST_F(ConstantRangeTest, Multiply) {
447447
// TODO: This should be return [-2, 0]
448448
EXPECT_EQ(ConstantRange(APInt(8, -2)).multiply(
449449
ConstantRange(APInt(8, 0), APInt(8, 2))),
450-
ConstantRange(APInt(8, 0), APInt(8, 255)));
450+
ConstantRange(APInt(8, -2), APInt(8, 1)));
451451
}
452452

453453
TEST_F(ConstantRangeTest, UMax) {

0 commit comments

Comments
 (0)