Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[HipStdPar] Fix globle variable #90627

Merged
merged 1 commit into from
May 2, 2024
Merged

Conversation

yxsamliu
Copy link
Collaborator

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.

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.
@llvmbot
Copy link
Collaborator

llvmbot commented Apr 30, 2024

@llvm/pr-subscribers-llvm-transforms

Author: Yaxun (Sam) Liu (yxsamliu)

Changes

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 --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
+@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
+}

@gregrodgers
Copy link
Contributor

This fixed my problem. Thank you .

Copy link
Contributor

@AlexVlx AlexVlx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for looking into this.

@yxsamliu yxsamliu merged commit cd683bd into llvm:main May 2, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants