[llvm] 133ad80 - [CodeGenPrepare] Report an error if ProfileSummaryAnalysis is not available (#199268)
via llvm-commits
llvm-commits at lists.llvm.org
Sun May 24 10:58:55 PDT 2026
Author: Justin Lebar
Date: 2026-05-24T10:58:51-07:00
New Revision: 133ad80cd864b546ee6d73f10b8ac36a9c982fed
URL: https://github.com/llvm/llvm-project/commit/133ad80cd864b546ee6d73f10b8ac36a9c982fed
DIFF: https://github.com/llvm/llvm-project/commit/133ad80cd864b546ee6d73f10b8ac36a9c982fed.diff
LOG: [CodeGenPrepare] Report an error if ProfileSummaryAnalysis is not available (#199268)
CodeGenPreparePass can't declare ProfileSummaryAnalysis as required,
because PSA is a module-level analysis, but CFP is a function-level pass.
Therefore it accesses PSA using getCachedResult, and PSA might be null.
In practice this doesn't happen, because the CGP pass pipeline
preparation code ensures that PSA is present. But if you invoke
CGP via opt -passes=codegenprepare, then it's not
there, and we segfault.
Fix for https://github.com/llvm/llvm-project/issues/173360.
This bug was found by a large run of Opus 4.7 looking for bugs in LLVM.
Added:
llvm/test/Transforms/CodeGenPrepare/X86/null-psi-no-crash.ll
Modified:
llvm/lib/CodeGen/CodeGenPrepare.cpp
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp b/llvm/lib/CodeGen/CodeGenPrepare.cpp
index 74a0502d8cb7c..9b756dc7b03b7 100644
--- a/llvm/lib/CodeGen/CodeGenPrepare.cpp
+++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp
@@ -570,6 +570,9 @@ bool CodeGenPrepare::run(Function &F, FunctionAnalysisManager &AM) {
BFI = &AM.getResult<BlockFrequencyAnalysis>(F);
auto &MAMProxy = AM.getResult<ModuleAnalysisManagerFunctionProxy>(F);
PSI = MAMProxy.getCachedResult<ProfileSummaryAnalysis>(*F.getParent());
+ if (!PSI)
+ reportFatalUsageError("this pass requires the profile-summary module "
+ "analysis to be available");
BBSectionsProfileReader =
AM.getCachedResult<BasicBlockSectionsProfileReaderAnalysis>(F);
DomTreeUpdater DTUpdater(&AM.getResult<DominatorTreeAnalysis>(F),
diff --git a/llvm/test/Transforms/CodeGenPrepare/X86/null-psi-no-crash.ll b/llvm/test/Transforms/CodeGenPrepare/X86/null-psi-no-crash.ll
new file mode 100644
index 0000000000000..c5ce8099f3f52
--- /dev/null
+++ b/llvm/test/Transforms/CodeGenPrepare/X86/null-psi-no-crash.ll
@@ -0,0 +1,8 @@
+; RUN: not opt -passes=codegenprepare -mtriple=x86_64-linux-gnu -disable-output < %s 2>&1 | FileCheck %s
+
+; Check that if we do not require PSI in the pipeline, we error out instead of crashing.
+
+; CHECK: LLVM ERROR: this pass requires the profile-summary module analysis to be available
+define void @f() {
+ ret void
+}
More information about the llvm-commits
mailing list