[llvm] [HipStdPar] Fix globle variable (PR #90627)

via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 30 09:58:11 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-transforms

Author: Yaxun (Sam) Liu (yxsamliu)

<details>
<summary>Changes</summary>

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.

---
Full diff: https://github.com/llvm/llvm-project/pull/90627.diff


2 Files Affected:

- (modified) llvm/lib/Transforms/HipStdPar/HipStdPar.cpp (+1) 
- (added) llvm/test/Transforms/HipStdPar/global-var.ll (+11) 


``````````diff
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
+}

``````````

</details>


https://github.com/llvm/llvm-project/pull/90627


More information about the llvm-commits mailing list