1 ; RUN: llc -O0 -mtriple=spirv64-unknown-unknown %s -o - | FileCheck %s --check-prefixes=CHECK-SPIRV,CHECK-SPIRV64
2 ; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown %s -o - -filetype=obj | spirv-val %}
4 ; RUN: llc -O0 -mtriple=spirv32-unknown-unknown %s -o - | FileCheck %s --check-prefixes=CHECK-SPIRV,CHECK-SPIRV32
5 ; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv32-unknown-unknown %s -o - -filetype=obj | spirv-val %}
7 ; CHECK-SPIRV: OpName %[[#Var:]] "var"
8 ; CHECK-SPIRV: OpName %[[#GVar:]] "g_var"
9 ; CHECK-SPIRV: OpName %[[#AVar:]] "a_var"
10 ; CHECK-SPIRV: OpName %[[#PVar:]] "p_var"
12 ; CHECK-SPIRV-DAG: %[[#CharTy:]] = OpTypeInt 8 0
13 ; CHECK-SPIRV-DAG: %[[#IntTy:]] = OpTypeInt 32 0
14 ; CHECK-SPIRV-DAG: %[[#V2CharTy:]] = OpTypeVector %[[#CharTy]] 2
15 ; CHECK-SPIRV-DAG: %[[#V2ConstNull:]] = OpConstantNull %[[#V2CharTy]]
16 ; CHECK-SPIRV-DAG: %[[#Const1:]] = OpConstant %[[#CharTy]] 1
17 ; CHECK-SPIRV-DAG: %[[#Const2:]] = OpConstant %[[#IntTy]] 2
18 ; CHECK-SPIRV-DAG: %[[#Arr2V2CharTy:]] = OpTypeArray %[[#V2CharTy]] %[[#Const2]]
19 ; CHECK-SPIRV-DAG: %[[#LongTy:]] = OpTypeInt 64 0
20 ; CHECK-SPIRV-DAG: %[[#PtrV2CharTy:]] = OpTypePointer CrossWorkgroup %[[#V2CharTy]]
21 ; CHECK-SPIRV-DAG: %[[#V2Char1:]] = OpConstantComposite %[[#V2CharTy]] %[[#Const1]] %[[#Const1]]
22 ; CHECK-SPIRV-DAG: %[[#Arr2V2Char:]] = OpConstantComposite %[[#Arr2V2CharTy]] %[[#V2Char1]] %[[#V2Char1]]
23 ; CHECK-SPIRV-DAG: %[[#PtrCharTy:]] = OpTypePointer CrossWorkgroup %[[#CharTy]]
24 ; CHECK-SPIRV-DAG: %[[#PtrArr2V2CharTy:]] = OpTypePointer CrossWorkgroup %[[#Arr2V2CharTy]]
25 ; CHECK-SPIRV-DAG: %[[#IntZero:]] = OpConstantNull %[[#IntTy]]
26 ; CHECK-SPIRV-DAG: %[[#LongZero:]] = OpConstantNull %[[#LongTy]]
27 ; CHECK-SPIRV64-DAG: %[[#ConstLong2:]] = OpConstant %[[#LongTy]] 2
28 ; CHECK-SPIRV64-DAG: %[[#PvarInit:]] = OpSpecConstantOp %[[#PtrCharTy]] 70 %[[#VarV2Char:]] %[[#IntZero]] %[[#ConstLong2]]
29 ; CHECK-SPIRV32-DAG: %[[#PvarInit:]] = OpSpecConstantOp %[[#PtrCharTy]] 70 %[[#VarV2Char:]] %[[#IntZero]] %[[#Const2]]
30 ; CHECK-SPIRV-DAG: %[[#PtrPtrCharTy:]] = OpTypePointer CrossWorkgroup %[[#PtrCharTy]]
31 ; CHECK-SPIRV-DAG: %[[#AVar]] = OpVariable %[[#PtrArr2V2CharTy]] CrossWorkgroup %[[#Arr2V2Char]]
32 ; CHECK-SPIRV-DAG: %[[#PVar]] = OpVariable %[[#PtrPtrCharTy]] CrossWorkgroup %[[#PvarInit]]
33 ; CHECK-SPIRV-DAG: %[[#GVar]] = OpVariable %[[#PtrV2CharTy]] CrossWorkgroup %[[#V2Char1]]
34 ; CHECK-SPIRV-DAG: %[[#]] = OpVariable %[[#PtrV2CharTy]] CrossWorkgroup %[[#V2ConstNull]]
36 ; As an option: %[[#Const0:]] = OpConstant %[[#CharTy]] 0
37 ; %[[#V2CharZero:]] = OpConstantComposite %[[#V2CharTy]] %[[#Const0]] %[[#Const0]]
38 ; %[[#]] = OpVariable %[[#PtrV2CharTy]] CrossWorkgroup %[[#V2CharZero]]
40 @var = addrspace(1) global <2 x i8> zeroinitializer, align 2
41 @g_var = addrspace(1) global <2 x i8> <i8 1, i8 1>, align 2
42 @a_var = addrspace(1) global [2 x <2 x i8>] [<2 x i8> <i8 1, i8 1>, <2 x i8> <i8 1, i8 1>], align 2
43 @p_var = addrspace(1) global ptr addrspace(1) getelementptr (i8, ptr addrspace(1) @a_var, i64 2), align 8
45 define spir_func <2 x i8> @from_buf(<2 x i8> %a) #0 {
50 define spir_func <2 x i8> @to_buf(<2 x i8> %a) #0 {
55 define spir_kernel void @writer(ptr addrspace(1) %src, i32 %idx) #0 !kernel_arg_addr_space !5 !kernel_arg_access_qual !6 !kernel_arg_type !7 !kernel_arg_type_qual !8 !kernel_arg_base_type !7 !spirv.ParameterDecorations !9 {
57 %arrayidx = getelementptr inbounds <2 x i8>, ptr addrspace(1) %src, i64 0
58 %0 = load <2 x i8>, ptr addrspace(1) %arrayidx, align 2
59 %call = call spir_func <2 x i8> @from_buf(<2 x i8> %0) #0
60 store <2 x i8> %call, ptr addrspace(1) @var, align 2
61 %arrayidx1 = getelementptr inbounds <2 x i8>, ptr addrspace(1) %src, i64 1
62 %1 = load <2 x i8>, ptr addrspace(1) %arrayidx1, align 2
63 %call2 = call spir_func <2 x i8> @from_buf(<2 x i8> %1) #0
64 store <2 x i8> %call2, ptr addrspace(1) @g_var, align 2
65 %arrayidx3 = getelementptr inbounds <2 x i8>, ptr addrspace(1) %src, i64 2
66 %2 = load <2 x i8>, ptr addrspace(1) %arrayidx3, align 2
67 %call4 = call spir_func <2 x i8> @from_buf(<2 x i8> %2) #0
68 %3 = getelementptr inbounds [2 x <2 x i8>], ptr addrspace(1) @a_var, i64 0, i64 0
69 store <2 x i8> %call4, ptr addrspace(1) %3, align 2
70 %arrayidx5 = getelementptr inbounds <2 x i8>, ptr addrspace(1) %src, i64 3
71 %4 = load <2 x i8>, ptr addrspace(1) %arrayidx5, align 2
72 %call6 = call spir_func <2 x i8> @from_buf(<2 x i8> %4) #0
73 %5 = getelementptr inbounds [2 x <2 x i8>], ptr addrspace(1) @a_var, i64 0, i64 1
74 store <2 x i8> %call6, ptr addrspace(1) %5, align 2
75 %idx.ext = zext i32 %idx to i64
76 %add.ptr = getelementptr inbounds <2 x i8>, ptr addrspace(1) %3, i64 %idx.ext
77 store ptr addrspace(1) %add.ptr, ptr addrspace(1) @p_var, align 8
81 define spir_kernel void @reader(ptr addrspace(1) %dest, <2 x i8> %ptr_write_val) #0 !kernel_arg_addr_space !5 !kernel_arg_access_qual !6 !kernel_arg_type !10 !kernel_arg_type_qual !8 !kernel_arg_base_type !10 !spirv.ParameterDecorations !9 {
83 %call = call spir_func <2 x i8> @from_buf(<2 x i8> %ptr_write_val) #0
84 %0 = load ptr addrspace(1), ptr addrspace(1) @p_var, align 8
85 store volatile <2 x i8> %call, ptr addrspace(1) %0, align 2
86 %1 = load <2 x i8>, ptr addrspace(1) @var, align 2
87 %call1 = call spir_func <2 x i8> @to_buf(<2 x i8> %1) #0
88 %arrayidx = getelementptr inbounds <2 x i8>, ptr addrspace(1) %dest, i64 0
89 store <2 x i8> %call1, ptr addrspace(1) %arrayidx, align 2
90 %2 = load <2 x i8>, ptr addrspace(1) @g_var, align 2
91 %call2 = call spir_func <2 x i8> @to_buf(<2 x i8> %2) #0
92 %arrayidx3 = getelementptr inbounds <2 x i8>, ptr addrspace(1) %dest, i64 1
93 store <2 x i8> %call2, ptr addrspace(1) %arrayidx3, align 2
94 %3 = getelementptr inbounds [2 x <2 x i8>], ptr addrspace(1) @a_var, i64 0, i64 0
95 %4 = load <2 x i8>, ptr addrspace(1) %3, align 2
96 %call4 = call spir_func <2 x i8> @to_buf(<2 x i8> %4) #0
97 %arrayidx5 = getelementptr inbounds <2 x i8>, ptr addrspace(1) %dest, i64 2
98 store <2 x i8> %call4, ptr addrspace(1) %arrayidx5, align 2
99 %5 = getelementptr inbounds [2 x <2 x i8>], ptr addrspace(1) @a_var, i64 0, i64 1
100 %6 = load <2 x i8>, ptr addrspace(1) %5, align 2
101 %call6 = call spir_func <2 x i8> @to_buf(<2 x i8> %6) #0
102 %arrayidx7 = getelementptr inbounds <2 x i8>, ptr addrspace(1) %dest, i64 3
103 store <2 x i8> %call6, ptr addrspace(1) %arrayidx7, align 2
107 attributes #0 = { nounwind }
109 !spirv.MemoryModel = !{!0}
110 !opencl.enable.FP_CONTRACT = !{}
111 !spirv.Source = !{!1}
112 !opencl.spir.version = !{!2}
113 !opencl.ocl.version = !{!2}
114 !opencl.used.extensions = !{!3}
115 !opencl.used.optional.core.features = !{!3}
116 !spirv.Generator = !{!4}
119 !1 = !{i32 3, i32 200000}
122 !4 = !{i16 6, i16 14}
124 !6 = !{!"none", !"none"}
125 !7 = !{!"char2*", !"int"}
128 !10 = !{!"char2*", !"char2"}