[PATCH] D101196: [SCEV] Handle uge/ugt predicates in applyLoopGuards()
Nikita Popov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 23 13:12:55 PDT 2021
nikic created this revision.
nikic added reviewers: fhahn, reames, mkazantsev.
Herald added a subscriber: hiraditya.
nikic requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
These can be handled the same way as ule/ult, just using umax instead of umin. This is useful in cases where the umax prevents the upper bound from overflowing.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D101196
Files:
llvm/lib/Analysis/ScalarEvolution.cpp
llvm/test/Analysis/ScalarEvolution/max-backedge-taken-count-guard-info.ll
Index: llvm/test/Analysis/ScalarEvolution/max-backedge-taken-count-guard-info.ll
===================================================================
--- llvm/test/Analysis/ScalarEvolution/max-backedge-taken-count-guard-info.ll
+++ llvm/test/Analysis/ScalarEvolution/max-backedge-taken-count-guard-info.ll
@@ -586,12 +586,12 @@
; CHECK-NEXT: %shr = lshr i32 %blockSize, 2
; CHECK-NEXT: --> (%blockSize /u 4) U: [0,1073741824) S: [0,1073741824)
; CHECK-NEXT: %iv = phi i32 [ %dec, %while.body ], [ %shr, %while.body.preheader ]
-; CHECK-NEXT: --> {(%blockSize /u 4),+,-1}<%while.body> U: full-set S: full-set Exits: 1 LoopDispositions: { %while.body: Computable }
+; CHECK-NEXT: --> {(%blockSize /u 4),+,-1}<%while.body> U: [-1073741822,1073741824) S: [-1073741822,1073741824) Exits: 1 LoopDispositions: { %while.body: Computable }
; CHECK-NEXT: %dec = add i32 %iv, -1
-; CHECK-NEXT: --> {(-1 + (%blockSize /u 4))<nsw>,+,-1}<%while.body> U: full-set S: full-set Exits: 0 LoopDispositions: { %while.body: Computable }
+; CHECK-NEXT: --> {(-1 + (%blockSize /u 4))<nsw>,+,-1}<%while.body> U: [-1073741823,1073741823) S: [-1073741823,1073741823) Exits: 0 LoopDispositions: { %while.body: Computable }
; CHECK-NEXT: Determining loop execution counts for: @test_guard_uge
; CHECK-NEXT: Loop %while.body: backedge-taken count is (-1 + (%blockSize /u 4))<nsw>
-; CHECK-NEXT: Loop %while.body: max backedge-taken count is -1
+; CHECK-NEXT: Loop %while.body: max backedge-taken count is 1073741822
; CHECK-NEXT: Loop %while.body: Predicated backedge-taken count is (-1 + (%blockSize /u 4))<nsw>
; CHECK-NEXT: Predicates:
; CHECK: Loop %while.body: Trip multiple is 1
@@ -622,12 +622,12 @@
; CHECK-NEXT: %shr = lshr i32 %blockSize, 2
; CHECK-NEXT: --> (%blockSize /u 4) U: [0,1073741824) S: [0,1073741824)
; CHECK-NEXT: %iv = phi i32 [ %dec, %while.body ], [ %shr, %while.body.preheader ]
-; CHECK-NEXT: --> {(%blockSize /u 4),+,-1}<%while.body> U: full-set S: full-set Exits: 1 LoopDispositions: { %while.body: Computable }
+; CHECK-NEXT: --> {(%blockSize /u 4),+,-1}<%while.body> U: [-1073741822,1073741824) S: [-1073741822,1073741824) Exits: 1 LoopDispositions: { %while.body: Computable }
; CHECK-NEXT: %dec = add i32 %iv, -1
-; CHECK-NEXT: --> {(-1 + (%blockSize /u 4))<nsw>,+,-1}<%while.body> U: full-set S: full-set Exits: 0 LoopDispositions: { %while.body: Computable }
+; CHECK-NEXT: --> {(-1 + (%blockSize /u 4))<nsw>,+,-1}<%while.body> U: [-1073741823,1073741823) S: [-1073741823,1073741823) Exits: 0 LoopDispositions: { %while.body: Computable }
; CHECK-NEXT: Determining loop execution counts for: @test_guard_ugt
; CHECK-NEXT: Loop %while.body: backedge-taken count is (-1 + (%blockSize /u 4))<nsw>
-; CHECK-NEXT: Loop %while.body: max backedge-taken count is -1
+; CHECK-NEXT: Loop %while.body: max backedge-taken count is 1073741822
; CHECK-NEXT: Loop %while.body: Predicated backedge-taken count is (-1 + (%blockSize /u 4))<nsw>
; CHECK-NEXT: Predicates:
; CHECK: Loop %while.body: Trip multiple is 1
Index: llvm/lib/Analysis/ScalarEvolution.cpp
===================================================================
--- llvm/lib/Analysis/ScalarEvolution.cpp
+++ llvm/lib/Analysis/ScalarEvolution.cpp
@@ -13457,6 +13457,27 @@
}
break;
}
+ case CmpInst::ICMP_UGT: {
+ if (!containsAddRecurrence(RHS)) {
+ const SCEV *Base = LHS;
+ auto I = RewriteMap.find(LHSUnknown->getValue());
+ if (I != RewriteMap.end())
+ Base = I->second;
+ RewriteMap[LHSUnknown->getValue()] =
+ getUMaxExpr(Base, getAddExpr(RHS, getOne(RHS->getType())));
+ }
+ break;
+ }
+ case CmpInst::ICMP_UGE: {
+ if (!containsAddRecurrence(RHS)) {
+ const SCEV *Base = LHS;
+ auto I = RewriteMap.find(LHSUnknown->getValue());
+ if (I != RewriteMap.end())
+ Base = I->second;
+ RewriteMap[LHSUnknown->getValue()] = getUMaxExpr(Base, RHS);
+ }
+ break;
+ }
case CmpInst::ICMP_EQ:
if (isa<SCEVConstant>(RHS))
RewriteMap[LHSUnknown->getValue()] = RHS;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D101196.340145.patch
Type: text/x-patch
Size: 4174 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210423/96fedf78/attachment.bin>
More information about the llvm-commits
mailing list