[llvm] Fix crash from [CGData] Global Merge Functions (#112671) (PR #116241)

Kyungwoo Lee via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 15 01:23:21 PST 2024


https://github.com/kyulee-com updated https://github.com/llvm/llvm-project/pull/116241

>From c24e0641572215dc01c6a270e61d6473951bc0c2 Mon Sep 17 00:00:00 2001
From: Kyungwoo Lee <kyulee at meta.com>
Date: Thu, 14 Nov 2024 07:03:53 -0800
Subject: [PATCH 1/2] Fix crash from [CGData] Global Merge Functions (#112671)

---
 llvm/include/llvm/CodeGen/GlobalMergeFunctions.h | 4 ++++
 llvm/lib/CodeGen/GlobalMergeFunctions.cpp        | 3 +--
 2 files changed, 5 insertions(+), 2 deletions(-)

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 2b367ca87d9008..0e109bcdc7b616 100644
--- a/llvm/lib/CodeGen/GlobalMergeFunctions.cpp
+++ b/llvm/lib/CodeGen/GlobalMergeFunctions.cpp
@@ -666,7 +666,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();
 }

>From 0bc42fad037f64b9042de8269a6bad08af1629e0 Mon Sep 17 00:00:00 2001
From: Kyungwoo Lee <kyulee at meta.com>
Date: Fri, 15 Nov 2024 01:22:52 -0800
Subject: [PATCH 2/2] Address comments from m mikaelholmen

---
 llvm/test/ThinLTO/AArch64/cgdata-merge-crash.ll | 6 ++++++
 1 file changed, 6 insertions(+)
 create mode 100644 llvm/test/ThinLTO/AArch64/cgdata-merge-crash.ll

diff --git a/llvm/test/ThinLTO/AArch64/cgdata-merge-crash.ll b/llvm/test/ThinLTO/AArch64/cgdata-merge-crash.ll
new file mode 100644
index 00000000000000..34a4622cee2b12
--- /dev/null
+++ b/llvm/test/ThinLTO/AArch64/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