blob: cb5873a1baf04d2533ad3174e73b59576d3d5521 [file] [log] [blame]
Lei Zhangffd45832020-03-18 13:56:381// RUN: mlir-opt -split-input-file -convert-std-to-spirv %s -o - | FileCheck %s
2
3//===----------------------------------------------------------------------===//
4// std arithmetic ops
5//===----------------------------------------------------------------------===//
Mahesh Ravishankard3a601c2019-06-11 17:47:066
Lei Zhang67e86902020-03-18 13:55:277module attributes {
8 spv.target_env = #spv.target_env<
Lei Zhangffd45832020-03-18 13:56:389 #spv.vce<v1.0, [Int8, Int16, Int64, Float16, Float64], []>,
Lei Zhang67e86902020-03-18 13:55:2710 {max_compute_workgroup_invocations = 128 : i32,
11 max_compute_workgroup_size = dense<[128, 128, 64]> : vector<3xi32>}>
12} {
13
Lei Zhangffd45832020-03-18 13:56:3814// Check integer operation conversions.
15// CHECK-LABEL: @int32_scalar
16func @int32_scalar(%lhs: i32, %rhs: i32) {
17 // CHECK: spv.IAdd %{{.*}}, %{{.*}}: i32
18 %0 = addi %lhs, %rhs: i32
19 // CHECK: spv.ISub %{{.*}}, %{{.*}}: i32
20 %1 = subi %lhs, %rhs: i32
21 // CHECK: spv.IMul %{{.*}}, %{{.*}}: i32
22 %2 = muli %lhs, %rhs: i32
23 // CHECK: spv.SDiv %{{.*}}, %{{.*}}: i32
24 %3 = divi_signed %lhs, %rhs: i32
25 // CHECK: spv.SRem %{{.*}}, %{{.*}}: i32
26 %4 = remi_signed %lhs, %rhs: i32
27 // CHECK: spv.UDiv %{{.*}}, %{{.*}}: i32
28 %5 = divi_unsigned %lhs, %rhs: i32
29 // CHECK: spv.UMod %{{.*}}, %{{.*}}: i32
30 %6 = remi_unsigned %lhs, %rhs: i32
Lei Zhangaaafeac2019-11-23 14:03:4031 return
32}
33
Lei Zhangffd45832020-03-18 13:56:3834// Check float operation conversions.
35// CHECK-LABEL: @float32_scalar
36func @float32_scalar(%lhs: f32, %rhs: f32) {
37 // CHECK: spv.FAdd %{{.*}}, %{{.*}}: f32
38 %0 = addf %lhs, %rhs: f32
39 // CHECK: spv.FSub %{{.*}}, %{{.*}}: f32
40 %1 = subf %lhs, %rhs: f32
41 // CHECK: spv.FMul %{{.*}}, %{{.*}}: f32
42 %2 = mulf %lhs, %rhs: f32
43 // CHECK: spv.FDiv %{{.*}}, %{{.*}}: f32
44 %3 = divf %lhs, %rhs: f32
45 // CHECK: spv.FRem %{{.*}}, %{{.*}}: f32
46 %4 = remf %lhs, %rhs: f32
Lei Zhangd3e78162020-02-07 16:30:1947 return
Denis Khalikovd968f962019-12-11 19:17:0348}
49
Lei Zhangffd45832020-03-18 13:56:3850// Check int vector types.
51// CHECK-LABEL: @int_vector234
52func @int_vector234(%arg0: vector<2xi8>, %arg1: vector<3xi16>, %arg2: vector<4xi64>) {
53 // CHECK: spv.SDiv %{{.*}}, %{{.*}}: vector<2xi8>
54 %0 = divi_signed %arg0, %arg0: vector<2xi8>
55 // CHECK: spv.SRem %{{.*}}, %{{.*}}: vector<3xi16>
56 %1 = remi_signed %arg1, %arg1: vector<3xi16>
57 // CHECK: spv.UDiv %{{.*}}, %{{.*}}: vector<4xi64>
58 %2 = divi_unsigned %arg2, %arg2: vector<4xi64>
Lei Zhangd3e78162020-02-07 16:30:1959 return
Denis Khalikovd968f962019-12-11 19:17:0360}
61
Lei Zhangffd45832020-03-18 13:56:3862// Check float vector types.
63// CHECK-LABEL: @float_vector234
64func @float_vector234(%arg0: vector<2xf16>, %arg1: vector<3xf64>) {
65 // CHECK: spv.FAdd %{{.*}}, %{{.*}}: vector<2xf16>
66 %0 = addf %arg0, %arg0: vector<2xf16>
67 // CHECK: spv.FMul %{{.*}}, %{{.*}}: vector<3xf64>
68 %1 = mulf %arg1, %arg1: vector<3xf64>
Lei Zhangd3e78162020-02-07 16:30:1969 return
Mahesh Ravishankard3a601c2019-06-11 17:47:0670}
71
Lei Zhangffd45832020-03-18 13:56:3872// CHECK-LABEL: @unsupported_1elem_vector
73func @unsupported_1elem_vector(%arg0: vector<1xi32>) {
74 // CHECK: addi
75 %0 = addi %arg0, %arg0: vector<1xi32>
Lei Zhangd3e78162020-02-07 16:30:1976 return
Mahesh Ravishankard3a601c2019-06-11 17:47:0677}
78
Lei Zhangffd45832020-03-18 13:56:3879// CHECK-LABEL: @unsupported_5elem_vector
80func @unsupported_5elem_vector(%arg0: vector<5xi32>) {
81 // CHECK: subi
82 %1 = subi %arg0, %arg0: vector<5xi32>
Lei Zhangd3e78162020-02-07 16:30:1983 return
Mahesh Ravishankard3a601c2019-06-11 17:47:0684}
85
Lei Zhangffd45832020-03-18 13:56:3886// CHECK-LABEL: @unsupported_2x2elem_vector
87func @unsupported_2x2elem_vector(%arg0: vector<2x2xi32>) {
88 // CHECK: muli
89 %2 = muli %arg0, %arg0: vector<2x2xi32>
Lei Zhangd3e78162020-02-07 16:30:1990 return
Mahesh Ravishankard3a601c2019-06-11 17:47:0691}
92
Lei Zhangffd45832020-03-18 13:56:3893} // end module
94
95// -----
96
97// Check that types are converted to 32-bit when no special capabilities.
98module attributes {
99 spv.target_env = #spv.target_env<
100 #spv.vce<v1.0, [], []>,
101 {max_compute_workgroup_invocations = 128 : i32,
102 max_compute_workgroup_size = dense<[128, 128, 64]> : vector<3xi32>}>
103} {
104
105// CHECK-LABEL: @int_vector234
106func @int_vector234(%arg0: vector<2xi8>, %arg1: vector<3xi16>, %arg2: vector<4xi64>) {
107 // CHECK: spv.SDiv %{{.*}}, %{{.*}}: vector<2xi32>
108 %0 = divi_signed %arg0, %arg0: vector<2xi8>
109 // CHECK: spv.SRem %{{.*}}, %{{.*}}: vector<3xi32>
110 %1 = remi_signed %arg1, %arg1: vector<3xi16>
111 // CHECK: spv.UDiv %{{.*}}, %{{.*}}: vector<4xi32>
112 %2 = divi_unsigned %arg2, %arg2: vector<4xi64>
Lei Zhangd3e78162020-02-07 16:30:19113 return
Mahesh Ravishankard3a601c2019-06-11 17:47:06114}
115
Lei Zhangffd45832020-03-18 13:56:38116// CHECK-LABEL: @float_scalar
117func @float_scalar(%arg0: f16, %arg1: f64) {
118 // CHECK: spv.FAdd %{{.*}}, %{{.*}}: f32
119 %0 = addf %arg0, %arg0: f16
120 // CHECK: spv.FMul %{{.*}}, %{{.*}}: f32
121 %1 = mulf %arg1, %arg1: f64
Lei Zhangd3e78162020-02-07 16:30:19122 return
Denis Khalikovd968f962019-12-11 19:17:03123}
124
Lei Zhangffd45832020-03-18 13:56:38125} // end module
Denis Khalikovd968f962019-12-11 19:17:03126
Lei Zhangffd45832020-03-18 13:56:38127// -----
Mahesh Ravishankar2be53602019-11-12 21:19:33128
Lei Zhangaaafeac2019-11-23 14:03:40129//===----------------------------------------------------------------------===//
Denis Khalikov9883b142020-01-08 02:40:42130// std bit ops
131//===----------------------------------------------------------------------===//
132
Lei Zhangffd45832020-03-18 13:56:38133module attributes {
134 spv.target_env = #spv.target_env<
135 #spv.vce<v1.0, [], []>,
136 {max_compute_workgroup_invocations = 128 : i32,
137 max_compute_workgroup_size = dense<[128, 128, 64]> : vector<3xi32>}>
138} {
139
Denis Khalikov9883b142020-01-08 02:40:42140// CHECK-LABEL: @bitwise_scalar
141func @bitwise_scalar(%arg0 : i32, %arg1 : i32) {
142 // CHECK: spv.BitwiseAnd
143 %0 = and %arg0, %arg1 : i32
144 // CHECK: spv.BitwiseOr
145 %1 = or %arg0, %arg1 : i32
146 // CHECK: spv.BitwiseXor
147 %2 = xor %arg0, %arg1 : i32
148 return
149}
150
151// CHECK-LABEL: @bitwise_vector
152func @bitwise_vector(%arg0 : vector<4xi32>, %arg1 : vector<4xi32>) {
153 // CHECK: spv.BitwiseAnd
154 %0 = and %arg0, %arg1 : vector<4xi32>
155 // CHECK: spv.BitwiseOr
156 %1 = or %arg0, %arg1 : vector<4xi32>
157 // CHECK: spv.BitwiseXor
158 %2 = xor %arg0, %arg1 : vector<4xi32>
159 return
160}
161
Lei Zhangffd45832020-03-18 13:56:38162// CHECK-LABEL: @logical_scalar
163func @logical_scalar(%arg0 : i1, %arg1 : i1) {
164 // CHECK: spv.LogicalAnd
165 %0 = and %arg0, %arg1 : i1
166 // CHECK: spv.LogicalOr
167 %1 = or %arg0, %arg1 : i1
168 return
169}
170
171// CHECK-LABEL: @logical_vector
172func @logical_vector(%arg0 : vector<4xi1>, %arg1 : vector<4xi1>) {
173 // CHECK: spv.LogicalAnd
174 %0 = and %arg0, %arg1 : vector<4xi1>
175 // CHECK: spv.LogicalOr
176 %1 = or %arg0, %arg1 : vector<4xi1>
177 return
178}
179
Denis Khalikov9883b142020-01-08 02:40:42180// CHECK-LABEL: @shift_scalar
181func @shift_scalar(%arg0 : i32, %arg1 : i32) {
182 // CHECK: spv.ShiftLeftLogical
183 %0 = shift_left %arg0, %arg1 : i32
184 // CHECK: spv.ShiftRightArithmetic
185 %1 = shift_right_signed %arg0, %arg1 : i32
186 // CHECK: spv.ShiftRightLogical
187 %2 = shift_right_unsigned %arg0, %arg1 : i32
188 return
189}
190
191// CHECK-LABEL: @shift_vector
192func @shift_vector(%arg0 : vector<4xi32>, %arg1 : vector<4xi32>) {
193 // CHECK: spv.ShiftLeftLogical
194 %0 = shift_left %arg0, %arg1 : vector<4xi32>
195 // CHECK: spv.ShiftRightArithmetic
196 %1 = shift_right_signed %arg0, %arg1 : vector<4xi32>
197 // CHECK: spv.ShiftRightLogical
198 %2 = shift_right_unsigned %arg0, %arg1 : vector<4xi32>
199 return
200}
201
202//===----------------------------------------------------------------------===//
Denis Khalikovdd495e82020-01-08 02:47:49203// std.cmpf
204//===----------------------------------------------------------------------===//
205
206// CHECK-LABEL: @cmpf
207func @cmpf(%arg0 : f32, %arg1 : f32) {
208 // CHECK: spv.FOrdEqual
209 %1 = cmpf "oeq", %arg0, %arg1 : f32
210 // CHECK: spv.FOrdGreaterThan
211 %2 = cmpf "ogt", %arg0, %arg1 : f32
212 // CHECK: spv.FOrdGreaterThanEqual
213 %3 = cmpf "oge", %arg0, %arg1 : f32
214 // CHECK: spv.FOrdLessThan
215 %4 = cmpf "olt", %arg0, %arg1 : f32
216 // CHECK: spv.FOrdLessThanEqual
217 %5 = cmpf "ole", %arg0, %arg1 : f32
218 // CHECK: spv.FOrdNotEqual
219 %6 = cmpf "one", %arg0, %arg1 : f32
220 // CHECK: spv.FUnordEqual
221 %7 = cmpf "ueq", %arg0, %arg1 : f32
222 // CHECK: spv.FUnordGreaterThan
223 %8 = cmpf "ugt", %arg0, %arg1 : f32
224 // CHECK: spv.FUnordGreaterThanEqual
225 %9 = cmpf "uge", %arg0, %arg1 : f32
226 // CHECK: spv.FUnordLessThan
227 %10 = cmpf "ult", %arg0, %arg1 : f32
228 // CHECK: FUnordLessThanEqual
229 %11 = cmpf "ule", %arg0, %arg1 : f32
230 // CHECK: spv.FUnordNotEqual
231 %12 = cmpf "une", %arg0, %arg1 : f32
232 return
233}
234
235//===----------------------------------------------------------------------===//
Lei Zhangaaafeac2019-11-23 14:03:40236// std.cmpi
237//===----------------------------------------------------------------------===//
238
239// CHECK-LABEL: @cmpi
240func @cmpi(%arg0 : i32, %arg1 : i32) {
Mahesh Ravishankar2be53602019-11-12 21:19:33241 // CHECK: spv.IEqual
242 %0 = cmpi "eq", %arg0, %arg1 : i32
243 // CHECK: spv.INotEqual
244 %1 = cmpi "ne", %arg0, %arg1 : i32
245 // CHECK: spv.SLessThan
246 %2 = cmpi "slt", %arg0, %arg1 : i32
247 // CHECK: spv.SLessThanEqual
248 %3 = cmpi "sle", %arg0, %arg1 : i32
249 // CHECK: spv.SGreaterThan
250 %4 = cmpi "sgt", %arg0, %arg1 : i32
251 // CHECK: spv.SGreaterThanEqual
252 %5 = cmpi "sge", %arg0, %arg1 : i32
Denis Khalikovdd495e82020-01-08 02:47:49253 // CHECK: spv.ULessThan
254 %6 = cmpi "ult", %arg0, %arg1 : i32
255 // CHECK: spv.ULessThanEqual
256 %7 = cmpi "ule", %arg0, %arg1 : i32
257 // CHECK: spv.UGreaterThan
258 %8 = cmpi "ugt", %arg0, %arg1 : i32
259 // CHECK: spv.UGreaterThanEqual
260 %9 = cmpi "uge", %arg0, %arg1 : i32
Mahesh Ravishankar2be53602019-11-12 21:19:33261 return
262}
263
Lei Zhangffd45832020-03-18 13:56:38264} // end module
265
266// -----
267
Lei Zhangaaafeac2019-11-23 14:03:40268//===----------------------------------------------------------------------===//
269// std.constant
270//===----------------------------------------------------------------------===//
271
Lei Zhangffd45832020-03-18 13:56:38272module attributes {
273 spv.target_env = #spv.target_env<
274 #spv.vce<v1.0, [Int8, Int16, Int64, Float16, Float64], []>,
275 {max_compute_workgroup_invocations = 128 : i32,
276 max_compute_workgroup_size = dense<[128, 128, 64]> : vector<3xi32>}>
277} {
278
Lei Zhangaaafeac2019-11-23 14:03:40279// CHECK-LABEL: @constant
280func @constant() {
281 // CHECK: spv.constant true
282 %0 = constant true
Lei Zhang73431a42020-03-18 13:56:51283 // CHECK: spv.constant 42 : i32
284 %1 = constant 42 : i32
285 // CHECK: spv.constant 5.000000e-01 : f32
Lei Zhangaaafeac2019-11-23 14:03:40286 %2 = constant 0.5 : f32
287 // CHECK: spv.constant dense<[2, 3]> : vector<2xi32>
288 %3 = constant dense<[2, 3]> : vector<2xi32>
289 // CHECK: spv.constant 1 : i32
290 %4 = constant 1 : index
Denis Khalikov4460cb52020-01-22 13:05:27291 // CHECK: spv.constant dense<1> : tensor<6xi32> : !spv.array<6 x i32 [4]>
292 %5 = constant dense<1> : tensor<2x3xi32>
293 // CHECK: spv.constant dense<1.000000e+00> : tensor<6xf32> : !spv.array<6 x f32 [4]>
294 %6 = constant dense<1.0> : tensor<2x3xf32>
295 // CHECK: spv.constant dense<{{\[}}1.000000e+00, 2.000000e+00, 3.000000e+00, 4.000000e+00, 5.000000e+00, 6.000000e+00]> : tensor<6xf32> : !spv.array<6 x f32 [4]>
296 %7 = constant dense<[[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]]> : tensor<2x3xf32>
297 // CHECK: spv.constant dense<{{\[}}1, 2, 3, 4, 5, 6]> : tensor<6xi32> : !spv.array<6 x i32 [4]>
298 %8 = constant dense<[[1, 2, 3], [4, 5, 6]]> : tensor<2x3xi32>
299 // CHECK: spv.constant dense<{{\[}}1, 2, 3, 4, 5, 6]> : tensor<6xi32> : !spv.array<6 x i32 [4]>
300 %9 = constant dense<[[1, 2], [3, 4], [5, 6]]> : tensor<3x2xi32>
301 // CHECK: spv.constant dense<{{\[}}1, 2, 3, 4, 5, 6]> : tensor<6xi32> : !spv.array<6 x i32 [4]>
302 %10 = constant dense<[1, 2, 3, 4, 5, 6]> : tensor<6xi32>
Lei Zhangaaafeac2019-11-23 14:03:40303 return
304}
305
Lei Zhang73431a42020-03-18 13:56:51306// CHECK-LABEL: @constant_16bit
307func @constant_16bit() {
308 // CHECK: spv.constant 4 : i16
309 %0 = constant 4 : i16
310 // CHECK: spv.constant 5.000000e+00 : f16
311 %1 = constant 5.0 : f16
312 // CHECK: spv.constant dense<[2, 3]> : vector<2xi16>
313 %2 = constant dense<[2, 3]> : vector<2xi16>
314 // CHECK: spv.constant dense<4.000000e+00> : tensor<5xf16> : !spv.array<5 x f16 [2]>
315 %3 = constant dense<4.0> : tensor<5xf16>
316 return
317}
318
319// CHECK-LABEL: @constant_64bit
320func @constant_64bit() {
321 // CHECK: spv.constant 4 : i64
322 %0 = constant 4 : i64
323 // CHECK: spv.constant 5.000000e+00 : f64
324 %1 = constant 5.0 : f64
325 // CHECK: spv.constant dense<[2, 3]> : vector<2xi64>
326 %2 = constant dense<[2, 3]> : vector<2xi64>
327 // CHECK: spv.constant dense<4.000000e+00> : tensor<5xf64> : !spv.array<5 x f64 [8]>
328 %3 = constant dense<4.0> : tensor<5xf64>
329 return
330}
331
332} // end module
333
334// -----
335
336// Check that constants are converted to 32-bit when no special capability.
337module attributes {
338 spv.target_env = #spv.target_env<
339 #spv.vce<v1.0, [], []>,
340 {max_compute_workgroup_invocations = 128 : i32,
341 max_compute_workgroup_size = dense<[128, 128, 64]> : vector<3xi32>}>
342} {
343
344// CHECK-LABEL: @constant_16bit
345func @constant_16bit() {
346 // CHECK: spv.constant 4 : i32
347 %0 = constant 4 : i16
348 // CHECK: spv.constant 5.000000e+00 : f32
349 %1 = constant 5.0 : f16
350 // CHECK: spv.constant dense<[2, 3]> : vector<2xi32>
351 %2 = constant dense<[2, 3]> : vector<2xi16>
352 // CHECK: spv.constant dense<4.000000e+00> : tensor<5xf32> : !spv.array<5 x f32 [4]>
353 %3 = constant dense<4.0> : tensor<5xf16>
354 // CHECK: spv.constant dense<[1.000000e+00, 2.000000e+00, 3.000000e+00, 4.000000e+00]> : tensor<4xf32> : !spv.array<4 x f32 [4]>
355 %4 = constant dense<[[1.0, 2.0], [3.0, 4.0]]> : tensor<2x2xf16>
356 return
357}
358
359// CHECK-LABEL: @constant_64bit
360func @constant_64bit() {
361 // CHECK: spv.constant 4 : i32
362 %0 = constant 4 : i64
363 // CHECK: spv.constant 5.000000e+00 : f32
364 %1 = constant 5.0 : f64
365 // CHECK: spv.constant dense<[2, 3]> : vector<2xi32>
366 %2 = constant dense<[2, 3]> : vector<2xi64>
367 // CHECK: spv.constant dense<4.000000e+00> : tensor<5xf32> : !spv.array<5 x f32 [4]>
368 %3 = constant dense<4.0> : tensor<5xf64>
369 // CHECK: spv.constant dense<[1.000000e+00, 2.000000e+00, 3.000000e+00, 4.000000e+00]> : tensor<4xf32> : !spv.array<4 x f32 [4]>
370 %4 = constant dense<[[1.0, 2.0], [3.0, 4.0]]> : tensor<2x2xf16>
371 return
372}
373
374// CHECK-LABEL: @corner_cases
375func @corner_cases() {
376 // CHECK: %{{.*}} = spv.constant -1 : i32
377 %0 = constant 4294967295 : i64 // 2^32 - 1
378 // CHECK: %{{.*}} = spv.constant 2147483647 : i32
379 %1 = constant 2147483647 : i64 // 2^31 - 1
380 // CHECK: %{{.*}} = spv.constant -2147483648 : i32
381 %2 = constant 2147483648 : i64 // 2^31
382 // CHECK: %{{.*}} = spv.constant -2147483648 : i32
383 %3 = constant -2147483648 : i64 // -2^31
384
385 // CHECK: %{{.*}} = spv.constant -1 : i32
386 %5 = constant -1 : i64
387 // CHECK: %{{.*}} = spv.constant -2 : i32
388 %6 = constant -2 : i64
389 // CHECK: %{{.*}} = spv.constant -1 : i32
390 %7 = constant -1 : index
391 // CHECK: %{{.*}} = spv.constant -2 : i32
392 %8 = constant -2 : index
393
394
395 // CHECK: spv.constant false
396 %9 = constant 0 : i1
397 // CHECK: spv.constant true
398 %10 = constant 1 : i1
399
400 return
401}
402
403// CHECK-LABEL: @unsupported_cases
404func @unsupported_cases() {
405 // CHECK: %{{.*}} = constant 4294967296 : i64
406 %0 = constant 4294967296 : i64 // 2^32
407 // CHECK: %{{.*}} = constant -2147483649 : i64
408 %1 = constant -2147483649 : i64 // -2^31 - 1
409 // CHECK: %{{.*}} = constant 1.0000000000000002 : f64
410 %2 = constant 0x3FF0000000000001 : f64 // smallest number > 1
411 return
412}
413
Lei Zhangffd45832020-03-18 13:56:38414} // end module
415
416// -----
417
Lei Zhangaaafeac2019-11-23 14:03:40418//===----------------------------------------------------------------------===//
Lei Zhangffd45832020-03-18 13:56:38419// std cast ops
MaheshRavishankarc3d35692019-12-26 00:29:17420//===----------------------------------------------------------------------===//
421
Lei Zhangffd45832020-03-18 13:56:38422module attributes {
423 spv.target_env = #spv.target_env<
424 #spv.vce<v1.0, [Int8, Int16, Int64, Float16, Float64], []>,
425 {max_compute_workgroup_invocations = 128 : i32,
426 max_compute_workgroup_size = dense<[128, 128, 64]> : vector<3xi32>}>
427} {
428
429// CHECK-LABEL: @fpext1
430func @fpext1(%arg0: f16) -> f64 {
431 // CHECK: spv.FConvert %{{.*}} : f16 to f64
432 %0 = std.fpext %arg0 : f16 to f64
433 return %0 : f64
MaheshRavishankarc3d35692019-12-26 00:29:17434}
435
Lei Zhangffd45832020-03-18 13:56:38436// CHECK-LABEL: @fpext2
437func @fpext2(%arg0 : f32) -> f64 {
438 // CHECK: spv.FConvert %{{.*}} : f32 to f64
Denis Khalikoveac01f62020-01-08 03:11:59439 %0 = std.fpext %arg0 : f32 to f64
Lei Zhangffd45832020-03-18 13:56:38440 return %0 : f64
Denis Khalikoveac01f62020-01-08 03:11:59441}
442
Lei Zhangffd45832020-03-18 13:56:38443// CHECK-LABEL: @fptrunc1
444func @fptrunc1(%arg0 : f64) -> f16 {
445 // CHECK: spv.FConvert %{{.*}} : f64 to f16
446 %0 = std.fptrunc %arg0 : f64 to f16
447 return %0 : f16
Denis Khalikoveac01f62020-01-08 03:11:59448}
449
Lei Zhangffd45832020-03-18 13:56:38450// CHECK-LABEL: @fptrunc2
451func @fptrunc2(%arg0: f32) -> f16 {
452 // CHECK: spv.FConvert %{{.*}} : f32 to f16
453 %0 = std.fptrunc %arg0 : f32 to f16
454 return %0 : f16
455}
456
457// CHECK-LABEL: @sitofp1
458func @sitofp1(%arg0 : i32) -> f32 {
459 // CHECK: spv.ConvertSToF %{{.*}} : i32 to f32
460 %0 = std.sitofp %arg0 : i32 to f32
461 return %0 : f32
462}
463
464// CHECK-LABEL: @sitofp2
465func @sitofp2(%arg0 : i64) -> f64 {
466 // CHECK: spv.ConvertSToF %{{.*}} : i64 to f64
467 %0 = std.sitofp %arg0 : i64 to f64
468 return %0 : f64
469}
470
471} // end module
472
473// -----
474
475// Checks that cast types will be adjusted when no special capabilities for
476// non-32-bit scalar types.
477module attributes {
478 spv.target_env = #spv.target_env<
479 #spv.vce<v1.0, [], []>,
480 {max_compute_workgroup_invocations = 128 : i32,
481 max_compute_workgroup_size = dense<[128, 128, 64]> : vector<3xi32>}>
482} {
483
484// CHECK-LABEL: @fpext1
485// CHECK-SAME: %[[ARG:.*]]: f32
486func @fpext1(%arg0: f16) {
487 // CHECK-NEXT: "use"(%[[ARG]])
488 %0 = std.fpext %arg0 : f16 to f64
489 "use"(%0) : (f64) -> ()
490}
491
492// CHECK-LABEL: @fpext2
493// CHECK-SAME: %[[ARG:.*]]: f32
494func @fpext2(%arg0 : f32) {
495 // CHECK-NEXT: "use"(%[[ARG]])
496 %0 = std.fpext %arg0 : f32 to f64
497 "use"(%0) : (f64) -> ()
498}
499
500// CHECK-LABEL: @fptrunc1
501// CHECK-SAME: %[[ARG:.*]]: f32
502func @fptrunc1(%arg0 : f64) {
503 // CHECK-NEXT: "use"(%[[ARG]])
504 %0 = std.fptrunc %arg0 : f64 to f16
505 "use"(%0) : (f16) -> ()
506}
507
508// CHECK-LABEL: @fptrunc2
509// CHECK-SAME: %[[ARG:.*]]: f32
510func @fptrunc2(%arg0: f32) {
511 // CHECK-NEXT: "use"(%[[ARG]])
512 %0 = std.fptrunc %arg0 : f32 to f16
513 "use"(%0) : (f16) -> ()
514}
515
516// CHECK-LABEL: @sitofp
517func @sitofp(%arg0 : i64) {
518 // CHECK: spv.ConvertSToF %{{.*}} : i32 to f32
519 %0 = std.sitofp %arg0 : i64 to f64
520 "use"(%0) : (f64) -> ()
521}
522
523} // end module
524
525// -----
526
527module attributes {
528 spv.target_env = #spv.target_env<
529 #spv.vce<v1.0, [Shader, Int8, Int16, Int64, Float16, Float64], [SPV_KHR_storage_buffer_storage_class]>,
530 {max_compute_workgroup_invocations = 128 : i32,
531 max_compute_workgroup_size = dense<[128, 128, 64]> : vector<3xi32>}>
532} {
533
Denis Khalikoveac01f62020-01-08 03:11:59534//===----------------------------------------------------------------------===//
Lei Zhangaaafeac2019-11-23 14:03:40535// std.select
536//===----------------------------------------------------------------------===//
537
Mahesh Ravishankar2be53602019-11-12 21:19:33538// CHECK-LABEL: @select
Lei Zhangaaafeac2019-11-23 14:03:40539func @select(%arg0 : i32, %arg1 : i32) {
Mahesh Ravishankar2be53602019-11-12 21:19:33540 %0 = cmpi "sle", %arg0, %arg1 : i32
541 // CHECK: spv.Select
542 %1 = select %0, %arg0, %arg1 : i32
543 return
544}
Denis Khalikoveac01f62020-01-08 03:11:59545
546//===----------------------------------------------------------------------===//
Lei Zhangffd45832020-03-18 13:56:38547// std load/store ops
Denis Khalikoveac01f62020-01-08 03:11:59548//===----------------------------------------------------------------------===//
549
Hanhan Wang29ad9d62020-02-21 19:39:32550// CHECK-LABEL: @load_store_zero_rank_float
551// CHECK: [[ARG0:%.*]]: !spv.ptr<!spv.struct<!spv.array<1 x f32 [4]> [0]>, StorageBuffer>,
552// CHECK: [[ARG1:%.*]]: !spv.ptr<!spv.struct<!spv.array<1 x f32 [4]> [0]>, StorageBuffer>)
553func @load_store_zero_rank_float(%arg0: memref<f32>, %arg1: memref<f32>) {
554 // CHECK: [[ZERO1:%.*]] = spv.constant 0 : i32
555 // CHECK: spv.AccessChain [[ARG0]][
556 // CHECK-SAME: [[ZERO1]], [[ZERO1]]
557 // CHECK-SAME: ] :
558 // CHECK: spv.Load "StorageBuffer" %{{.*}} : f32
559 %0 = load %arg0[] : memref<f32>
560 // CHECK: [[ZERO2:%.*]] = spv.constant 0 : i32
561 // CHECK: spv.AccessChain [[ARG1]][
562 // CHECK-SAME: [[ZERO2]], [[ZERO2]]
563 // CHECK-SAME: ] :
564 // CHECK: spv.Store "StorageBuffer" %{{.*}} : f32
565 store %0, %arg1[] : memref<f32>
566 return
567}
568
569// CHECK-LABEL: @load_store_zero_rank_int
570// CHECK: [[ARG0:%.*]]: !spv.ptr<!spv.struct<!spv.array<1 x i32 [4]> [0]>, StorageBuffer>,
571// CHECK: [[ARG1:%.*]]: !spv.ptr<!spv.struct<!spv.array<1 x i32 [4]> [0]>, StorageBuffer>)
572func @load_store_zero_rank_int(%arg0: memref<i32>, %arg1: memref<i32>) {
573 // CHECK: [[ZERO1:%.*]] = spv.constant 0 : i32
574 // CHECK: spv.AccessChain [[ARG0]][
575 // CHECK-SAME: [[ZERO1]], [[ZERO1]]
576 // CHECK-SAME: ] :
577 // CHECK: spv.Load "StorageBuffer" %{{.*}} : i32
578 %0 = load %arg0[] : memref<i32>
579 // CHECK: [[ZERO2:%.*]] = spv.constant 0 : i32
580 // CHECK: spv.AccessChain [[ARG1]][
581 // CHECK-SAME: [[ZERO2]], [[ZERO2]]
582 // CHECK-SAME: ] :
583 // CHECK: spv.Store "StorageBuffer" %{{.*}} : i32
584 store %0, %arg1[] : memref<i32>
585 return
586}
Lei Zhang67e86902020-03-18 13:55:27587
588} // end module