[llvm] [CodeGen][GC] Skip function without GC in `GCLoweringPass` (PR #84421)

via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 7 22:49:51 PST 2024


https://github.com/paperchalice updated https://github.com/llvm/llvm-project/pull/84421

>From e1668c840819c5ff2ebe28424bcd54a9a2abc484 Mon Sep 17 00:00:00 2001
From: PaperChalice <liujunchang97 at outlook.com>
Date: Fri, 8 Mar 2024 10:14:00 +0800
Subject: [PATCH 1/2] [CodeGen][GC] Skip function without GC in
 `GCLoweringPass`

---
 llvm/lib/CodeGen/GCRootLowering.cpp | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/llvm/lib/CodeGen/GCRootLowering.cpp b/llvm/lib/CodeGen/GCRootLowering.cpp
index 894ab9a0486a7b..0d82f2bab8960b 100644
--- a/llvm/lib/CodeGen/GCRootLowering.cpp
+++ b/llvm/lib/CodeGen/GCRootLowering.cpp
@@ -81,6 +81,9 @@ class GCMachineCodeAnalysis : public MachineFunctionPass {
 
 PreservedAnalyses GCLoweringPass::run(Function &F,
                                       FunctionAnalysisManager &FAM) {
+  if (!F.hasGC())
+    return PreservedAnalyses::all();
+
   auto &Info = FAM.getResult<GCFunctionAnalysis>(F);
 
   bool Changed = DoLowering(F, Info.getStrategy());

>From ac2ca2d5d3aa4ff5cc1cab5c8520f3de220f36c2 Mon Sep 17 00:00:00 2001
From: PaperChalice <liujunchang97 at outlook.com>
Date: Fri, 8 Mar 2024 14:16:12 +0800
Subject: [PATCH 2/2] add test

---
 llvm/test/CodeGen/X86/GC/alloc_loop.ll | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/llvm/test/CodeGen/X86/GC/alloc_loop.ll b/llvm/test/CodeGen/X86/GC/alloc_loop.ll
index 4b7230fee9c5a9..4e87735e830ffe 100644
--- a/llvm/test/CodeGen/X86/GC/alloc_loop.ll
+++ b/llvm/test/CodeGen/X86/GC/alloc_loop.ll
@@ -1,4 +1,5 @@
 ; RUN: llc -mtriple=x86_64 < %s
+; RUN: opt -S -passes='require<collector-metadata>,function(gc-lowering)' < %s | FileCheck %s
 
 declare ptr @llvm_gc_allocate(i32)
 declare void @llvm_gc_initialize(i32)
@@ -31,6 +32,8 @@ entry:
 	%B.1 = load ptr, ptr %B
 	%A.1 = load ptr, ptr %A
 	call void @llvm.gcwrite(ptr %A.1, ptr %B.upgrd.1, ptr %B.1)
+	; CHECK-NOT: call void @llvm.gcwrite(ptr %A.1, ptr %B.upgrd.1, ptr %B.1)
+	; CHECK: store ptr %A.1, ptr %B.1, align 8
 	
 	br label %AllocLoop
 
@@ -47,4 +50,8 @@ Exit:
 	ret i32 0
 }
 
+define void @no_gc() {
+	ret void
+}
+
 declare void @__main()



More information about the llvm-commits mailing list