1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
|
; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv64-unknown-unknown %s -o - | FileCheck %s --check-prefix=CHECK-SPIRV
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown %s -o - -filetype=obj | spirv-val %}
; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv32-unknown-unknown %s -o - | FileCheck %s --check-prefix=CHECK-SPIRV
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv32-unknown-unknown %s -o - -filetype=obj | spirv-val %}
; CHECK-SPIRV-DAG: %[[#int:]] = OpTypeInt 32 0
; CHECK-SPIRV-DAG: %[[#intv2:]] = OpTypeVector %[[#int]] 2
; CHECK-SPIRV-DAG: %[[#intv3:]] = OpTypeVector %[[#int]] 3
; CHECK-SPIRV-DAG: %[[#float:]] = OpTypeFloat 32
; CHECK-SPIRV-DAG: %[[#ScopeCrossWorkgroup:]] = OpConstantNull %[[#int]]
; CHECK-SPIRV-DAG: %[[#ScopeWorkgroup:]] = OpConstant %[[#int]] 2{{$}}
; CHECK-SPIRV-DAG: %[[#ScopeSubgroup:]] = OpConstant %[[#int]] 3{{$}}
; CHECK-SPIRV: OpFunction
; CHECK-SPIRV: %[[#]] = OpGroupFMax %[[#float]] %[[#ScopeWorkgroup]] Reduce
; CHECK-SPIRV: OpFunctionEnd
;; kernel void testWorkGroupFMax(float a, global float *res) {
;; res[0] = work_group_reduce_max(a);
;; }
define dso_local spir_kernel void @testWorkGroupFMax(float noundef %a, float addrspace(1)* nocapture noundef writeonly %res) local_unnamed_addr {
entry:
%call = call spir_func float @_Z21work_group_reduce_maxf(float noundef %a)
store float %call, float addrspace(1)* %res, align 4
ret void
}
declare spir_func float @_Z21work_group_reduce_maxf(float noundef) local_unnamed_addr
; CHECK-SPIRV: OpFunction
; CHECK-SPIRV: %[[#]] = OpGroupFMin %[[#float]] %[[#ScopeWorkgroup]] Reduce
; CHECK-SPIRV: OpFunctionEnd
;; kernel void testWorkGroupFMin(float a, global float *res) {
;; res[0] = work_group_reduce_min(a);
;; }
define dso_local spir_kernel void @testWorkGroupFMin(float noundef %a, float addrspace(1)* nocapture noundef writeonly %res) local_unnamed_addr {
entry:
%call = call spir_func float @_Z21work_group_reduce_minf(float noundef %a)
store float %call, float addrspace(1)* %res, align 4
ret void
}
declare spir_func float @_Z21work_group_reduce_minf(float noundef) local_unnamed_addr
; CHECK-SPIRV: OpFunction
; CHECK-SPIRV: %[[#]] = OpGroupFAdd %[[#float]] %[[#ScopeWorkgroup]] Reduce
; CHECK-SPIRV: OpFunctionEnd
;; kernel void testWorkGroupFAdd(float a, global float *res) {
;; res[0] = work_group_reduce_add(a);
;; }
define dso_local spir_kernel void @testWorkGroupFAdd(float noundef %a, float addrspace(1)* nocapture noundef writeonly %res) local_unnamed_addr {
entry:
%call = call spir_func float @_Z21work_group_reduce_addf(float noundef %a)
store float %call, float addrspace(1)* %res, align 4
ret void
}
declare spir_func float @_Z21work_group_reduce_addf(float noundef) local_unnamed_addr
; CHECK-SPIRV: OpFunction
; CHECK-SPIRV: %[[#]] = OpGroupFMax %[[#float]] %[[#ScopeWorkgroup]] InclusiveScan
; CHECK-SPIRV: OpFunctionEnd
;; kernel void testWorkGroupScanInclusiveFMax(float a, global float *res) {
;; res[0] = work_group_scan_inclusive_max(a);
;; }
define dso_local spir_kernel void @testWorkGroupScanInclusiveFMax(float noundef %a, float addrspace(1)* nocapture noundef writeonly %res) local_unnamed_addr {
entry:
%call = call spir_func float @_Z29work_group_scan_inclusive_maxf(float noundef %a)
store float %call, float addrspace(1)* %res, align 4
ret void
}
declare spir_func float @_Z29work_group_scan_inclusive_maxf(float noundef) local_unnamed_addr
; CHECK-SPIRV: OpFunction
; CHECK-SPIRV: %[[#]] = OpGroupFMax %[[#float]] %[[#ScopeWorkgroup]] ExclusiveScan
; CHECK-SPIRV: OpFunctionEnd
;; kernel void testWorkGroupScanExclusiveFMax(float a, global float *res) {
;; res[0] = work_group_scan_exclusive_max(a);
;; }
define dso_local spir_kernel void @testWorkGroupScanExclusiveFMax(float noundef %a, float addrspace(1)* nocapture noundef writeonly %res) local_unnamed_addr {
entry:
%call = call spir_func float @_Z29work_group_scan_exclusive_maxf(float noundef %a)
store float %call, float addrspace(1)* %res, align 4
ret void
}
declare spir_func float @_Z29work_group_scan_exclusive_maxf(float noundef) local_unnamed_addr
; CHECK-SPIRV: OpFunction
; CHECK-SPIRV: %[[#]] = OpGroupSMax %[[#int]] %[[#ScopeWorkgroup]] Reduce
; CHECK-SPIRV: OpFunctionEnd
;; kernel void testWorkGroupSMax(int a, global int *res) {
;; res[0] = work_group_reduce_max(a);
;; }
define dso_local spir_kernel void @testWorkGroupSMax(i32 noundef %a, i32 addrspace(1)* nocapture noundef writeonly %res) local_unnamed_addr {
entry:
%call = call spir_func i32 @_Z21work_group_reduce_maxi(i32 noundef %a)
store i32 %call, i32 addrspace(1)* %res, align 4
ret void
}
declare spir_func i32 @_Z21work_group_reduce_maxi(i32 noundef) local_unnamed_addr
; CHECK-SPIRV: OpFunction
; CHECK-SPIRV: %[[#]] = OpGroupSMin %[[#int]] %[[#ScopeWorkgroup]] Reduce
; CHECK-SPIRV: OpFunctionEnd
;; kernel void testWorkGroupSMin(int a, global int *res) {
;; res[0] = work_group_reduce_min(a);
;; }
define dso_local spir_kernel void @testWorkGroupSMin(i32 noundef %a, i32 addrspace(1)* nocapture noundef writeonly %res) local_unnamed_addr {
entry:
%call = call spir_func i32 @_Z21work_group_reduce_mini(i32 noundef %a)
store i32 %call, i32 addrspace(1)* %res, align 4
ret void
}
declare spir_func i32 @_Z21work_group_reduce_mini(i32 noundef) local_unnamed_addr
; CHECK-SPIRV: OpFunction
; CHECK-SPIRV: %[[#]] = OpGroupIAdd %[[#int]] %[[#ScopeWorkgroup]] Reduce
; CHECK-SPIRV: OpFunctionEnd
;; kernel void testWorkGroupIAddSigned(int a, global int *res) {
;; res[0] = work_group_reduce_add(a);
;; }
define dso_local spir_kernel void @testWorkGroupIAddSigned(i32 noundef %a, i32 addrspace(1)* nocapture noundef writeonly %res) local_unnamed_addr {
entry:
%call = call spir_func i32 @_Z21work_group_reduce_addi(i32 noundef %a)
store i32 %call, i32 addrspace(1)* %res, align 4
ret void
}
declare spir_func i32 @_Z21work_group_reduce_addi(i32 noundef) local_unnamed_addr
; CHECK-SPIRV: OpFunction
; CHECK-SPIRV: %[[#]] = OpGroupIAdd %[[#int]] %[[#ScopeWorkgroup]] Reduce
; CHECK-SPIRV: OpFunctionEnd
;; kernel void testWorkGroupIAddUnsigned(uint a, global uint *res) {
;; res[0] = work_group_reduce_add(a);
;; }
define dso_local spir_kernel void @testWorkGroupIAddUnsigned(i32 noundef %a, i32 addrspace(1)* nocapture noundef writeonly %res) local_unnamed_addr {
entry:
%call = call spir_func i32 @_Z21work_group_reduce_addj(i32 noundef %a)
store i32 %call, i32 addrspace(1)* %res, align 4
ret void
}
declare spir_func i32 @_Z21work_group_reduce_addj(i32 noundef) local_unnamed_addr
; CHECK-SPIRV: OpFunction
; CHECK-SPIRV: %[[#]] = OpGroupUMax %[[#int]] %[[#ScopeWorkgroup]] Reduce
; CHECK-SPIRV: OpFunctionEnd
;; kernel void testWorkGroupUMax(uint a, global uint *res) {
;; res[0] = work_group_reduce_max(a);
;; }
define dso_local spir_kernel void @testWorkGroupUMax(i32 noundef %a, i32 addrspace(1)* nocapture noundef writeonly %res) local_unnamed_addr {
entry:
%call = call spir_func i32 @_Z21work_group_reduce_maxj(i32 noundef %a)
store i32 %call, i32 addrspace(1)* %res, align 4
ret void
}
declare spir_func i32 @_Z21work_group_reduce_maxj(i32 noundef) local_unnamed_addr
; CHECK-SPIRV: OpFunction
; CHECK-SPIRV: %[[#]] = OpGroupUMax %[[#int]] %[[#ScopeSubgroup]] Reduce
; CHECK-SPIRV: OpFunctionEnd
;; #pragma OPENCL EXTENSION cl_khr_subgroups: enable
;; kernel void testSubGroupUMax(uint a, global uint *res) {
;; res[0] = sub_group_reduce_max(a);
;; }
;; #pragma OPENCL EXTENSION cl_khr_subgroups: disable
define dso_local spir_kernel void @testSubGroupUMax(i32 noundef %a, i32 addrspace(1)* nocapture noundef writeonly %res) local_unnamed_addr {
entry:
%call = call spir_func i32 @_Z20sub_group_reduce_maxj(i32 noundef %a)
store i32 %call, i32 addrspace(1)* %res, align 4
ret void
}
declare spir_func i32 @_Z20sub_group_reduce_maxj(i32 noundef) local_unnamed_addr
; CHECK-SPIRV: OpFunction
; CHECK-SPIRV: %[[#]] = OpGroupUMax %[[#int]] %[[#ScopeWorkgroup]] InclusiveScan
; CHECK-SPIRV: OpFunctionEnd
;; kernel void testWorkGroupScanInclusiveUMax(uint a, global uint *res) {
;; res[0] = work_group_scan_inclusive_max(a);
;; }
define dso_local spir_kernel void @testWorkGroupScanInclusiveUMax(i32 noundef %a, i32 addrspace(1)* nocapture noundef writeonly %res) local_unnamed_addr {
entry:
%call = call spir_func i32 @_Z29work_group_scan_inclusive_maxj(i32 noundef %a)
store i32 %call, i32 addrspace(1)* %res, align 4
ret void
}
declare spir_func i32 @_Z29work_group_scan_inclusive_maxj(i32 noundef) local_unnamed_addr
; CHECK-SPIRV: OpFunction
; CHECK-SPIRV: %[[#]] = OpGroupUMax %[[#int]] %[[#ScopeWorkgroup]] ExclusiveScan
; CHECK-SPIRV: OpFunctionEnd
;; kernel void testWorkGroupScanExclusiveUMax(uint a, global uint *res) {
;; res[0] = work_group_scan_exclusive_max(a);
;; }
define dso_local spir_kernel void @testWorkGroupScanExclusiveUMax(i32 noundef %a, i32 addrspace(1)* nocapture noundef writeonly %res) local_unnamed_addr {
entry:
%call = call spir_func i32 @_Z29work_group_scan_exclusive_maxj(i32 noundef %a)
store i32 %call, i32 addrspace(1)* %res, align 4
ret void
}
declare spir_func i32 @_Z29work_group_scan_exclusive_maxj(i32 noundef) local_unnamed_addr
; CHECK-SPIRV: OpFunction
; CHECK-SPIRV: %[[#]] = OpGroupUMin %[[#int]] %[[#ScopeWorkgroup]] Reduce
; CHECK-SPIRV: OpFunctionEnd
;; kernel void testWorkGroupUMin(uint a, global uint *res) {
;; res[0] = work_group_reduce_min(a);
;; }
define dso_local spir_kernel void @testWorkGroupUMin(i32 noundef %a, i32 addrspace(1)* nocapture noundef writeonly %res) local_unnamed_addr {
entry:
%call = call spir_func i32 @_Z21work_group_reduce_minj(i32 noundef %a)
store i32 %call, i32 addrspace(1)* %res, align 4
ret void
}
declare spir_func i32 @_Z21work_group_reduce_minj(i32 noundef) local_unnamed_addr
; CHECK-SPIRV: OpFunction
; CHECK-SPIRV: %[[#]] = OpGroupBroadcast %[[#int]] %[[#ScopeWorkgroup]] %[[#BroadcastValue:]] %[[#BroadcastLocalId:]]
; CHECK-SPIRV: %[[#BroadcastVec2:]] = OpCompositeConstruct %[[#intv2]] %[[#BroadcastLocalId]] %[[#BroadcastLocalId]]
; CHECK-SPIRV: %[[#]] = OpGroupBroadcast %[[#int]] %[[#ScopeWorkgroup]] %[[#BroadcastValue]] %[[#BroadcastVec2]]
; CHECK-SPIRV: %[[#BroadcastVec3:]] = OpCompositeConstruct %[[#intv3]] %[[#BroadcastLocalId]] %[[#BroadcastLocalId]] %[[#BroadcastLocalId]]
; CHECK-SPIRV: %[[#]] = OpGroupBroadcast %[[#int]] %[[#ScopeWorkgroup]] %[[#BroadcastValue]] %[[#BroadcastVec3]]
; CHECK-SPIRV: %[[#]] = OpGroupBroadcast %[[#int]] %[[#ScopeCrossWorkgroup]] %[[#BroadcastValue]] %[[#BroadcastLocalId]]
; CHECK-SPIRV: OpFunctionEnd
;; kernel void testWorkGroupBroadcast(uint a, global size_t *id, global int *res) {
;; res[0] = work_group_broadcast(a, *id);
;; }
define dso_local spir_kernel void @testWorkGroupBroadcast(i32 noundef %a, i32 addrspace(1)* nocapture noundef readonly %id, i32 addrspace(1)* nocapture noundef writeonly %res) local_unnamed_addr {
entry:
%0 = load i32, i32 addrspace(1)* %id, align 4
%call = call spir_func i32 @_Z20work_group_broadcastjj(i32 noundef %a, i32 noundef %0)
%call_v2 = call spir_func i32 @_Z20work_group_broadcastjj(i32 noundef %a, i32 noundef %0, i32 noundef %0)
%call_v3 = call spir_func i32 @_Z20work_group_broadcastjj(i32 noundef %a, i32 noundef %0, i32 noundef %0, i32 noundef %0)
store i32 %call, i32 addrspace(1)* %res, align 4
%call1 = call spir_func i32 @__spirv_GroupBroadcast(i32 0, i32 noundef %a, i32 noundef %0)
ret void
}
declare spir_func i32 @_Z20work_group_broadcastjj(i32 noundef, i32 noundef) local_unnamed_addr
declare spir_func i32 @_Z20work_group_broadcastjjj(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr
declare spir_func i32 @_Z20work_group_broadcastjjjj(i32 noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr
declare spir_func i32 @__spirv_GroupBroadcast(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr
; CHECK-SPIRV: OpFunction
; CHECK-SPIRV: %[[#]] = OpGroupFAdd %[[#float]] %[[#ScopeCrossWorkgroup]] Reduce %[[#FValue:]]
; CHECK-SPIRV: %[[#]] = OpGroupFMin %[[#float]] %[[#ScopeWorkgroup]] InclusiveScan %[[#FValue]]
; CHECK-SPIRV: %[[#]] = OpGroupFMax %[[#float]] %[[#ScopeSubgroup]] ExclusiveScan %[[#FValue]]
; CHECK-SPIRV: %[[#]] = OpGroupIAdd %[[#int]] %[[#ScopeCrossWorkgroup]] Reduce %[[#IValue:]]
; CHECK-SPIRV: %[[#]] = OpGroupUMin %[[#int]] %[[#ScopeWorkgroup]] InclusiveScan %[[#IValue]]
; CHECK-SPIRV: %[[#]] = OpGroupSMin %[[#int]] %[[#ScopeSubgroup]] ExclusiveScan %[[#IValue]]
; CHECK-SPIRV: %[[#]] = OpGroupUMax %[[#int]] %[[#ScopeCrossWorkgroup]] Reduce %[[#IValue]]
; CHECK-SPIRV: %[[#]] = OpGroupSMax %[[#int]] %[[#ScopeWorkgroup]] InclusiveScan %[[#IValue]]
; CHECK-SPIRV: OpFunctionEnd
define spir_kernel void @foo(float %a, i32 %b) {
entry:
%f1 = call spir_func float @__spirv_GroupFAdd(i32 0, i32 0, float %a)
%f2 = call spir_func float @__spirv_GroupFMin(i32 2, i32 1, float %a)
%f3 = call spir_func float @__spirv_GroupFMax(i32 3, i32 2, float %a)
%i1 = call spir_func i32 @__spirv_GroupIAdd(i32 0, i32 0, i32 %b)
%i2 = call spir_func i32 @__spirv_GroupUMin(i32 2, i32 1, i32 %b)
%i3 = call spir_func i32 @__spirv_GroupSMin(i32 3, i32 2, i32 %b)
%i4 = call spir_func i32 @__spirv_GroupUMax(i32 0, i32 0, i32 %b)
%i5 = call spir_func i32 @__spirv_GroupSMax(i32 2, i32 1, i32 %b)
ret void
}
declare spir_func float @__spirv_GroupFAdd(i32, i32, float)
declare spir_func float @__spirv_GroupFMin(i32, i32, float)
declare spir_func float @__spirv_GroupFMax(i32, i32, float)
declare spir_func i32 @__spirv_GroupIAdd(i32, i32, i32)
declare spir_func i32 @__spirv_GroupUMin(i32, i32, i32)
declare spir_func i32 @__spirv_GroupSMin(i32, i32, i32)
declare spir_func i32 @__spirv_GroupUMax(i32, i32, i32)
declare spir_func i32 @__spirv_GroupSMax(i32, i32, i32)
|