[llvm] cd683bd - [HipStdPar] Fix globle variable (#90627)

via llvm-commits llvm-commits at lists.llvm.org
Thu May 2 06:34:56 PDT 2024


Author: Yaxun (Sam) Liu
Date: 2024-05-02T09:34:52-04:00
New Revision: cd683bd32cecd97b9d9fd345c4e6c067d84fefd4

URL: https://github.com/llvm/llvm-project/commit/cd683bd32cecd97b9d9fd345c4e6c067d84fefd4
DIFF: https://github.com/llvm/llvm-project/commit/cd683bd32cecd97b9d9fd345c4e6c067d84fefd4.diff

LOG: [HipStdPar] Fix globle variable (#90627)

HipStdParAcceleratorCodeSelectionPass changes linkage of global
variables to extern_weak, which does not allow initializer.

An extern_weak global variable with initializer will cause llvm-as and
llc to fail.

Added: 
    llvm/test/Transforms/HipStdPar/global-var.ll

Modified: 
    llvm/lib/Transforms/HipStdPar/HipStdPar.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/HipStdPar/HipStdPar.cpp b/llvm/lib/Transforms/HipStdPar/HipStdPar.cpp
index fb7cba9edbdb8b..1a8096f647d847 100644
--- a/llvm/lib/Transforms/HipStdPar/HipStdPar.cpp
+++ b/llvm/lib/Transforms/HipStdPar/HipStdPar.cpp
@@ -133,6 +133,7 @@ static inline void maybeHandleGlobals(Module &M) {
       continue;
 
     G.setLinkage(GlobalVariable::ExternalWeakLinkage);
+    G.setInitializer(nullptr);
     G.setExternallyInitialized(true);
   }
 }

diff  --git a/llvm/test/Transforms/HipStdPar/global-var.ll b/llvm/test/Transforms/HipStdPar/global-var.ll
new file mode 100644
index 00000000000000..30340bd6c7ca06
--- /dev/null
+++ b/llvm/test/Transforms/HipStdPar/global-var.ll
@@ -0,0 +1,11 @@
+; RUN: opt -S -mtriple=amdgcn-amd-amdhsa -passes=hipstdpar-select-accelerator-code \
+; RUN: %s | FileCheck %s
+
+; CHECK: @var = extern_weak addrspace(1) externally_initialized global i32, align 4
+ at var = addrspace(1) global i32 0, align 4
+
+define amdgpu_kernel void @kernel() {
+entry:
+  store i32 1, ptr addrspace(1) @var, align 4
+  ret void
+}


        


More information about the llvm-commits mailing list