[llvm] [SPIR-V] Fix wrong element inferred for long vectors when using ByteAdressBuffer (PR #222220)

Justin Bogner via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 16 10:06:10 PDT 2026


================
@@ -0,0 +1,37 @@
+; RUN: llc -O0 -mtriple=spirv-unknown-vulkan-compute %s -o - | FileCheck %s
+; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv-unknown-vulkan-compute %s -o - -filetype=obj | spirv-val --target-env vulkan1.3 %}
+
+; CHECK-DAG: %[[GLSLEXT:[0-9]+]] = OpExtInstImport "GLSL.std.450"
+; CHECK-DAG: %[[FLOAT:[0-9]+]] = OpTypeFloat 32
+; CHECK-DAG: %[[V4FLOAT:[0-9]+]] = OpTypeVector %[[FLOAT]] 4
+; CHECK: OpBitcast %[[FLOAT]]
+; CHECK-COUNT-4: OpCompositeConstruct %[[V4FLOAT]]
+; CHECK-COUNT-4: OpExtInst %[[V4FLOAT]] %[[GLSLEXT]] {{Cosh}}
+
+
+ at .str = private unnamed_addr constant [4 x i8] c"In0\00", align 1
+ at .str.2 = private unnamed_addr constant [4 x i8] c"Out\00", align 1
+
+declare token @llvm.experimental.convergence.entry()
+
+define void @main() local_unnamed_addr #0 {
+entry:
+  %convergence = tail call token @llvm.experimental.convergence.entry()
+  %input = tail call target("spirv.VulkanBuffer", [0 x i8], 12, 0) @llvm.spv.resource.handlefrombinding.t0(i32 0, i32 0, i32 1, i32 0, ptr nonnull @.str)
+  %output = tail call target("spirv.VulkanBuffer", [0 x i8], 12, 1) @llvm.spv.resource.handlefrombinding.t1(i32 0, i32 1, i32 1, i32 0, ptr nonnull @.str.2)
+  %input.ptr = call ptr addrspace(11) @llvm.spv.resource.getpointer.t0(target("spirv.VulkanBuffer", [0 x i8], 12, 0) %input, i32 0) [ "convergencectrl"(token %convergence) ]
+  %value = load <16 x float>, ptr addrspace(11) %input.ptr, align 4
+  %result = tail call <16 x float> @llvm.cosh.v16f32(<16 x float> %value)
+  %output.ptr = call ptr addrspace(11) @llvm.spv.resource.getpointer.t1(target("spirv.VulkanBuffer", [0 x i8], 12, 1) %output, i32 0) [ "convergencectrl"(token %convergence) ]
+  store <16 x float> %result, ptr addrspace(11) %output.ptr, align 4
+  ret void
+}
+
+declare <16 x float> @llvm.cosh.v16f32(<16 x float>)
+
+declare target("spirv.VulkanBuffer", [0 x i8], 12, 0) @llvm.spv.resource.handlefrombinding.t0(i32, i32, i32, i32, ptr)
+declare target("spirv.VulkanBuffer", [0 x i8], 12, 1) @llvm.spv.resource.handlefrombinding.t1(i32, i32, i32, i32, ptr)
+declare ptr addrspace(11) @llvm.spv.resource.getpointer.t0(target("spirv.VulkanBuffer", [0 x i8], 12, 0), i32)
+declare ptr addrspace(11) @llvm.spv.resource.getpointer.t1(target("spirv.VulkanBuffer", [0 x i8], 12, 1), i32)
----------------
bogner wrote:

The parser cleans it all up for you so it doesn't matter _too much_, but if we're going to declare these manually we really should:
1. Use the actual mangling
2. Use the correct function attributes

For example, if you run this through opt and look at one of the `handlefrombinding` declarations:
```llvm
declare target("spirv.VulkanBuffer", [0 x i8], 12, 0) @llvm.spv.resource.handlefrombinding.tspirv.VulkanBuffer_a0i8_12_0t(i32, i32, i32, i32, ptr) #3
...
attributes #3 = { nocallback nofree nosync nounwind willreturn memory(none) }
```

Similarly, `cosh` has a bunch of attributes.

The better alternative is to omit the `declare`s entirely, and just use the unsuffixed function names, `@llvm.cosh(...)`, `@llvm.spv.resource.handlefrombinding(...)`, and `@llvm.spv.resource.getpointer(...)`. The custom mangling with `.t0` and `.t1` is more confusing than its worth.

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


More information about the llvm-commits mailing list