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: %[[#LocalCharPtr:]] = OpTypePointer Workgroup %[[#Char]]
6 ; CHECK-SPIRV-DAG: %[[#GenericCharPtr:]] = OpTypePointer Generic %[[#Char]]
8 ; CHECK-SPIRV-DAG: %[[#Int:]] = OpTypeInt 32 0
9 ; CHECK-SPIRV-DAG: %[[#GlobalIntPtr:]] = OpTypePointer CrossWorkgroup %[[#Int]]
10 ; CHECK-SPIRV-DAG: %[[#PrivateIntPtr:]] = OpTypePointer Function %[[#Int]]
11 ; CHECK-SPIRV-DAG: %[[#GenericIntPtr:]] = OpTypePointer Generic %[[#Int]]
14 %arr = type { [1 x i64] }
16 @__spirv_BuiltInGlobalInvocationId = external local_unnamed_addr addrspace(1) constant <3 x i64>
20 ; CHECK-SPIRV: OpFunction
21 ; CHECK-SPIRV: OpPtrCastToGeneric %[[#GenericIntPtr]]
22 ; CHECK-SPIRV-NEXT: OpPtrCastToGeneric %[[#GenericCharPtr]]
23 ; CHECK-SPIRV-NEXT: OpPtrCastToGeneric %[[#GenericIntPtr]]
24 ; CHECK-SPIRV-NEXT: OpGenericCastToPtr %[[#GlobalIntPtr]]
25 ; CHECK-SPIRV-NEXT: OpGenericCastToPtr %[[#LocalCharPtr]]
26 ; CHECK-SPIRV-NEXT: OpGenericCastToPtr %[[#PrivateIntPtr]]
27 ; CHECK-SPIRV-NEXT: OpGenericCastToPtr %[[#GlobalIntPtr]]
28 ; CHECK-SPIRV-NEXT: OpGenericCastToPtr %[[#LocalCharPtr]]
29 ; CHECK-SPIRV-NEXT: OpGenericCastToPtr %[[#PrivateIntPtr]]
30 ; CHECK-SPIRV: OpFunctionEnd
32 define spir_kernel void @test1(ptr addrspace(1) %_arg_GlobalA, ptr byval(%id) %_arg_GlobalId, ptr addrspace(3) %_arg_LocalA) {
35 %p0 = load i64, ptr %_arg_GlobalId
36 %add = getelementptr inbounds i32, ptr addrspace(1) %_arg_GlobalA, i64 %p0
37 %p2 = load i64, ptr addrspace(1) @__spirv_BuiltInGlobalInvocationId
38 %idx = getelementptr inbounds i32, ptr addrspace(1) %add, i64 %p2
39 %var1 = addrspacecast ptr addrspace(1) %idx to ptr addrspace(4)
40 %var2 = addrspacecast ptr addrspace(3) %_arg_LocalA to ptr addrspace(4)
41 %var3 = addrspacecast ptr %var to ptr addrspace(4)
42 %G = call spir_func ptr addrspace(1) @_Z33__spirv_GenericCastToPtr_ToGlobalPvi(ptr addrspace(4) %var1, i32 5)
43 %L = call spir_func ptr addrspace(3) @_Z32__spirv_GenericCastToPtr_ToLocalPvi(ptr addrspace(4) %var2, i32 4)
44 %P = call spir_func ptr @_Z34__spirv_GenericCastToPtr_ToPrivatePvi(ptr addrspace(4) %var3, i32 7)
45 %GE = call spir_func ptr addrspace(1) @_Z41__spirv_GenericCastToPtrExplicit_ToGlobalPvi(ptr addrspace(4) %var1, i32 5)
46 %LE = call spir_func ptr addrspace(3) @_Z40__spirv_GenericCastToPtrExplicit_ToLocalPvi(ptr addrspace(4) %var2, i32 4)
47 %PE = call spir_func ptr @_Z42__spirv_GenericCastToPtrExplicit_ToPrivatePvi(ptr addrspace(4) %var3, i32 7)
51 ; CHECK-SPIRV: OpFunction
52 ; CHECK-SPIRV: OpPtrCastToGeneric %[[#GenericIntPtr]]
53 ; CHECK-SPIRV-NEXT: OpPtrCastToGeneric %[[#GenericCharPtr]]
54 ; CHECK-SPIRV-NEXT: OpPtrCastToGeneric %[[#GenericIntPtr]]
55 ; CHECK-SPIRV-NEXT: OpGenericCastToPtr %[[#GlobalIntPtr]]
56 ; CHECK-SPIRV-NEXT: OpGenericCastToPtr %[[#LocalCharPtr]]
57 ; CHECK-SPIRV-NEXT: OpGenericCastToPtr %[[#PrivateIntPtr]]
58 ; CHECK-SPIRV: OpFunctionEnd
60 define spir_kernel void @test2(ptr addrspace(1) %_arg_GlobalA, ptr byval(%id) %_arg_GlobalId, ptr addrspace(3) %_arg_LocalA) {
63 %p0 = load i64, ptr %_arg_GlobalId
64 %add = getelementptr inbounds i32, ptr addrspace(1) %_arg_GlobalA, i64 %p0
65 %p2 = load i64, ptr addrspace(1) @__spirv_BuiltInGlobalInvocationId
66 %idx = getelementptr inbounds i32, ptr addrspace(1) %add, i64 %p2
67 %var1 = addrspacecast ptr addrspace(1) %idx to ptr addrspace(4)
68 %var2 = addrspacecast ptr addrspace(3) %_arg_LocalA to ptr addrspace(4)
69 %var3 = addrspacecast ptr %var to ptr addrspace(4)
70 %G = call spir_func ptr addrspace(1) @_Z9to_globalPv(ptr addrspace(4) %var1)
71 %L = call spir_func ptr addrspace(3) @_Z8to_localPv(ptr addrspace(4) %var2)
72 %P = call spir_func ptr @_Z10to_privatePv(ptr addrspace(4) %var3)
76 declare spir_func ptr addrspace(1) @_Z33__spirv_GenericCastToPtr_ToGlobalPvi(ptr addrspace(4), i32)
77 declare spir_func ptr addrspace(3) @_Z32__spirv_GenericCastToPtr_ToLocalPvi(ptr addrspace(4), i32)
78 declare spir_func ptr @_Z34__spirv_GenericCastToPtr_ToPrivatePvi(ptr addrspace(4), i32)
79 declare spir_func ptr addrspace(1) @_Z41__spirv_GenericCastToPtrExplicit_ToGlobalPvi(ptr addrspace(4), i32)
80 declare spir_func ptr addrspace(3) @_Z40__spirv_GenericCastToPtrExplicit_ToLocalPvi(ptr addrspace(4), i32)
81 declare spir_func ptr @_Z42__spirv_GenericCastToPtrExplicit_ToPrivatePvi(ptr addrspace(4), i32)
83 declare spir_func ptr addrspace(1) @_Z9to_globalPv(ptr addrspace(4))
84 declare spir_func ptr addrspace(3) @_Z8to_localPv(ptr addrspace(4))
85 declare spir_func ptr @_Z10to_privatePv(ptr addrspace(4))
89 ; CHECK-SPIRV: OpFunction
90 ; CHECK-SPIRV: OpPtrCastToGeneric %[[#GenericIntPtr]]
91 ; CHECK-SPIRV-NEXT: OpPtrCastToGeneric %[[#GenericCharPtr]]
92 ; CHECK-SPIRV-NEXT: OpPtrCastToGeneric %[[#GenericIntPtr]]
93 ; CHECK-SPIRV-NEXT: OpGenericCastToPtr %[[#GlobalIntPtr]]
94 ; CHECK-SPIRV-NEXT: OpGenericCastToPtr %[[#LocalCharPtr]]
95 ; CHECK-SPIRV-NEXT: OpGenericCastToPtr %[[#PrivateIntPtr]]
96 ; CHECK-SPIRV-NEXT: OpGenericCastToPtr %[[#GlobalIntPtr]]
97 ; CHECK-SPIRV-NEXT: OpGenericCastToPtr %[[#LocalCharPtr]]
98 ; CHECK-SPIRV-NEXT: OpGenericCastToPtr %[[#PrivateIntPtr]]
99 ; CHECK-SPIRV: OpFunctionEnd
101 ; CHECK-SPIRV: OpFunction
102 ; CHECK-SPIRV: OpPtrCastToGeneric %[[#GenericIntPtr]]
103 ; CHECK-SPIRV-NEXT: OpPtrCastToGeneric %[[#GenericCharPtr]]
104 ; CHECK-SPIRV-NEXT: OpPtrCastToGeneric %[[#GenericIntPtr]]
105 ; CHECK-SPIRV-NEXT: OpGenericCastToPtr %[[#GlobalIntPtr]]
106 ; CHECK-SPIRV-NEXT: OpGenericCastToPtr %[[#LocalCharPtr]]
107 ; CHECK-SPIRV-NEXT: OpGenericCastToPtr %[[#PrivateIntPtr]]
108 ; CHECK-SPIRV: OpFunctionEnd
110 define spir_kernel void @test3(ptr addrspace(1) %_arg_GlobalA, ptr byval(%id) %_arg_GlobalId, ptr addrspace(3) %_arg_LocalA) {
113 %p0 = load i64, ptr %_arg_GlobalId
114 %add = getelementptr inbounds i32, ptr addrspace(1) %_arg_GlobalA, i64 %p0
115 %p2 = load i64, ptr addrspace(1) @__spirv_BuiltInGlobalInvocationId
116 %idx = getelementptr inbounds i32, ptr addrspace(1) %add, i64 %p2
117 %var1 = addrspacecast ptr addrspace(1) %idx to ptr addrspace(4)
118 %var2 = addrspacecast ptr addrspace(3) %_arg_LocalA to ptr addrspace(4)
119 %var3 = addrspacecast ptr %var to ptr addrspace(4)
120 %G = call spir_func ptr addrspace(1) @__spirv_GenericCastToPtr_ToGlobal(ptr addrspace(4) %var1, i32 5)
121 %L = call spir_func ptr addrspace(3) @__spirv_GenericCastToPtr_ToLocal(ptr addrspace(4) %var2, i32 4)
122 %P = call spir_func ptr @__spirv_GenericCastToPtr_ToPrivate(ptr addrspace(4) %var3, i32 7)
123 %GE = call spir_func ptr addrspace(1) @__spirv_GenericCastToPtrExplicit_ToGlobal(ptr addrspace(4) %var1, i32 5)
124 %LE = call spir_func ptr addrspace(3) @__spirv_GenericCastToPtrExplicit_ToLocal(ptr addrspace(4) %var2, i32 4)
125 %PE = call spir_func ptr @__spirv_GenericCastToPtrExplicit_ToPrivate(ptr addrspace(4) %var3, i32 7)
129 define spir_kernel void @test4(ptr addrspace(1) %_arg_GlobalA, ptr byval(%id) %_arg_GlobalId, ptr addrspace(3) %_arg_LocalA) {
132 %p0 = load i64, ptr %_arg_GlobalId
133 %add = getelementptr inbounds i32, ptr addrspace(1) %_arg_GlobalA, i64 %p0
134 %p2 = load i64, ptr addrspace(1) @__spirv_BuiltInGlobalInvocationId
135 %idx = getelementptr inbounds i32, ptr addrspace(1) %add, i64 %p2
136 %var1 = addrspacecast ptr addrspace(1) %idx to ptr addrspace(4)
137 %var2 = addrspacecast ptr addrspace(3) %_arg_LocalA to ptr addrspace(4)
138 %var3 = addrspacecast ptr %var to ptr addrspace(4)
139 %G = call spir_func ptr addrspace(1) @to_global(ptr addrspace(4) %var1)
140 %L = call spir_func ptr addrspace(3) @to_local(ptr addrspace(4) %var2)
141 %P = call spir_func ptr @to_private(ptr addrspace(4) %var3)
145 declare spir_func ptr addrspace(1) @__spirv_GenericCastToPtr_ToGlobal(ptr addrspace(4), i32)
146 declare spir_func ptr addrspace(3) @__spirv_GenericCastToPtr_ToLocal(ptr addrspace(4), i32)
147 declare spir_func ptr @__spirv_GenericCastToPtr_ToPrivate(ptr addrspace(4), i32)
148 declare spir_func ptr addrspace(1) @__spirv_GenericCastToPtrExplicit_ToGlobal(ptr addrspace(4), i32)
149 declare spir_func ptr addrspace(3) @__spirv_GenericCastToPtrExplicit_ToLocal(ptr addrspace(4), i32)
150 declare spir_func ptr @__spirv_GenericCastToPtrExplicit_ToPrivate(ptr addrspace(4), i32)
152 declare spir_func ptr addrspace(1) @to_global(ptr addrspace(4))
153 declare spir_func ptr addrspace(3) @to_local(ptr addrspace(4))
154 declare spir_func ptr @to_private(ptr addrspace(4))