]> granicus.if.org Git - llvm/commitdiff
[ConstantRange] Fix the early out in ConstantRange::multiply for positive numbers...
authorCraig Topper <craig.topper@gmail.com>
Wed, 10 May 2017 20:01:48 +0000 (20:01 +0000)
committerCraig Topper <craig.topper@gmail.com>
Wed, 10 May 2017 20:01:48 +0000 (20:01 +0000)
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

lib/IR/ConstantRange.cpp
unittests/IR/ConstantRangeTest.cpp

index a33d062dbeaa1723ce48552961d18e30de54e2ac..509caba3acd49cbdc1ae9da9db0e2b98d176d342 100644 (file)
@@ -757,7 +757,8 @@ ConstantRange::multiply(const ConstantRange &Other) const {
   // from one positive number to another which is as good as we can generate.
   // In this case, skip the extra work of generating signed ranges which aren't
   // going to be better than this range.
-  if (!UR.isWrappedSet() && UR.getLower().isNonNegative())
+  if (!UR.isWrappedSet() &&
+      (UR.getUpper().isNonNegative() || UR.getUpper().isMinSignedValue()))
     return UR;
 
   // Now the signed range. Because we could be dealing with negative numbers
index 6c5c8f50340f535a2572f505b6b9cb73a3d88a79..593580e2f61a47d1d100849c7136de0a89cc97b5 100644 (file)
@@ -447,7 +447,7 @@ TEST_F(ConstantRangeTest, Multiply) {
   // TODO: This should be return [-2, 0]
   EXPECT_EQ(ConstantRange(APInt(8, -2)).multiply(
               ConstantRange(APInt(8, 0), APInt(8, 2))),
-            ConstantRange(APInt(8, 0), APInt(8, 255)));
+            ConstantRange(APInt(8, -2), APInt(8, 1)));
 }
 
 TEST_F(ConstantRangeTest, UMax) {