[PATCH] D145231: [SCEV] Support mul in SCEVLoopGuardRewriter
Dmitry Makogon via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 3 04:42:30 PST 2023
dmakogon created this revision.
dmakogon added reviewers: mkazantsev, fhahn, aleksandr.popov.
Herald added subscribers: StephenFan, javed.absar, hiraditya.
Herald added a project: All.
dmakogon requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Adds support for these SCEVs to cover more cases.
https://reviews.llvm.org/D145231
Files:
llvm/lib/Analysis/ScalarEvolution.cpp
llvm/test/Analysis/ScalarEvolution/trip-count-minmax.ll
llvm/test/Analysis/ScalarEvolution/trip-count9.ll
Index: llvm/test/Analysis/ScalarEvolution/trip-count9.ll
===================================================================
--- llvm/test/Analysis/ScalarEvolution/trip-count9.ll
+++ llvm/test/Analysis/ScalarEvolution/trip-count9.ll
@@ -283,7 +283,7 @@
; CHECK-NEXT: Loop %loop: symbolic max backedge-taken count is (-1 + (2 * %n))
; CHECK-NEXT: Loop %loop: Predicated backedge-taken count is (-1 + (2 * %n))
; CHECK-NEXT: Predicates:
-; CHECK: Loop %loop: Trip multiple is 2
+; CHECK: Loop %loop: Trip multiple is 1
;
entry:
%m = shl i4 %n, 1
@@ -421,7 +421,7 @@
; CHECK-NEXT: Loop %loop: symbolic max backedge-taken count is (-1 + (2 * %n))
; CHECK-NEXT: Loop %loop: Predicated backedge-taken count is (-1 + (2 * %n))
; CHECK-NEXT: Predicates:
-; CHECK: Loop %loop: Trip multiple is 2
+; CHECK: Loop %loop: Trip multiple is 1
;
entry:
%m = shl i4 %n, 1
Index: llvm/test/Analysis/ScalarEvolution/trip-count-minmax.ll
===================================================================
--- llvm/test/Analysis/ScalarEvolution/trip-count-minmax.ll
+++ llvm/test/Analysis/ScalarEvolution/trip-count-minmax.ll
@@ -156,16 +156,16 @@
; CHECK-NEXT: %cond = select i1 %cmp, i32 %mul, i32 %mul1
; CHECK-NEXT: --> ((2 * %a)<nsw> smin (4 * %b)<nsw>) U: [0,-1) S: [-2147483648,2147483645)
; CHECK-NEXT: %i.011 = phi i32 [ %inc, %for.body ], [ 0, %entry ]
-; CHECK-NEXT: --> {0,+,1}<nuw><nsw><%for.body> U: [0,-2147483648) S: [0,-2147483648) Exits: (-1 + ((2 * %a)<nsw> smin (4 * %b)<nsw>)) LoopDispositions: { %for.body: Computable }
+; CHECK-NEXT: --> {0,+,1}<nuw><nsw><%for.body> U: [0,2147483647) S: [0,2147483647) Exits: (-1 + ((2 * %a)<nsw> smin (4 * %b)<nsw>)) LoopDispositions: { %for.body: Computable }
; CHECK-NEXT: %inc = add nuw nsw i32 %i.011, 1
-; CHECK-NEXT: --> {1,+,1}<nuw><%for.body> U: [1,-1) S: [1,-1) Exits: ((2 * %a)<nsw> smin (4 * %b)<nsw>) LoopDispositions: { %for.body: Computable }
+; CHECK-NEXT: --> {1,+,1}<nuw><nsw><%for.body> U: [1,-2147483648) S: [1,-2147483648) Exits: ((2 * %a)<nsw> smin (4 * %b)<nsw>) LoopDispositions: { %for.body: Computable }
; CHECK-NEXT: Determining loop execution counts for: @smin
; CHECK-NEXT: Loop %for.body: backedge-taken count is (-1 + ((2 * %a)<nsw> smin (4 * %b)<nsw>))
-; CHECK-NEXT: Loop %for.body: constant max backedge-taken count is -3
+; CHECK-NEXT: Loop %for.body: constant max backedge-taken count is 2147483646
; CHECK-NEXT: Loop %for.body: symbolic max backedge-taken count is (-1 + ((2 * %a)<nsw> smin (4 * %b)<nsw>))
; CHECK-NEXT: Loop %for.body: Predicated backedge-taken count is (-1 + ((2 * %a)<nsw> smin (4 * %b)<nsw>))
; CHECK-NEXT: Predicates:
-; CHECK: Loop %for.body: Trip multiple is 2
+; CHECK: Loop %for.body: Trip multiple is 1
;
; void smin(signed a, signed b) {
; a *= 2;
Index: llvm/lib/Analysis/ScalarEvolution.cpp
===================================================================
--- llvm/lib/Analysis/ScalarEvolution.cpp
+++ llvm/lib/Analysis/ScalarEvolution.cpp
@@ -14971,6 +14971,13 @@
return SCEVRewriteVisitor<SCEVLoopGuardRewriter>::visitSMinExpr(Expr);
return I->second;
}
+
+ const SCEV *visitMulExpr(const SCEVMulExpr *Expr) {
+ auto I = Map.find(Expr);
+ if (I == Map.end())
+ return SCEVRewriteVisitor<SCEVLoopGuardRewriter>::visitMulExpr(Expr);
+ return I->second;
+ }
};
const SCEV *ScalarEvolution::applyLoopGuards(const SCEV *Expr, const Loop *L) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D145231.502101.patch
Type: text/x-patch
Size: 3490 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230303/f8a1810f/attachment.bin>
More information about the llvm-commits
mailing list