[llvm] [SPIR-V] Avoid typed pointers for global variables (PR #201203)
Akhil Goel via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 4 02:28:51 PDT 2026
https://github.com/akhilgoe updated https://github.com/llvm/llvm-project/pull/201203
>From e44f4c74dde33c0e346ed8cb8c58079f0c8c0eca Mon Sep 17 00:00:00 2001
From: Akhil Goel <akhil.goel at intel.com>
Date: Tue, 2 Jun 2026 14:10:59 -0700
Subject: [PATCH 1/2] Use opaque pointers for global vars
---
llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp | 2 ++
1 file changed, 2 insertions(+)
diff --git a/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp b/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp
index 343311fb44475..cf759d8d3ccd6 100644
--- a/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp
@@ -818,6 +818,8 @@ Register SPIRVGlobalRegistry::buildGlobalVariable(
GVar = M->getGlobalVariable(Name);
if (GVar == nullptr) {
const Type *Ty = getTypeForSPIRVType(BaseType); // TODO: check type.
+ if (auto *TPTy = dyn_cast<TypedPointerType>(Ty))
+ Ty = PointerType::get(M->getContext(), TPTy->getAddressSpace());
// Module takes ownership of the global var.
GVar = new GlobalVariable(*M, const_cast<Type *>(Ty), false,
GlobalValue::ExternalLinkage, nullptr,
>From fe64e830d98a2293f3e9dae23d59b263eba6facf Mon Sep 17 00:00:00 2001
From: Akhil Goel <akhil.goel at intel.com>
Date: Thu, 4 Jun 2026 02:32:17 -0700
Subject: [PATCH 2/2] Add test
---
.../CodeGen/SPIRV/pointers/global-vars-untyped.ll | 14 ++++++++++++++
1 file changed, 14 insertions(+)
create mode 100644 llvm/test/CodeGen/SPIRV/pointers/global-vars-untyped.ll
diff --git a/llvm/test/CodeGen/SPIRV/pointers/global-vars-untyped.ll b/llvm/test/CodeGen/SPIRV/pointers/global-vars-untyped.ll
new file mode 100644
index 0000000000000..fcf9581e4b648
--- /dev/null
+++ b/llvm/test/CodeGen/SPIRV/pointers/global-vars-untyped.ll
@@ -0,0 +1,14 @@
+; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv64-unknown-unknown %s -stop-after=irtranslator -o - | FileCheck %s
+; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown %s -o - -filetype=obj | spirv-val %}
+
+; CHECK: @__spirv_BuiltInLocalInvocationId = external addrspace(1) global ptr addrspace
+; CHECK: define spir_kernel void @func
+; CHECK-SAME: ptr addrspace(1) %{{.*}}
+
+define spir_kernel void @func(ptr addrspace(1) %arg) {
+entry:
+ %x = call spir_func i64 @_Z12get_local_idj(i32 0)
+ ret void
+}
+
+declare spir_func i64 @_Z12get_local_idj(i32)
More information about the llvm-commits
mailing list