[clang] [llvm] [SPIR-V] Fixup storage class for global private (PR #116636)

Steven Perron via cfe-commits cfe-commits at lists.llvm.org
Fri Nov 29 08:01:47 PST 2024


================
@@ -0,0 +1,17 @@
+; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv64-unknown-unknown %s -o - | FileCheck %s
+; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown %s -o - -filetype=obj | spirv-val %}
+
+ at PrivInternal = internal addrspace(10) global i32 456
+; CHECK-DAG:  %[[#type:]] = OpTypeInt 32 0
+; CHECK-DAG: %[[#ptrty:]] = OpTypePointer Private %[[#type]]
+; CHECK-DAG: %[[#value:]] = OpConstant %[[#type]] 456
+; CHECK-DAG:   %[[#var:]] = OpVariable %[[#ptrty]] Private %[[#value]]
+
+define spir_kernel void @Foo() {
+  %p = addrspacecast ptr addrspace(10) @PrivInternal to ptr
----------------
s-perron wrote:

Where does this `addrsspacecast` come from? I would have expected the operand on the load to be `ptr addrspace(10) %p`.

I wonder because in SPIR-V the storage class matters. We cannot mix and match pointer from different storage classes. If we allow/generate address space casts generally, we could end up with problems.

In DXC, we were a little loose with storage classes in very specific situations, and we could do that because he have a pass in spirv-opt that will fix up those very specific situations. 

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


More information about the cfe-commits mailing list