From 7a57c7308915eba4a710bdce45214821eee822b9 Mon Sep 17 00:00:00 2001 From: gbaraldi Date: Mon, 5 May 2025 17:21:22 -0300 Subject: [PATCH 1/2] Fix removal of globals with addrspaces in removeAddrspaces --- src/llvm-remove-addrspaces.cpp | 4 ++-- test/llvmpasses/remove-addrspaces.ll | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/llvm-remove-addrspaces.cpp b/src/llvm-remove-addrspaces.cpp index bb492f467e74c..78ff70b12409b 100644 --- a/src/llvm-remove-addrspaces.cpp +++ b/src/llvm-remove-addrspaces.cpp @@ -256,7 +256,7 @@ bool removeAddrspaces(Module &M, AddrspaceRemapFunction ASRemapper) Name, (GlobalVariable *)nullptr, GV->getThreadLocalMode(), - GV->getType()->getAddressSpace()); + cast(TypeRemapper.remapType(GV->getType()))->getAddressSpace()); NGV->copyAttributesFrom(GV); VMap[GV] = NGV; } @@ -276,7 +276,7 @@ bool removeAddrspaces(Module &M, AddrspaceRemapFunction ASRemapper) auto *NGA = GlobalAlias::create( TypeRemapper.remapType(GA->getValueType()), - GA->getType()->getPointerAddressSpace(), + cast(TypeRemapper.remapType(GA->getType()))->getAddressSpace(), GA->getLinkage(), Name, &M); diff --git a/test/llvmpasses/remove-addrspaces.ll b/test/llvmpasses/remove-addrspaces.ll index fbd84de85a4a3..15fed41b44819 100644 --- a/test/llvmpasses/remove-addrspaces.ll +++ b/test/llvmpasses/remove-addrspaces.ll @@ -110,6 +110,18 @@ define void @byval_type([1 x {} addrspace(10)*] addrspace(11)* byval([1 x {} add ret void } +; COM: check that the addrspace of the global itself is removed +; CHECK: @ejl_enz_runtime_exc = external global {} +; OPAQUE: @ejl_enz_runtime_exc = external global {} +@ejl_enz_runtime_exc = external addrspace(10) global {} + +define private fastcc void @diffejulia__mapreduce_97() { +L6: +; CHECK: store atomic {}* @ejl_enz_runtime_exc, {}** null unordered +; OPAQUE: store atomic ptr @ejl_enz_runtime_exc, ptr null unordered + store atomic {} addrspace(10)* @ejl_enz_runtime_exc, {} addrspace(10)* addrspace(10)* null unordered, align 8 + unreachable +} ; COM: check that function attributes are preserved on declarations too declare void @convergent_function() #0 From 61d0c9e51138ecb4d8d1af1947e3acc944afbaf0 Mon Sep 17 00:00:00 2001 From: gbaraldi Date: Mon, 5 May 2025 19:39:07 -0300 Subject: [PATCH 2/2] Fix test --- test/llvmpasses/remove-addrspaces.ll | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/test/llvmpasses/remove-addrspaces.ll b/test/llvmpasses/remove-addrspaces.ll index 15fed41b44819..99acd92b0e03b 100644 --- a/test/llvmpasses/remove-addrspaces.ll +++ b/test/llvmpasses/remove-addrspaces.ll @@ -2,6 +2,9 @@ ; RUN: opt --load-pass-plugin=libjulia-codegen%shlibext -passes='RemoveJuliaAddrspaces' -S %s | FileCheck %s --check-prefixes=CHECK,OPAQUE +; COM: check that the addrspace of the global itself is removed +; OPAQUE: @ejl_enz_runtime_exc = external global {} +@ejl_enz_runtime_exc = external addrspace(10) global {} ; COM: check that package image fptrs work @pjlsys_BoundsError_32 = internal global {} addrspace(10)* ({}***, {} addrspace(10)*, [1 x i64] addrspace(11)*)* null @@ -110,14 +113,9 @@ define void @byval_type([1 x {} addrspace(10)*] addrspace(11)* byval([1 x {} add ret void } -; COM: check that the addrspace of the global itself is removed -; CHECK: @ejl_enz_runtime_exc = external global {} -; OPAQUE: @ejl_enz_runtime_exc = external global {} -@ejl_enz_runtime_exc = external addrspace(10) global {} define private fastcc void @diffejulia__mapreduce_97() { L6: -; CHECK: store atomic {}* @ejl_enz_runtime_exc, {}** null unordered ; OPAQUE: store atomic ptr @ejl_enz_runtime_exc, ptr null unordered store atomic {} addrspace(10)* @ejl_enz_runtime_exc, {} addrspace(10)* addrspace(10)* null unordered, align 8 unreachable