Skip to content

Commit

Permalink
[LAA] Only invalidate loops that require runtime checks (NFCI).
Browse files Browse the repository at this point in the history
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
  • Loading branch information
fhahn committed Jul 6, 2024
1 parent 8426b51 commit 5028dea
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion llvm/include/llvm/Analysis/LoopAccessAnalysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -863,7 +863,7 @@ class LoopAccessInfoManager {

const LoopAccessInfo &getInfo(Loop &L);

void clear() { LoopAccessInfoMap.clear(); }
void clear();

bool invalidate(Function &F, const PreservedAnalyses &PA,
FunctionAnalysisManager::Invalidator &Inv);
Expand Down
16 changes: 16 additions & 0 deletions llvm/lib/Analysis/LoopAccessAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3084,6 +3084,22 @@ const LoopAccessInfo &LoopAccessInfoManager::getInfo(Loop &L) {

return *It->second;
}
void LoopAccessInfoManager::clear() {
SmallVector<Loop *> ToRemove;
// Collect LoopAccessInfo entries that may keep references to IR outside the
// analyzed loop or SCEVs that may have been modified or invalidated. At the
// moment, that is loops requiring memory or SCEV runtime checks, as those cache
// SCEVs, e.g. for pointer expressions.
for (const auto &[L, LAI] : LoopAccessInfoMap) {
if (LAI->getRuntimePointerChecking()->getChecks().empty() &&
LAI->getPSE().getPredicate().isAlwaysTrue())
continue;
ToRemove.push_back(L);
}

for (Loop *L : ToRemove)
LoopAccessInfoMap.erase(L);
}

bool LoopAccessInfoManager::invalidate(
Function &F, const PreservedAnalyses &PA,
Expand Down

0 comments on commit 5028dea

Please sign in to comment.