[llvm] Utils: Preserve address space for global_ctors (PR #112532)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 16 05:25:42 PDT 2024
https://github.com/arsenm created https://github.com/llvm/llvm-project/pull/112532
None
>From b93d55924781112606303e182f3cdeaafe0a858b Mon Sep 17 00:00:00 2001
From: Matt Arsenault <Matthew.Arsenault at amd.com>
Date: Wed, 16 Oct 2024 16:15:28 +0400
Subject: [PATCH] Utils: Preserve address space for global_ctors
---
llvm/lib/Transforms/Utils/CtorUtils.cpp | 6 +++---
.../GlobalOpt/ctor-list-preserve-addrspace.ll | 19 +++++++++++++++++++
2 files changed, 22 insertions(+), 3 deletions(-)
create mode 100644 llvm/test/Transforms/GlobalOpt/ctor-list-preserve-addrspace.ll
diff --git a/llvm/lib/Transforms/Utils/CtorUtils.cpp b/llvm/lib/Transforms/Utils/CtorUtils.cpp
index 507729bc5ebc06..968446c4eee117 100644
--- a/llvm/lib/Transforms/Utils/CtorUtils.cpp
+++ b/llvm/lib/Transforms/Utils/CtorUtils.cpp
@@ -45,9 +45,9 @@ static void removeGlobalCtors(GlobalVariable *GCL, const BitVector &CtorsToRemov
}
// Create the new global and insert it next to the existing list.
- GlobalVariable *NGV =
- new GlobalVariable(CA->getType(), GCL->isConstant(), GCL->getLinkage(),
- CA, "", GCL->getThreadLocalMode());
+ GlobalVariable *NGV = new GlobalVariable(
+ CA->getType(), GCL->isConstant(), GCL->getLinkage(), CA, "",
+ GCL->getThreadLocalMode(), GCL->getAddressSpace());
GCL->getParent()->insertGlobalVariable(GCL->getIterator(), NGV);
NGV->takeName(GCL);
diff --git a/llvm/test/Transforms/GlobalOpt/ctor-list-preserve-addrspace.ll b/llvm/test/Transforms/GlobalOpt/ctor-list-preserve-addrspace.ll
new file mode 100644
index 00000000000000..3f2f041b90e74d
--- /dev/null
+++ b/llvm/test/Transforms/GlobalOpt/ctor-list-preserve-addrspace.ll
@@ -0,0 +1,19 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals all --version 5
+; RUN: opt -S -passes=globalopt < %s | FileCheck %s
+
+; Make sure the address space of global_ctors is preserved
+
+%ini = type { i32, ptr, ptr }
+
+ at llvm.global_ctors = appending addrspace(1) global [1 x %ini] [%ini { i32 65534, ptr @ctor1, ptr null }]
+
+;.
+; CHECK: @llvm.global_ctors = appending addrspace(1) global [0 x %ini] zeroinitializer
+;.
+define void @ctor1() {
+; CHECK-LABEL: define void @ctor1() local_unnamed_addr {
+; CHECK-NEXT: ret void
+;
+ ret void
+}
+
More information about the llvm-commits
mailing list