[llvm] e45168c - [SCEV] Handle uge/ugt predicates in applyLoopGuards()
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 27 13:41:14 PDT 2021
Author: Nikita Popov
Date: 2021-04-27T22:41:05+02:00
New Revision: e45168c4fa7debe61ec0fdb6ddae347e18477d37
URL: https://github.com/llvm/llvm-project/commit/e45168c4fa7debe61ec0fdb6ddae347e18477d37
DIFF: https://github.com/llvm/llvm-project/commit/e45168c4fa7debe61ec0fdb6ddae347e18477d37.diff
LOG: [SCEV] Handle uge/ugt predicates in applyLoopGuards()
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.
Differential Revision: https://reviews.llvm.org/D101196
Added:
Modified:
llvm/lib/Analysis/ScalarEvolution.cpp
llvm/test/Analysis/ScalarEvolution/max-backedge-taken-count-guard-info.ll
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index 488f60de41e4..4de5abfdc3f1 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -13449,6 +13449,15 @@ const SCEV *ScalarEvolution::applyLoopGuards(const SCEV *Expr, const Loop *L) {
if (!containsAddRecurrence(RHS))
RewriteMap[LHSUnknown->getValue()] = getUMinExpr(RewrittenLHS, RHS);
break;
+ case CmpInst::ICMP_UGT:
+ if (!containsAddRecurrence(RHS))
+ RewriteMap[LHSUnknown->getValue()] =
+ getUMaxExpr(RewrittenLHS, getAddExpr(RHS, getOne(RHS->getType())));
+ break;
+ case CmpInst::ICMP_UGE:
+ if (!containsAddRecurrence(RHS))
+ RewriteMap[LHSUnknown->getValue()] = getUMaxExpr(RewrittenLHS, RHS);
+ break;
case CmpInst::ICMP_EQ:
if (isa<SCEVConstant>(RHS))
RewriteMap[LHSUnknown->getValue()] = RHS;
diff --git a/llvm/test/Analysis/ScalarEvolution/max-backedge-taken-count-guard-info.ll b/llvm/test/Analysis/ScalarEvolution/max-backedge-taken-count-guard-info.ll
index ab64b154c58b..e5df81dfb6a5 100644
--- a/llvm/test/Analysis/ScalarEvolution/max-backedge-taken-count-guard-info.ll
+++ b/llvm/test/Analysis/ScalarEvolution/max-backedge-taken-count-guard-info.ll
@@ -622,12 +622,12 @@ define void @test_guard_uge(i32 %blockSize) {
; 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
@@ -658,12 +658,12 @@ define void @test_guard_ugt(i32 %blockSize) {
; 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
@@ -694,12 +694,12 @@ define void @test_guard_uge_and_ule(i32 %blockSize) {
; 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: [-255,1073741824) S: [-255,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: [-256,1073741823) S: [-256,1073741823) Exits: 0 LoopDispositions: { %while.body: Computable }
; CHECK-NEXT: Determining loop execution counts for: @test_guard_uge_and_ule
; 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 255
; 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
@@ -734,12 +734,12 @@ define void @test_guard_ugt_and_ult(i32 %blockSize) {
; 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: [-255,1073741824) S: [-255,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: [-256,1073741823) S: [-256,1073741823) Exits: 0 LoopDispositions: { %while.body: Computable }
; CHECK-NEXT: Determining loop execution counts for: @test_guard_ugt_and_ult
; 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 255
; 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
More information about the llvm-commits
mailing list