Skip to content

Commit 5028dea

Browse files
committed
[LAA] Only invalidate loops that require runtime checks (NFCI).
LAA doesn't keep references to IR outside the loop or references to SCEVs that may be invalidated, unless runtime checks are needed (either memory or SCEV predicates). For the current LAA users, it should be sufficient to invalidate entries for loops that require runtime checks, thus avoiding analyzing loops again unnecessarily. This helps reduce compile-time, in particular when removing the restrictions added in 234cc40. https://llvm-compile-time-tracker.com/compare.php?from=73894dba2cdbcc00678d0c13a6b61765675f60b4&to=05c6bdc41b5f63696ebeb7116325725fa94f66d6&stat=instructions:u
1 parent 8426b51 commit 5028dea

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

llvm/include/llvm/Analysis/LoopAccessAnalysis.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -863,7 +863,7 @@ class LoopAccessInfoManager {
863863

864864
const LoopAccessInfo &getInfo(Loop &L);
865865

866-
void clear() { LoopAccessInfoMap.clear(); }
866+
void clear();
867867

868868
bool invalidate(Function &F, const PreservedAnalyses &PA,
869869
FunctionAnalysisManager::Invalidator &Inv);

llvm/lib/Analysis/LoopAccessAnalysis.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3084,6 +3084,22 @@ const LoopAccessInfo &LoopAccessInfoManager::getInfo(Loop &L) {
30843084

30853085
return *It->second;
30863086
}
3087+
void LoopAccessInfoManager::clear() {
3088+
SmallVector<Loop *> ToRemove;
3089+
// Collect LoopAccessInfo entries that may keep references to IR outside the
3090+
// analyzed loop or SCEVs that may have been modified or invalidated. At the
3091+
// moment, that is loops requiring memory or SCEV runtime checks, as those cache
3092+
// SCEVs, e.g. for pointer expressions.
3093+
for (const auto &[L, LAI] : LoopAccessInfoMap) {
3094+
if (LAI->getRuntimePointerChecking()->getChecks().empty() &&
3095+
LAI->getPSE().getPredicate().isAlwaysTrue())
3096+
continue;
3097+
ToRemove.push_back(L);
3098+
}
3099+
3100+
for (Loop *L : ToRemove)
3101+
LoopAccessInfoMap.erase(L);
3102+
}
30873103

30883104
bool LoopAccessInfoManager::invalidate(
30893105
Function &F, const PreservedAnalyses &PA,

0 commit comments

Comments
 (0)