[PATCH] D72436: [SCEV] get a more accurate range for AddRecExpr with nsw flag

ChenZheng via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 8 22:35:01 PST 2020


shchenz created this revision.
shchenz added reviewers: nikic, sanjoy.google, reames, fhahn, hfinkel.
Herald added subscribers: llvm-commits, wuzish, hiraditya.
Herald added a project: LLVM.

This is follow up of https://reviews.llvm.org/D71690.

In this patch, handle `nsw` as well


https://reviews.llvm.org/D72436

Files:
  llvm/lib/Analysis/ScalarEvolution.cpp
  llvm/test/Analysis/ScalarEvolution/range_nw_flag.ll


Index: llvm/test/Analysis/ScalarEvolution/range_nw_flag.ll
===================================================================
--- llvm/test/Analysis/ScalarEvolution/range_nw_flag.ll
+++ llvm/test/Analysis/ScalarEvolution/range_nw_flag.ll
@@ -40,7 +40,7 @@
 }
 
 ; CHECK-LABEL: @test-addrec-nsw
-; CHECK: -->  {(-1 + (-10 smin %offset))<nsw>,+,-1}<nsw><%loop> U: [-2147483648,1) S: [-2147483648,1)
+; CHECK: -->  {(-1 + (-10 smin %offset))<nsw>,+,-1}<nsw><%loop> U: [-2147483648,-10) S: [-2147483648,-10)
 define void @test-addrec-nsw(float* %input, i32 %offset, i32 %numIterations) {
 entry:
   %cmp = icmp slt i32 %offset, -10 
Index: llvm/lib/Analysis/ScalarEvolution.cpp
===================================================================
--- llvm/lib/Analysis/ScalarEvolution.cpp
+++ llvm/lib/Analysis/ScalarEvolution.cpp
@@ -5678,12 +5678,12 @@
       }
       if (AllNonNeg)
         ConservativeResult = ConservativeResult.intersectWith(
-          ConstantRange(APInt(BitWidth, 0),
+          ConstantRange(getSignedRangeMin(AddRec->getStart()),
                         APInt::getSignedMinValue(BitWidth)), RangeType);
       else if (AllNonPos)
         ConservativeResult = ConservativeResult.intersectWith(
           ConstantRange(APInt::getSignedMinValue(BitWidth),
-                        APInt(BitWidth, 1)), RangeType);
+                        getSignedRangeMax(AddRec->getStart()) + 1), RangeType);
     }
 
     // TODO: non-affine addrec


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D72436.236969.patch
Type: text/x-patch
Size: 1461 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200109/5d3bc394/attachment.bin>


More information about the llvm-commits mailing list