1 ; RUN: llc -O0 -mtriple=spirv64-unknown-unknown %s -o - | FileCheck %s --check-prefixes=CHECK-SPIRV
2 ; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown %s -o - -filetype=obj | spirv-val %}
4 ; CHECK-SPIRV-DAG: %[[#Char:]] = OpTypeInt 8 0
5 ; CHECK-SPIRV-DAG: %[[#GlobalCharPtr:]] = OpTypePointer CrossWorkgroup %[[#Char]]
6 ; CHECK-SPIRV-DAG: %[[#LocalCharPtr:]] = OpTypePointer Workgroup %[[#Char]]
7 ; CHECK-SPIRV-DAG: %[[#PrivateCharPtr:]] = OpTypePointer Function %[[#Char]]
8 ; CHECK-SPIRV-DAG: %[[#GenericCharPtr:]] = OpTypePointer Generic %[[#Char]]
10 ; CHECK-SPIRV-DAG: %[[#Int:]] = OpTypeInt 32 0
11 ; CHECK-SPIRV-DAG: %[[#GlobalIntPtr:]] = OpTypePointer CrossWorkgroup %[[#Int]]
12 ; CHECK-SPIRV-DAG: %[[#PrivateIntPtr:]] = OpTypePointer Function %[[#Int]]
13 ; CHECK-SPIRV-DAG: %[[#GenericIntPtr:]] = OpTypePointer Generic %[[#Int]]
16 %arr = type { [1 x i64] }
18 @__spirv_BuiltInGlobalInvocationId = external local_unnamed_addr addrspace(1) constant <3 x i64>
22 ; CHECK-SPIRV: OpFunction
23 ; CHECK-SPIRV: OpPtrCastToGeneric %[[#GenericIntPtr]]
24 ; CHECK-SPIRV-NEXT: OpPtrCastToGeneric %[[#GenericCharPtr]]
25 ; CHECK-SPIRV-NEXT: OpPtrCastToGeneric %[[#GenericIntPtr]]
26 ; CHECK-SPIRV-NEXT: OpGenericCastToPtr %[[#GlobalIntPtr]]
27 ; CHECK-SPIRV-NEXT: OpGenericCastToPtr %[[#LocalCharPtr]]
28 ; CHECK-SPIRV-NEXT: OpGenericCastToPtr %[[#PrivateIntPtr]]
29 ; CHECK-SPIRV-NEXT: OpGenericCastToPtr %[[#GlobalIntPtr]]
30 ; CHECK-SPIRV-NEXT: OpGenericCastToPtr %[[#LocalCharPtr]]
31 ; CHECK-SPIRV-NEXT: OpGenericCastToPtr %[[#PrivateIntPtr]]
32 ; CHECK-SPIRV: OpFunctionEnd
34 define spir_kernel void @test1(ptr addrspace(1) %_arg_GlobalA, ptr byval(%id) %_arg_GlobalId, ptr addrspace(3) %_arg_LocalA) {
37 %p0 = load i64, ptr %_arg_GlobalId
38 %add = getelementptr inbounds i32, ptr addrspace(1) %_arg_GlobalA, i64 %p0
39 %p2 = load i64, ptr addrspace(1) @__spirv_BuiltInGlobalInvocationId
40 %idx = getelementptr inbounds i32, ptr addrspace(1) %add, i64 %p2
41 %var1 = addrspacecast ptr addrspace(1) %idx to ptr addrspace(4)
42 %var2 = addrspacecast ptr addrspace(3) %_arg_LocalA to ptr addrspace(4)
43 %var3 = addrspacecast ptr %var to ptr addrspace(4)
44 %G = call spir_func ptr addrspace(1) @_Z33__spirv_GenericCastToPtr_ToGlobalPvi(ptr addrspace(4) %var1, i32 5)
45 %L = call spir_func ptr addrspace(3) @_Z32__spirv_GenericCastToPtr_ToLocalPvi(ptr addrspace(4) %var2, i32 4)
46 %P = call spir_func ptr @_Z34__spirv_GenericCastToPtr_ToPrivatePvi(ptr addrspace(4) %var3, i32 7)
47 %GE = call spir_func ptr addrspace(1) @_Z41__spirv_GenericCastToPtrExplicit_ToGlobalPvi(ptr addrspace(4) %var1, i32 5)
48 %LE = call spir_func ptr addrspace(3) @_Z40__spirv_GenericCastToPtrExplicit_ToLocalPvi(ptr addrspace(4) %var2, i32 4)
49 %PE = call spir_func ptr @_Z42__spirv_GenericCastToPtrExplicit_ToPrivatePvi(ptr addrspace(4) %var3, i32 7)
53 ; CHECK-SPIRV: OpFunction
54 ; CHECK-SPIRV: OpPtrCastToGeneric %[[#GenericIntPtr]]
55 ; CHECK-SPIRV-NEXT: OpPtrCastToGeneric %[[#GenericCharPtr]]
56 ; CHECK-SPIRV-NEXT: OpPtrCastToGeneric %[[#GenericIntPtr]]
57 ; CHECK-SPIRV-NEXT: OpGenericCastToPtr %[[#GlobalIntPtr]]
58 ; CHECK-SPIRV-NEXT: OpGenericCastToPtr %[[#LocalCharPtr]]
59 ; CHECK-SPIRV-NEXT: OpGenericCastToPtr %[[#PrivateIntPtr]]
60 ; CHECK-SPIRV: OpFunctionEnd
62 define spir_kernel void @test2(ptr addrspace(1) %_arg_GlobalA, ptr byval(%id) %_arg_GlobalId, ptr addrspace(3) %_arg_LocalA) {
65 %p0 = load i64, ptr %_arg_GlobalId
66 %add = getelementptr inbounds i32, ptr addrspace(1) %_arg_GlobalA, i64 %p0
67 %p2 = load i64, ptr addrspace(1) @__spirv_BuiltInGlobalInvocationId
68 %idx = getelementptr inbounds i32, ptr addrspace(1) %add, i64 %p2
69 %var1 = addrspacecast ptr addrspace(1) %idx to ptr addrspace(4)
70 %var2 = addrspacecast ptr addrspace(3) %_arg_LocalA to ptr addrspace(4)
71 %var3 = addrspacecast ptr %var to ptr addrspace(4)
72 %G = call spir_func ptr addrspace(1) @_Z9to_globalPv(ptr addrspace(4) %var1)
73 %L = call spir_func ptr addrspace(3) @_Z8to_localPv(ptr addrspace(4) %var2)
74 %P = call spir_func ptr @_Z10to_privatePv(ptr addrspace(4) %var3)
78 declare spir_func ptr addrspace(1) @_Z33__spirv_GenericCastToPtr_ToGlobalPvi(ptr addrspace(4), i32)
79 declare spir_func ptr addrspace(3) @_Z32__spirv_GenericCastToPtr_ToLocalPvi(ptr addrspace(4), i32)
80 declare spir_func ptr @_Z34__spirv_GenericCastToPtr_ToPrivatePvi(ptr addrspace(4), i32)
81 declare spir_func ptr addrspace(1) @_Z41__spirv_GenericCastToPtrExplicit_ToGlobalPvi(ptr addrspace(4), i32)
82 declare spir_func ptr addrspace(3) @_Z40__spirv_GenericCastToPtrExplicit_ToLocalPvi(ptr addrspace(4), i32)
83 declare spir_func ptr @_Z42__spirv_GenericCastToPtrExplicit_ToPrivatePvi(ptr addrspace(4), i32)
85 declare spir_func ptr addrspace(1) @_Z9to_globalPv(ptr addrspace(4))
86 declare spir_func ptr addrspace(3) @_Z8to_localPv(ptr addrspace(4))
87 declare spir_func ptr @_Z10to_privatePv(ptr addrspace(4))
91 ; CHECK-SPIRV: OpFunction
92 ; CHECK-SPIRV: OpPtrCastToGeneric %[[#GenericIntPtr]]
93 ; CHECK-SPIRV-NEXT: OpPtrCastToGeneric %[[#GenericCharPtr]]
94 ; CHECK-SPIRV-NEXT: OpPtrCastToGeneric %[[#GenericIntPtr]]
95 ; CHECK-SPIRV-NEXT: OpGenericCastToPtr %[[#GlobalIntPtr]]
96 ; CHECK-SPIRV-NEXT: OpGenericCastToPtr %[[#LocalCharPtr]]
97 ; CHECK-SPIRV-NEXT: OpGenericCastToPtr %[[#PrivateIntPtr]]
98 ; CHECK-SPIRV-NEXT: OpGenericCastToPtr %[[#GlobalIntPtr]]
99 ; CHECK-SPIRV-NEXT: OpGenericCastToPtr %[[#LocalCharPtr]]
100 ; CHECK-SPIRV-NEXT: OpGenericCastToPtr %[[#PrivateIntPtr]]
101 ; CHECK-SPIRV: OpFunctionEnd
103 ; CHECK-SPIRV: OpFunction
104 ; CHECK-SPIRV: OpPtrCastToGeneric %[[#GenericIntPtr]]
105 ; CHECK-SPIRV-NEXT: OpPtrCastToGeneric %[[#GenericCharPtr]]
106 ; CHECK-SPIRV-NEXT: OpPtrCastToGeneric %[[#GenericIntPtr]]
107 ; CHECK-SPIRV-NEXT: OpGenericCastToPtr %[[#GlobalIntPtr]]
108 ; CHECK-SPIRV-NEXT: OpGenericCastToPtr %[[#LocalCharPtr]]
109 ; CHECK-SPIRV-NEXT: OpGenericCastToPtr %[[#PrivateIntPtr]]
110 ; CHECK-SPIRV: OpFunctionEnd
112 define spir_kernel void @test3(ptr addrspace(1) %_arg_GlobalA, ptr byval(%id) %_arg_GlobalId, ptr addrspace(3) %_arg_LocalA) {
115 %p0 = load i64, ptr %_arg_GlobalId
116 %add = getelementptr inbounds i32, ptr addrspace(1) %_arg_GlobalA, i64 %p0
117 %p2 = load i64, ptr addrspace(1) @__spirv_BuiltInGlobalInvocationId
118 %idx = getelementptr inbounds i32, ptr addrspace(1) %add, i64 %p2
119 %var1 = addrspacecast ptr addrspace(1) %idx to ptr addrspace(4)
120 %var2 = addrspacecast ptr addrspace(3) %_arg_LocalA to ptr addrspace(4)
121 %var3 = addrspacecast ptr %var to ptr addrspace(4)
122 %G = call spir_func ptr addrspace(1) @__spirv_GenericCastToPtr_ToGlobal(ptr addrspace(4) %var1, i32 5)
123 %L = call spir_func ptr addrspace(3) @__spirv_GenericCastToPtr_ToLocal(ptr addrspace(4) %var2, i32 4)
124 %P = call spir_func ptr @__spirv_GenericCastToPtr_ToPrivate(ptr addrspace(4) %var3, i32 7)
125 %GE = call spir_func ptr addrspace(1) @__spirv_GenericCastToPtrExplicit_ToGlobal(ptr addrspace(4) %var1, i32 5)
126 %LE = call spir_func ptr addrspace(3) @__spirv_GenericCastToPtrExplicit_ToLocal(ptr addrspace(4) %var2, i32 4)
127 %PE = call spir_func ptr @__spirv_GenericCastToPtrExplicit_ToPrivate(ptr addrspace(4) %var3, i32 7)
131 define spir_kernel void @test4(ptr addrspace(1) %_arg_GlobalA, ptr byval(%id) %_arg_GlobalId, ptr addrspace(3) %_arg_LocalA) {
134 %p0 = load i64, ptr %_arg_GlobalId
135 %add = getelementptr inbounds i32, ptr addrspace(1) %_arg_GlobalA, i64 %p0
136 %p2 = load i64, ptr addrspace(1) @__spirv_BuiltInGlobalInvocationId
137 %idx = getelementptr inbounds i32, ptr addrspace(1) %add, i64 %p2
138 %var1 = addrspacecast ptr addrspace(1) %idx to ptr addrspace(4)
139 %var2 = addrspacecast ptr addrspace(3) %_arg_LocalA to ptr addrspace(4)
140 %var3 = addrspacecast ptr %var to ptr addrspace(4)
141 %G = call spir_func ptr addrspace(1) @to_global(ptr addrspace(4) %var1)
142 %L = call spir_func ptr addrspace(3) @to_local(ptr addrspace(4) %var2)
143 %P = call spir_func ptr @to_private(ptr addrspace(4) %var3)
147 declare spir_func ptr addrspace(1) @__spirv_GenericCastToPtr_ToGlobal(ptr addrspace(4), i32)
148 declare spir_func ptr addrspace(3) @__spirv_GenericCastToPtr_ToLocal(ptr addrspace(4), i32)
149 declare spir_func ptr @__spirv_GenericCastToPtr_ToPrivate(ptr addrspace(4), i32)
150 declare spir_func ptr addrspace(1) @__spirv_GenericCastToPtrExplicit_ToGlobal(ptr addrspace(4), i32)
151 declare spir_func ptr addrspace(3) @__spirv_GenericCastToPtrExplicit_ToLocal(ptr addrspace(4), i32)
152 declare spir_func ptr @__spirv_GenericCastToPtrExplicit_ToPrivate(ptr addrspace(4), i32)
154 declare spir_func ptr addrspace(1) @to_global(ptr addrspace(4))
155 declare spir_func ptr addrspace(3) @to_local(ptr addrspace(4))
156 declare spir_func ptr @to_private(ptr addrspace(4))