[llvm] r302717 - [ConstantRange] Fix the early out in ConstantRange::multiply for positive numbers to really do what the comment says

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Wed May 10 13:01:48 PDT 2017


Author: ctopper
Date: Wed May 10 15:01:48 2017
New Revision: 302717

URL: http://llvm.org/viewvc/llvm-project?rev=302717&view=rev
Log:
[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.

Modified:
    llvm/trunk/lib/IR/ConstantRange.cpp
    llvm/trunk/unittests/IR/ConstantRangeTest.cpp

Modified: llvm/trunk/lib/IR/ConstantRange.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/ConstantRange.cpp?rev=302717&r1=302716&r2=302717&view=diff
==============================================================================
--- llvm/trunk/lib/IR/ConstantRange.cpp (original)
+++ llvm/trunk/lib/IR/ConstantRange.cpp Wed May 10 15:01:48 2017
@@ -757,7 +757,8 @@ ConstantRange::multiply(const ConstantRa
   // 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

Modified: llvm/trunk/unittests/IR/ConstantRangeTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/IR/ConstantRangeTest.cpp?rev=302717&r1=302716&r2=302717&view=diff
==============================================================================
--- llvm/trunk/unittests/IR/ConstantRangeTest.cpp (original)
+++ llvm/trunk/unittests/IR/ConstantRangeTest.cpp Wed May 10 15:01:48 2017
@@ -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) {




More information about the llvm-commits mailing list