[PATCH] D126503: [SCEV] Use fact that B >u 0 for A <u B in applyLoopGuards.
Florian Hahn via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 1 08:51:42 PST 2023
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG62bd944e4247: [SCEV] Use fact that B >u 0 for A <u B in applyLoopGuards. (authored by fhahn).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D126503/new/
https://reviews.llvm.org/D126503
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
@@ -308,19 +308,18 @@
ret void
}
-; TODO: Currently we miss getting the tightest constant max backedge-taken count (11).
define void @test_multiple_var_guards_order1(ptr nocapture %a, i64 %i, i64 %N) {
; CHECK-LABEL: 'test_multiple_var_guards_order1'
; CHECK-NEXT: Classifying expressions for: @test_multiple_var_guards_order1
; CHECK-NEXT: %iv = phi i64 [ %iv.next, %loop ], [ 0, %guardbb ]
-; CHECK-NEXT: --> {0,+,1}<nuw><nsw><%loop> U: [0,-9223372036854775808) S: [0,-9223372036854775808) Exits: %i LoopDispositions: { %loop: Computable }
+; CHECK-NEXT: --> {0,+,1}<nuw><nsw><%loop> U: [0,11) S: [0,11) Exits: %i LoopDispositions: { %loop: Computable }
; CHECK-NEXT: %idx = getelementptr inbounds i32, ptr %a, i64 %iv
; CHECK-NEXT: --> {%a,+,4}<nuw><%loop> U: full-set S: full-set Exits: ((4 * %i) + %a) LoopDispositions: { %loop: Computable }
; CHECK-NEXT: %iv.next = add nuw nsw i64 %iv, 1
-; CHECK-NEXT: --> {1,+,1}<nuw><%loop> U: [1,0) S: [1,0) Exits: (1 + %i) LoopDispositions: { %loop: Computable }
+; CHECK-NEXT: --> {1,+,1}<nuw><nsw><%loop> U: [1,12) S: [1,12) Exits: (1 + %i) LoopDispositions: { %loop: Computable }
; CHECK-NEXT: Determining loop execution counts for: @test_multiple_var_guards_order1
; CHECK-NEXT: Loop %loop: backedge-taken count is %i
-; CHECK-NEXT: Loop %loop: constant max backedge-taken count is -1
+; CHECK-NEXT: Loop %loop: constant max backedge-taken count is 10
; CHECK-NEXT: Loop %loop: symbolic max backedge-taken count is %i
; CHECK-NEXT: Loop %loop: Predicated backedge-taken count is %i
; CHECK-NEXT: Predicates:
@@ -346,19 +345,18 @@
ret void
}
-; TODO: Currently we miss getting the tightest constant max backedge-taken count (11).
define void @test_multiple_var_guards_order2(ptr nocapture %a, i64 %i, i64 %N) {
; CHECK-LABEL: 'test_multiple_var_guards_order2'
; CHECK-NEXT: Classifying expressions for: @test_multiple_var_guards_order2
; CHECK-NEXT: %iv = phi i64 [ %iv.next, %loop ], [ 0, %guardbb ]
-; CHECK-NEXT: --> {0,+,1}<nuw><nsw><%loop> U: [0,-9223372036854775808) S: [0,-9223372036854775808) Exits: %i LoopDispositions: { %loop: Computable }
+; CHECK-NEXT: --> {0,+,1}<nuw><nsw><%loop> U: [0,11) S: [0,11) Exits: %i LoopDispositions: { %loop: Computable }
; CHECK-NEXT: %idx = getelementptr inbounds i32, ptr %a, i64 %iv
; CHECK-NEXT: --> {%a,+,4}<nuw><%loop> U: full-set S: full-set Exits: ((4 * %i) + %a) LoopDispositions: { %loop: Computable }
; CHECK-NEXT: %iv.next = add nuw nsw i64 %iv, 1
-; CHECK-NEXT: --> {1,+,1}<nuw><%loop> U: [1,0) S: [1,0) Exits: (1 + %i) LoopDispositions: { %loop: Computable }
+; CHECK-NEXT: --> {1,+,1}<nuw><nsw><%loop> U: [1,12) S: [1,12) Exits: (1 + %i) LoopDispositions: { %loop: Computable }
; CHECK-NEXT: Determining loop execution counts for: @test_multiple_var_guards_order2
; CHECK-NEXT: Loop %loop: backedge-taken count is %i
-; CHECK-NEXT: Loop %loop: constant max backedge-taken count is -1
+; CHECK-NEXT: Loop %loop: constant max backedge-taken count is 10
; CHECK-NEXT: Loop %loop: symbolic max backedge-taken count is %i
; CHECK-NEXT: Loop %loop: Predicated backedge-taken count is %i
; CHECK-NEXT: Predicates:
@@ -393,10 +391,10 @@
; CHECK-NEXT: %idx = getelementptr inbounds i32, ptr %a, i64 %iv
; CHECK-NEXT: --> {%a,+,4}<nuw><%loop> U: full-set S: full-set Exits: ((4 * %N) + %a) LoopDispositions: { %loop: Computable }
; CHECK-NEXT: %iv.next = add nuw nsw i64 %iv, 1
-; CHECK-NEXT: --> {1,+,1}<nuw><%loop> U: [1,0) S: [1,0) Exits: (1 + %N) LoopDispositions: { %loop: Computable }
+; CHECK-NEXT: --> {1,+,1}<nuw><%loop> U: [1,-1) S: [1,-1) Exits: (1 + %N) LoopDispositions: { %loop: Computable }
; CHECK-NEXT: Determining loop execution counts for: @test_multiple_var_guards_cycle
; CHECK-NEXT: Loop %loop: backedge-taken count is %N
-; CHECK-NEXT: Loop %loop: constant max backedge-taken count is -1
+; CHECK-NEXT: Loop %loop: constant max backedge-taken count is -3
; CHECK-NEXT: Loop %loop: symbolic max backedge-taken count is %N
; CHECK-NEXT: Loop %loop: Predicated backedge-taken count is %N
; CHECK-NEXT: Predicates:
Index: llvm/lib/Analysis/ScalarEvolution.cpp
===================================================================
--- llvm/lib/Analysis/ScalarEvolution.cpp
+++ llvm/lib/Analysis/ScalarEvolution.cpp
@@ -15052,10 +15052,14 @@
const SCEV *RewrittenRHS = nullptr;
switch (Predicate) {
- case CmpInst::ICMP_ULT:
+ case CmpInst::ICMP_ULT: {
+ if (RHS->getType()->isPointerTy())
+ break;
+ const SCEV *One = getOne(RHS->getType());
RewrittenRHS =
- getUMinExpr(RewrittenLHS, getMinusSCEV(RHS, getOne(RHS->getType())));
+ getUMinExpr(RewrittenLHS, getMinusSCEV(getUMaxExpr(RHS, One), One));
break;
+ }
case CmpInst::ICMP_SLT:
RewrittenRHS =
getSMinExpr(RewrittenLHS, getMinusSCEV(RHS, getOne(RHS->getType())));
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D126503.493976.patch
Type: text/x-patch
Size: 5264 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230201/500be6c0/attachment.bin>
More information about the llvm-commits
mailing list