Debian Codegraph @

llvm/test/CodeGen/SPIRV/pointers/resource-addrspacecast-2.ll

raw
1 ; RUN: llc -verify-machineinstrs -O3 -mtriple=spirv-unknown-vulkan1.3-compute %s -o - | FileCheck %s --match-full-lines
2 ; RUN: %if spirv-tools %{ llc -O3 -mtriple=spirv-unknown-vulkan1.3-compute %s -o - -filetype=obj | spirv-val %}
3
4 @.str = private unnamed_addr constant [3 x i8] c"B0\00", align 1
5
6 %S2 = type { { [10 x { i32, i32 } ] }, i32 }
7
8 ; CHECK-DAG: %[[#uint:]] = OpTypeInt 32 0
9 ; CHECK-DAG: %[[#uint_0:]] = OpConstant %[[#uint]] 0
10 ; CHECK-DAG: %[[#uint_1:]] = OpConstant %[[#uint]] 1
11 ; CHECK-DAG: %[[#uint_3:]] = OpConstant %[[#uint]] 3
12 ; CHECK-DAG: %[[#uint_10:]] = OpConstant %[[#uint]] 10
13 ; CHECK-DAG: %[[#uint_11:]] = OpConstant %[[#uint]] 11
14 ; CHECK-DAG: %[[#ptr_StorageBuffer_uint:]] = OpTypePointer StorageBuffer %[[#uint]]
15
16 ; CHECK-DAG: %[[#t_s2_s_a_s:]] = OpTypeStruct %[[#uint]] %[[#uint]]
17 ; CHECK-DAG: %[[#t_s2_s_a:]] = OpTypeArray %[[#t_s2_s_a_s]] %[[#uint_10]]
18 ; CHECK-DAG: %[[#t_s2_s:]] = OpTypeStruct %[[#t_s2_s_a]]
19 ; CHECK-DAG: %[[#t_s2:]] = OpTypeStruct %[[#t_s2_s]] %[[#uint]]
20
21 ; CHECK-DAG: %[[#ptr_StorageBuffer_struct:]] = OpTypePointer StorageBuffer %[[#t_s2]]
22 ; CHECK-DAG: %[[#rarr:]] = OpTypeRuntimeArray %[[#t_s2]]
23 ; CHECK-DAG: %[[#rarr_struct:]] = OpTypeStruct %[[#rarr]]
24 ; CHECK-DAG: %[[#spirv_VulkanBuffer:]] = OpTypePointer StorageBuffer %[[#rarr_struct]]
25
26 define void @main() "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" {
27 entry:
28 %handle = tail call target("spirv.VulkanBuffer", [0 x %S2], 12, 1) @llvm.spv.resource.handlefrombinding.tspirv.VulkanBuffer_a0s_Ss_12_1t(i32 0, i32 0, i32 1, i32 0, ptr nonnull @.str)
29 ; CHECK: %[[#resource:]] = OpVariable %[[#spirv_VulkanBuffer]] StorageBuffer
30
31 %ptr = tail call noundef align 4 dereferenceable(4) ptr addrspace(11) @llvm.spv.resource.getpointer.p11.tspirv.VulkanBuffer_a0s_Ss_12_1t(target("spirv.VulkanBuffer", [0 x %S2], 12, 1) %handle, i32 0)
32 ; CHECK: %[[#a:]] = OpCopyObject %[[#spirv_VulkanBuffer]] %[[#resource]]
33 ; CHECK: %[[#b:]] = OpAccessChain %[[#ptr_StorageBuffer_struct]] %[[#a:]] %[[#uint_0]] %[[#uint_0]]
34 %casted = addrspacecast ptr addrspace(11) %ptr to ptr
35
36 ; CHECK: %[[#ptr2:]] = OpInBoundsAccessChain %[[#ptr_StorageBuffer_uint]] %[[#b:]] %[[#uint_0]] %[[#uint_0]] %[[#uint_3]] %[[#uint_1]]
37 %ptr2 = getelementptr inbounds %S2, ptr %casted, i64 0, i32 0, i32 0, i32 3, i32 1
38
39 ; CHECK: OpStore %[[#ptr2]] %[[#uint_10]] Aligned 4
40 store i32 10, ptr %ptr2, align 4
41
42 ; Another store, but this time using LLVM's ability to load the first element
43 ; without an explicit GEP. The backend has to determine the ptr type and
44 ; generate the appropriate access chain.
45 ; CHECK: %[[#ptr3:]] = OpInBoundsAccessChain %[[#ptr_StorageBuffer_uint]] %[[#b:]] %[[#uint_0]] %[[#uint_0]] %[[#uint_0]] %[[#uint_0]]
46 ; CHECK: OpStore %[[#ptr3]] %[[#uint_11]] Aligned 4
47 store i32 11, ptr %casted, align 4
48 ret void
49 }
50
51 declare ptr addrspace(11) @llvm.spv.resource.getpointer.p11.tspirv.VulkanBuffer_a0s_S2s_12_1t(target("spirv.VulkanBuffer", [0 x %S2], 12, 1), i32)