Skip to content

Commit 2f89d4a

Browse files
authored
[SCEV] Split collecting and applying rewrite info from loop guards (NFC) (#97316)
Introduce a new LoopGuards class to track info from loop guards and split off collecting rewrite info to LoopGuards::collect. This allows users of applyLoopGuards to collect rewrite info once in cases where the same loop guards are applied multiple times. This is used to collect rewrite info once in howFarToZero, which saves a bit of compile-time: stage1-O3: -0.04% stage1-ReleaseThinLTO: -0.02% stage1-ReleaseLTO-g: -0.04% stage2-O3: -0.02% https://llvm-compile-time-tracker.com/compare.php?from=117b53ae38428ca66eaa886fb432e6f09db88fe4&to=4ffb7b2e1c99081ccebe6f236c48a0be2f64b6ff&stat=instructions:u Notably this improves mafft by -0.9% with -O3, -0.11% with LTO and -0.12% with stage2-O3. PR: #97316
1 parent 3c50cbf commit 2f89d4a

File tree

2 files changed

+196
-158
lines changed

2 files changed

+196
-158
lines changed

llvm/include/llvm/Analysis/ScalarEvolution.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1299,8 +1299,26 @@ class ScalarEvolution {
12991299
/// sharpen it.
13001300
void setNoWrapFlags(SCEVAddRecExpr *AddRec, SCEV::NoWrapFlags Flags);
13011301

1302+
class LoopGuards {
1303+
DenseMap<const SCEV *, const SCEV *> RewriteMap;
1304+
bool PreserveNUW = false;
1305+
bool PreserveNSW = false;
1306+
ScalarEvolution &SE;
1307+
1308+
LoopGuards(ScalarEvolution &SE) : SE(SE) {}
1309+
1310+
public:
1311+
/// Collect rewrite map for loop guards for loop \p L, together with flags
1312+
/// indicating if NUW and NSW can be preserved during rewriting.
1313+
static LoopGuards collect(const Loop *L, ScalarEvolution &SE);
1314+
1315+
/// Try to apply the collected loop guards to \p Expr.
1316+
const SCEV *rewrite(const SCEV *Expr) const;
1317+
};
1318+
13021319
/// Try to apply information from loop guards for \p L to \p Expr.
13031320
const SCEV *applyLoopGuards(const SCEV *Expr, const Loop *L);
1321+
const SCEV *applyLoopGuards(const SCEV *Expr, const LoopGuards &Guards);
13041322

13051323
/// Return true if the loop has no abnormal exits. That is, if the loop
13061324
/// is not infinite, it must exit through an explicit edge in the CFG.

0 commit comments

Comments
 (0)