[llvm] 5028dea - [LAA] Only invalidate loops that require runtime checks (NFCI).

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Sat Jul 6 14:15:20 PDT 2024


Author: Florian Hahn
Date: 2024-07-06T22:14:01+01:00
New Revision: 5028dea65266ab8b7f8f9ebd5d5e01faacebc645

URL: https://github.com/llvm/llvm-project/commit/5028dea65266ab8b7f8f9ebd5d5e01faacebc645
DIFF: https://github.com/llvm/llvm-project/commit/5028dea65266ab8b7f8f9ebd5d5e01faacebc645.diff

LOG: [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 234cc40adc6.

https://llvm-compile-time-tracker.com/compare.php?from=73894dba2cdbcc00678d0c13a6b61765675f60b4&to=05c6bdc41b5f63696ebeb7116325725fa94f66d6&stat=instructions:u

Added: 
    

Modified: 
    llvm/include/llvm/Analysis/LoopAccessAnalysis.h
    llvm/lib/Analysis/LoopAccessAnalysis.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Analysis/LoopAccessAnalysis.h b/llvm/include/llvm/Analysis/LoopAccessAnalysis.h
index c74e76604e786..f6bb044392938 100644
--- a/llvm/include/llvm/Analysis/LoopAccessAnalysis.h
+++ b/llvm/include/llvm/Analysis/LoopAccessAnalysis.h
@@ -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);

diff  --git a/llvm/lib/Analysis/LoopAccessAnalysis.cpp b/llvm/lib/Analysis/LoopAccessAnalysis.cpp
index f132e45540525..018861a665c4c 100644
--- a/llvm/lib/Analysis/LoopAccessAnalysis.cpp
+++ b/llvm/lib/Analysis/LoopAccessAnalysis.cpp
@@ -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,


        


More information about the llvm-commits mailing list