[llvm-branch-commits] [llvm] FunctionAttrs: Only invalidate analyses of changed functions in norecurse LTO inference (PR #244818)
Matt Arsenault via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Fri Nov 20 20:55:26 PST 2026
https://github.com/arsenm created https://github.com/llvm/llvm-project/pull/244818
NoRecurseLTOInferencePass only adds norecurse, so invalidate only the
changed functions and their direct callers instead of every function
analysis.
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
>From c012cae6fd9cd4ccdf07901386c9405d91d217ec Mon Sep 17 00:00:00 2001
From: Matt Arsenault <Matthew.Arsenault at amd.com>
Date: Fri, 20 Nov 2026 23:50:51 -0500
Subject: [PATCH] FunctionAttrs: Only invalidate analyses of changed functions
in norecurse LTO inference
NoRecurseLTOInferencePass only adds norecurse, so invalidate only the
changed functions and their direct callers instead of every function
analysis.
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
---
llvm/lib/Transforms/IPO/FunctionAttrs.cpp | 13 +++++--
...orecurse-lto-preserve-function-analyses.ll | 38 +++++++++++++++++++
2 files changed, 47 insertions(+), 4 deletions(-)
create mode 100644 llvm/test/Transforms/FunctionAttrs/norecurse-lto-preserve-function-analyses.ll
diff --git a/llvm/lib/Transforms/IPO/FunctionAttrs.cpp b/llvm/lib/Transforms/IPO/FunctionAttrs.cpp
index 1cfe62b8cadb1..4c50f45e7e186 100644
--- a/llvm/lib/Transforms/IPO/FunctionAttrs.cpp
+++ b/llvm/lib/Transforms/IPO/FunctionAttrs.cpp
@@ -2500,6 +2500,8 @@ PreservedAnalyses NoRecurseLTOInferencePass::run(Module &M,
// module.
bool Changed = false;
LazyCallGraph &CG = MAM.getResult<LazyCallGraphAnalysis>(M);
+ FunctionAnalysisManager &FAM =
+ MAM.getResult<FunctionAnalysisManagerModuleProxy>(M).getManager();
CG.buildRefSCCs();
for (LazyCallGraph::RefSCC &RC : CG.postorder_ref_sccs()) {
@@ -2525,14 +2527,17 @@ PreservedAnalyses NoRecurseLTOInferencePass::run(Module &M,
if (!mayHaveRecursiveCallee(F, AnyFunctionsAddressIsTaken)) {
F.setDoesNotRecurse();
++NumNoRecurse;
+ invalidateChangedFunction(FAM, F);
Changed = true;
}
}
+ if (!Changed)
+ return PreservedAnalyses::all();
+
PreservedAnalyses PA;
- if (Changed)
- PA.preserve<LazyCallGraphAnalysis>();
- else
- PA = PreservedAnalyses::all();
+ PA.preserve<LazyCallGraphAnalysis>();
+ PA.preserve<FunctionAnalysisManagerModuleProxy>();
+ PA.preserveSet<AllAnalysesOn<Function>>();
return PA;
}
diff --git a/llvm/test/Transforms/FunctionAttrs/norecurse-lto-preserve-function-analyses.ll b/llvm/test/Transforms/FunctionAttrs/norecurse-lto-preserve-function-analyses.ll
new file mode 100644
index 0000000000000..24eb63d2592a5
--- /dev/null
+++ b/llvm/test/Transforms/FunctionAttrs/norecurse-lto-preserve-function-analyses.ll
@@ -0,0 +1,38 @@
+; RUN: opt -disable-output -debug-pass-manager -passes='function(require<domtree>,require<lazy-value-info>,require<target-lib-info>,require<target-ir>),norecurse-lto-inference,function(require<domtree>,require<lazy-value-info>,require<target-lib-info>,require<target-ir>)' %s 2>&1 | FileCheck %s
+
+; Inferring norecurse on @callee and @caller should only invalidate the non-CFG
+; analyses of those functions, other than TargetLibraryInfo and
+; TargetTransformInfo, and not the analyses of @other.
+
+; CHECK: Running pass: NoRecurseLTOInferencePass on [module]{{$}}
+; CHECK-NEXT: Running analysis: LazyCallGraphAnalysis on [module]{{$}}
+; CHECK-NEXT: Invalidating analysis: LazyValueAnalysis on callee{{$}}
+; CHECK-NEXT: Invalidating analysis: LazyValueAnalysis on caller{{$}}
+; CHECK-NEXT: Running pass: RequireAnalysisPass<{{.*}}DominatorTreeAnalysis{{.*}}> on callee (1 instruction){{$}}
+; CHECK-NEXT: Running pass: RequireAnalysisPass<{{.*}}LazyValueAnalysis{{.*}}> on callee (1 instruction){{$}}
+; CHECK-NEXT: Running analysis: LazyValueAnalysis on callee{{$}}
+; CHECK-NEXT: Running pass: RequireAnalysisPass<{{.*}}TargetLibraryAnalysis{{.*}}> on callee (1 instruction){{$}}
+; CHECK-NEXT: Running pass: RequireAnalysisPass<{{.*}}TargetIRAnalysis{{.*}}> on callee (1 instruction){{$}}
+; CHECK-NEXT: Running pass: RequireAnalysisPass<{{.*}}DominatorTreeAnalysis{{.*}}> on caller (2 instructions){{$}}
+; CHECK-NEXT: Running pass: RequireAnalysisPass<{{.*}}LazyValueAnalysis{{.*}}> on caller (2 instructions){{$}}
+; CHECK-NEXT: Running analysis: LazyValueAnalysis on caller{{$}}
+; CHECK-NEXT: Running pass: RequireAnalysisPass<{{.*}}TargetLibraryAnalysis{{.*}}> on caller (2 instructions){{$}}
+; CHECK-NEXT: Running pass: RequireAnalysisPass<{{.*}}TargetIRAnalysis{{.*}}> on caller (2 instructions){{$}}
+; CHECK-NEXT: Running pass: RequireAnalysisPass<{{.*}}DominatorTreeAnalysis{{.*}}> on other (1 instruction){{$}}
+; CHECK-NEXT: Running pass: RequireAnalysisPass<{{.*}}LazyValueAnalysis{{.*}}> on other (1 instruction){{$}}
+; CHECK-NEXT: Running pass: RequireAnalysisPass<{{.*}}TargetLibraryAnalysis{{.*}}> on other (1 instruction){{$}}
+; CHECK-NEXT: Running pass: RequireAnalysisPass<{{.*}}TargetIRAnalysis{{.*}}> on other (1 instruction){{$}}
+; CHECK-NEXT: Running pass: VerifierPass on [module]{{$}}
+
+define internal void @callee() {
+ ret void
+}
+
+define void @caller() {
+ call void @callee()
+ ret void
+}
+
+define void @other() norecurse {
+ ret void
+}
More information about the llvm-branch-commits
mailing list