[llvm] 816c975 - Fix crash from [CGData] Global Merge Functions (#112671) (#116241)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 15 14:57:21 PST 2024
Author: Kyungwoo Lee
Date: 2024-11-15T14:57:17-08:00
New Revision: 816c975ea7b27a784c8f0d6a9b92571ebc97d4a3
URL: https://github.com/llvm/llvm-project/commit/816c975ea7b27a784c8f0d6a9b92571ebc97d4a3
DIFF: https://github.com/llvm/llvm-project/commit/816c975ea7b27a784c8f0d6a9b92571ebc97d4a3.diff
LOG: Fix crash from [CGData] Global Merge Functions (#112671) (#116241)
Module summary index is optional for this pass, and we shouldn't run it,
but import it as necessary.
Added:
llvm/test/CodeGen/Generic/cgdata-merge-crash.ll
Modified:
llvm/include/llvm/CodeGen/GlobalMergeFunctions.h
llvm/lib/CodeGen/GlobalMergeFunctions.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/CodeGen/GlobalMergeFunctions.h b/llvm/include/llvm/CodeGen/GlobalMergeFunctions.h
index 82239e04dbd4fd..caea5b62851ea6 100644
--- a/llvm/include/llvm/CodeGen/GlobalMergeFunctions.h
+++ b/llvm/include/llvm/CodeGen/GlobalMergeFunctions.h
@@ -78,6 +78,10 @@ class GlobalMergeFunc {
/// Global function merging pass for new pass manager.
struct GlobalMergeFuncPass : public PassInfoMixin<GlobalMergeFuncPass> {
+ const ModuleSummaryIndex *ImportSummary = nullptr;
+ GlobalMergeFuncPass() = default;
+ GlobalMergeFuncPass(const ModuleSummaryIndex *ImportSummary)
+ : ImportSummary(ImportSummary) {}
PreservedAnalyses run(Module &M, AnalysisManager<Module> &);
};
diff --git a/llvm/lib/CodeGen/GlobalMergeFunctions.cpp b/llvm/lib/CodeGen/GlobalMergeFunctions.cpp
index be34855d0dc3af..c8f1b98c9a18e9 100644
--- a/llvm/lib/CodeGen/GlobalMergeFunctions.cpp
+++ b/llvm/lib/CodeGen/GlobalMergeFunctions.cpp
@@ -637,7 +637,6 @@ bool GlobalMergeFuncPassWrapper::runOnModule(Module &M) {
PreservedAnalyses GlobalMergeFuncPass::run(Module &M,
AnalysisManager<Module> &AM) {
- ModuleSummaryIndex *Index = &(AM.getResult<ModuleSummaryIndexAnalysis>(M));
- bool Changed = GlobalMergeFunc(Index).run(M);
+ bool Changed = GlobalMergeFunc(ImportSummary).run(M);
return Changed ? PreservedAnalyses::none() : PreservedAnalyses::all();
}
diff --git a/llvm/test/CodeGen/Generic/cgdata-merge-crash.ll b/llvm/test/CodeGen/Generic/cgdata-merge-crash.ll
new file mode 100644
index 00000000000000..34a4622cee2b12
--- /dev/null
+++ b/llvm/test/CodeGen/Generic/cgdata-merge-crash.ll
@@ -0,0 +1,6 @@
+; This test checks if the global merge func pass should not build module summary.
+
+; RUN: opt --passes=global-merge-func %s -o /dev/null
+
+ at 0 = global { { ptr, i32, i32 } } { { ptr, i32, i32 } { ptr null, i32 19, i32 5 } }
+ at 1 = global { { ptr, i32, i32 } } { { ptr, i32, i32 } { ptr null, i32 22, i32 5 } }
More information about the llvm-commits
mailing list