1 // RUN: mlir-opt -split-input-file -verify-diagnostics %s | FileCheck %s
3 //===----------------------------------------------------------------------===//
5 //===----------------------------------------------------------------------===//
7 func.func @fadd_scalar(%arg: f32) -> f32 {
9 %0 = spirv.FAdd %arg, %arg : f32
15 //===----------------------------------------------------------------------===//
17 //===----------------------------------------------------------------------===//
19 func.func @fdiv_scalar(%arg: f32) -> f32 {
21 %0 = spirv.FDiv %arg, %arg : f32
27 //===----------------------------------------------------------------------===//
29 //===----------------------------------------------------------------------===//
31 func.func @fmod_scalar(%arg: f32) -> f32 {
33 %0 = spirv.FMod %arg, %arg : f32
39 //===----------------------------------------------------------------------===//
41 //===----------------------------------------------------------------------===//
43 func.func @fmul_scalar(%arg: f32) -> f32 {
45 %0 = spirv.FMul %arg, %arg : f32
49 func.func @fmul_vector(%arg: vector<4xf32>) -> vector<4xf32> {
51 %0 = spirv.FMul %arg, %arg : vector<4xf32>
52 return %0 : vector<4xf32>
57 func.func @fmul_i32(%arg: i32) -> i32 {
58 // expected-error @+1 {{operand #0 must be 16/32/64-bit float or vector of 16/32/64-bit float values}}
59 %0 = spirv.FMul %arg, %arg : i32
65 func.func @fmul_bf16(%arg: bf16) -> bf16 {
66 // expected-error @+1 {{operand #0 must be 16/32/64-bit float or vector of 16/32/64-bit float values}}
67 %0 = spirv.FMul %arg, %arg : bf16
73 func.func @fmul_tensor(%arg: tensor<4xf32>) -> tensor<4xf32> {
74 // expected-error @+1 {{operand #0 must be 16/32/64-bit float or vector of 16/32/64-bit float values}}
75 %0 = spirv.FMul %arg, %arg : tensor<4xf32>
76 return %0 : tensor<4xf32>
81 //===----------------------------------------------------------------------===//
83 //===----------------------------------------------------------------------===//
85 func.func @fnegate_scalar(%arg: f32) -> f32 {
86 // CHECK: spirv.FNegate
87 %0 = spirv.FNegate %arg : f32
93 //===----------------------------------------------------------------------===//
95 //===----------------------------------------------------------------------===//
97 func.func @frem_scalar(%arg: f32) -> f32 {
99 %0 = spirv.FRem %arg, %arg : f32
105 //===----------------------------------------------------------------------===//
107 //===----------------------------------------------------------------------===//
109 func.func @fsub_scalar(%arg: f32) -> f32 {
111 %0 = spirv.FSub %arg, %arg : f32
117 //===----------------------------------------------------------------------===//
119 //===----------------------------------------------------------------------===//
121 func.func @iadd_scalar(%arg: i32) -> i32 {
123 %0 = spirv.IAdd %arg, %arg : i32
129 //===----------------------------------------------------------------------===//
131 //===----------------------------------------------------------------------===//
133 func.func @imul_scalar(%arg: i32) -> i32 {
135 %0 = spirv.IMul %arg, %arg : i32
141 //===----------------------------------------------------------------------===//
143 //===----------------------------------------------------------------------===//
145 func.func @isub_scalar(%arg: i32) -> i32 {
147 %0 = spirv.ISub %arg, %arg : i32
153 //===----------------------------------------------------------------------===//
155 //===----------------------------------------------------------------------===//
157 // CHECK-LABEL: @iadd_carry_scalar
158 func.func @iadd_carry_scalar(%arg: i32) -> !spirv.struct<(i32, i32)> {
159 // CHECK: spirv.IAddCarry %{{.+}}, %{{.+}} : !spirv.struct<(i32, i32)>
160 %0 = spirv.IAddCarry %arg, %arg : !spirv.struct<(i32, i32)>
161 return %0 : !spirv.struct<(i32, i32)>
164 // CHECK-LABEL: @iadd_carry_vector
165 func.func @iadd_carry_vector(%arg: vector<3xi32>) -> !spirv.struct<(vector<3xi32>, vector<3xi32>)> {
166 // CHECK: spirv.IAddCarry %{{.+}}, %{{.+}} : !spirv.struct<(vector<3xi32>, vector<3xi32>)>
167 %0 = spirv.IAddCarry %arg, %arg : !spirv.struct<(vector<3xi32>, vector<3xi32>)>
168 return %0 : !spirv.struct<(vector<3xi32>, vector<3xi32>)>
173 func.func @iadd_carry(%arg: i32) -> !spirv.struct<(i32, i32, i32)> {
174 // expected-error @+1 {{expected spirv.struct type with two members}}
175 %0 = spirv.IAddCarry %arg, %arg : !spirv.struct<(i32, i32, i32)>
176 return %0 : !spirv.struct<(i32, i32, i32)>
181 func.func @iadd_carry(%arg: i32) -> !spirv.struct<(i32)> {
182 // expected-error @+1 {{expected result struct type containing two members}}
183 %0 = "spirv.IAddCarry"(%arg, %arg): (i32, i32) -> !spirv.struct<(i32)>
184 return %0 : !spirv.struct<(i32)>
189 func.func @iadd_carry(%arg: i32) -> !spirv.struct<(i32, i64)> {
190 // expected-error @+1 {{expected all operand types and struct member types are the same}}
191 %0 = "spirv.IAddCarry"(%arg, %arg): (i32, i32) -> !spirv.struct<(i32, i64)>
192 return %0 : !spirv.struct<(i32, i64)>
197 func.func @iadd_carry(%arg: i64) -> !spirv.struct<(i32, i32)> {
198 // expected-error @+1 {{expected all operand types and struct member types are the same}}
199 %0 = "spirv.IAddCarry"(%arg, %arg): (i64, i64) -> !spirv.struct<(i32, i32)>
200 return %0 : !spirv.struct<(i32, i32)>
205 //===----------------------------------------------------------------------===//
207 //===----------------------------------------------------------------------===//
209 // CHECK-LABEL: @isub_borrow_scalar
210 func.func @isub_borrow_scalar(%arg: i32) -> !spirv.struct<(i32, i32)> {
211 // CHECK: spirv.ISubBorrow %{{.+}}, %{{.+}} : !spirv.struct<(i32, i32)>
212 %0 = spirv.ISubBorrow %arg, %arg : !spirv.struct<(i32, i32)>
213 return %0 : !spirv.struct<(i32, i32)>
216 // CHECK-LABEL: @isub_borrow_vector
217 func.func @isub_borrow_vector(%arg: vector<3xi32>) -> !spirv.struct<(vector<3xi32>, vector<3xi32>)> {
218 // CHECK: spirv.ISubBorrow %{{.+}}, %{{.+}} : !spirv.struct<(vector<3xi32>, vector<3xi32>)>
219 %0 = spirv.ISubBorrow %arg, %arg : !spirv.struct<(vector<3xi32>, vector<3xi32>)>
220 return %0 : !spirv.struct<(vector<3xi32>, vector<3xi32>)>
225 func.func @isub_borrow(%arg: i32) -> !spirv.struct<(i32, i32, i32)> {
226 // expected-error @+1 {{expected spirv.struct type with two members}}
227 %0 = spirv.ISubBorrow %arg, %arg : !spirv.struct<(i32, i32, i32)>
228 return %0 : !spirv.struct<(i32, i32, i32)>
233 func.func @isub_borrow(%arg: i32) -> !spirv.struct<(i32)> {
234 // expected-error @+1 {{expected result struct type containing two members}}
235 %0 = "spirv.ISubBorrow"(%arg, %arg): (i32, i32) -> !spirv.struct<(i32)>
236 return %0 : !spirv.struct<(i32)>
241 func.func @isub_borrow(%arg: i32) -> !spirv.struct<(i32, i64)> {
242 // expected-error @+1 {{expected all operand types and struct member types are the same}}
243 %0 = "spirv.ISubBorrow"(%arg, %arg): (i32, i32) -> !spirv.struct<(i32, i64)>
244 return %0 : !spirv.struct<(i32, i64)>
249 func.func @isub_borrow(%arg: i64) -> !spirv.struct<(i32, i32)> {
250 // expected-error @+1 {{expected all operand types and struct member types are the same}}
251 %0 = "spirv.ISubBorrow"(%arg, %arg): (i64, i64) -> !spirv.struct<(i32, i32)>
252 return %0 : !spirv.struct<(i32, i32)>
257 //===----------------------------------------------------------------------===//
259 //===----------------------------------------------------------------------===//
261 func.func @dot(%arg0: vector<4xf32>, %arg1: vector<4xf32>) -> f32 {
262 %0 = spirv.Dot %arg0, %arg1 : vector<4xf32> -> f32
268 // expected-note @+1 {{prior use here}}
269 func.func @dot(%arg0: vector<4xf32>, %arg1: vector<3xf32>) -> f32 {
270 // expected-error @+1 {{use of value '%arg1' expects different type than prior uses}}
271 %0 = spirv.Dot %arg0, %arg1 : vector<4xf32> -> f32
277 func.func @dot(%arg0: vector<4xf32>, %arg1: vector<4xf32>) -> f16 {
278 // expected-error @+1 {{'spirv.Dot' op failed to verify that all of {vector1, result} have same element type}}
279 %0 = spirv.Dot %arg0, %arg1 : vector<4xf32> -> f16
285 func.func @dot(%arg0: vector<4xi32>, %arg1: vector<4xi32>) -> i32 {
286 // expected-error @+1 {{'spirv.Dot' op operand #0 must be vector of 16/32/64-bit float values of length 2/3/4/8/16}}
287 %0 = spirv.Dot %arg0, %arg1 : vector<4xi32> -> i32
293 //===----------------------------------------------------------------------===//
294 // spirv.SMulExtended
295 //===----------------------------------------------------------------------===//
297 // CHECK-LABEL: @smul_extended_scalar
298 func.func @smul_extended_scalar(%arg: i32) -> !spirv.struct<(i32, i32)> {
299 // CHECK: spirv.SMulExtended %{{.+}}, %{{.+}} : !spirv.struct<(i32, i32)>
300 %0 = spirv.SMulExtended %arg, %arg : !spirv.struct<(i32, i32)>
301 return %0 : !spirv.struct<(i32, i32)>
304 // CHECK-LABEL: @smul_extended_vector
305 func.func @smul_extended_vector(%arg: vector<3xi32>) -> !spirv.struct<(vector<3xi32>, vector<3xi32>)> {
306 // CHECK: spirv.SMulExtended %{{.+}}, %{{.+}} : !spirv.struct<(vector<3xi32>, vector<3xi32>)>
307 %0 = spirv.SMulExtended %arg, %arg : !spirv.struct<(vector<3xi32>, vector<3xi32>)>
308 return %0 : !spirv.struct<(vector<3xi32>, vector<3xi32>)>
313 func.func @smul_extended(%arg: i32) -> !spirv.struct<(i32, i32, i32)> {
314 // expected-error @+1 {{expected spirv.struct type with two members}}
315 %0 = spirv.SMulExtended %arg, %arg : !spirv.struct<(i32, i32, i32)>
316 return %0 : !spirv.struct<(i32, i32, i32)>
321 func.func @smul_extended(%arg: i32) -> !spirv.struct<(i32)> {
322 // expected-error @+1 {{expected result struct type containing two members}}
323 %0 = "spirv.SMulExtended"(%arg, %arg): (i32, i32) -> !spirv.struct<(i32)>
324 return %0 : !spirv.struct<(i32)>
329 func.func @smul_extended(%arg: i32) -> !spirv.struct<(i32, i64)> {
330 // expected-error @+1 {{expected all operand types and struct member types are the same}}
331 %0 = "spirv.SMulExtended"(%arg, %arg): (i32, i32) -> !spirv.struct<(i32, i64)>
332 return %0 : !spirv.struct<(i32, i64)>
337 func.func @smul_extended(%arg: i64) -> !spirv.struct<(i32, i32)> {
338 // expected-error @+1 {{expected all operand types and struct member types are the same}}
339 %0 = "spirv.SMulExtended"(%arg, %arg): (i64, i64) -> !spirv.struct<(i32, i32)>
340 return %0 : !spirv.struct<(i32, i32)>
345 //===----------------------------------------------------------------------===//
346 // spirv.UMulExtended
347 //===----------------------------------------------------------------------===//
349 // CHECK-LABEL: @umul_extended_scalar
350 func.func @umul_extended_scalar(%arg: i32) -> !spirv.struct<(i32, i32)> {
351 // CHECK: spirv.UMulExtended %{{.+}}, %{{.+}} : !spirv.struct<(i32, i32)>
352 %0 = spirv.UMulExtended %arg, %arg : !spirv.struct<(i32, i32)>
353 return %0 : !spirv.struct<(i32, i32)>
356 // CHECK-LABEL: @umul_extended_vector
357 func.func @umul_extended_vector(%arg: vector<3xi32>) -> !spirv.struct<(vector<3xi32>, vector<3xi32>)> {
358 // CHECK: spirv.UMulExtended %{{.+}}, %{{.+}} : !spirv.struct<(vector<3xi32>, vector<3xi32>)>
359 %0 = spirv.UMulExtended %arg, %arg : !spirv.struct<(vector<3xi32>, vector<3xi32>)>
360 return %0 : !spirv.struct<(vector<3xi32>, vector<3xi32>)>
365 func.func @umul_extended(%arg: i32) -> !spirv.struct<(i32, i32, i32)> {
366 // expected-error @+1 {{expected spirv.struct type with two members}}
367 %0 = spirv.UMulExtended %arg, %arg : !spirv.struct<(i32, i32, i32)>
368 return %0 : !spirv.struct<(i32, i32, i32)>
373 func.func @umul_extended(%arg: i32) -> !spirv.struct<(i32)> {
374 // expected-error @+1 {{expected result struct type containing two members}}
375 %0 = "spirv.UMulExtended"(%arg, %arg): (i32, i32) -> !spirv.struct<(i32)>
376 return %0 : !spirv.struct<(i32)>
381 func.func @umul_extended(%arg: i32) -> !spirv.struct<(i32, i64)> {
382 // expected-error @+1 {{expected all operand types and struct member types are the same}}
383 %0 = "spirv.UMulExtended"(%arg, %arg): (i32, i32) -> !spirv.struct<(i32, i64)>
384 return %0 : !spirv.struct<(i32, i64)>
389 func.func @umul_extended(%arg: i64) -> !spirv.struct<(i32, i32)> {
390 // expected-error @+1 {{expected all operand types and struct member types are the same}}
391 %0 = "spirv.UMulExtended"(%arg, %arg): (i64, i64) -> !spirv.struct<(i32, i32)>
392 return %0 : !spirv.struct<(i32, i32)>
397 //===----------------------------------------------------------------------===//
399 //===----------------------------------------------------------------------===//
401 func.func @sdiv_scalar(%arg: i32) -> i32 {
403 %0 = spirv.SDiv %arg, %arg : i32
409 //===----------------------------------------------------------------------===//
411 //===----------------------------------------------------------------------===//
413 func.func @smod_scalar(%arg: i32) -> i32 {
415 %0 = spirv.SMod %arg, %arg : i32
421 //===----------------------------------------------------------------------===//
423 //===----------------------------------------------------------------------===//
425 func.func @snegate_scalar(%arg: i32) -> i32 {
426 // CHECK: spirv.SNegate
427 %0 = spirv.SNegate %arg : i32
432 //===----------------------------------------------------------------------===//
434 //===----------------------------------------------------------------------===//
436 func.func @srem_scalar(%arg: i32) -> i32 {
438 %0 = spirv.SRem %arg, %arg : i32
444 //===----------------------------------------------------------------------===//
446 //===----------------------------------------------------------------------===//
448 func.func @udiv_scalar(%arg: i32) -> i32 {
450 %0 = spirv.UDiv %arg, %arg : i32
456 //===----------------------------------------------------------------------===//
458 //===----------------------------------------------------------------------===//
460 func.func @umod_scalar(%arg: i32) -> i32 {
462 %0 = spirv.UMod %arg, %arg : i32
467 //===----------------------------------------------------------------------===//
468 // spirv.VectorTimesScalar
469 //===----------------------------------------------------------------------===//
471 func.func @vector_times_scalar(%vector: vector<4xf32>, %scalar: f32) -> vector<4xf32> {
472 // CHECK: spirv.VectorTimesScalar %{{.+}}, %{{.+}} : (vector<4xf32>, f32) -> vector<4xf32>
473 %0 = spirv.VectorTimesScalar %vector, %scalar : (vector<4xf32>, f32) -> vector<4xf32>
474 return %0 : vector<4xf32>
479 func.func @vector_times_scalar(%vector: vector<4xf32>, %scalar: f16) -> vector<4xf32> {
480 // expected-error @+1 {{scalar operand and result element type match}}
481 %0 = spirv.VectorTimesScalar %vector, %scalar : (vector<4xf32>, f16) -> vector<4xf32>
482 return %0 : vector<4xf32>
487 func.func @vector_times_scalar(%vector: vector<4xf32>, %scalar: f32) -> vector<3xf32> {
488 // expected-error @+1 {{vector operand and result type mismatch}}
489 %0 = spirv.VectorTimesScalar %vector, %scalar : (vector<4xf32>, f32) -> vector<3xf32>
490 return %0 : vector<3xf32>