[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 13:35:23 PST 2024


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

>From 6254638213938d0dfa7825ce078e33c4f8935a39 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/3] 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 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();
 }

>From 0c8810ee4c2ed97ef775fa1133be20e07a98a522 Mon Sep 17 00:00:00 2001
From: Kyungwoo Lee <kyulee at meta.com>
Date: Fri, 15 Nov 2024 00:39:46 -0800
Subject: [PATCH 2/3] Address comments from 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 } }

>From f96d7173de39d932108cba10909c284de124dda1 Mon Sep 17 00:00:00 2001
From: Kyungwoo Lee <kyulee at meta.com>
Date: Fri, 15 Nov 2024 06:42:38 -0800
Subject: [PATCH 3/3] Address comments from nocchijiang

---
 .../{ThinLTO/AArch64 => CodeGen/Generic}/cgdata-merge-crash.ll    | 0
 1 file changed, 0 insertions(+), 0 deletions(-)
 rename llvm/test/{ThinLTO/AArch64 => CodeGen/Generic}/cgdata-merge-crash.ll (100%)

diff --git a/llvm/test/ThinLTO/AArch64/cgdata-merge-crash.ll b/llvm/test/CodeGen/Generic/cgdata-merge-crash.ll
similarity index 100%
rename from llvm/test/ThinLTO/AArch64/cgdata-merge-crash.ll
rename to llvm/test/CodeGen/Generic/cgdata-merge-crash.ll



More information about the llvm-commits mailing list