1 // RUN: mlir-opt %s -split-input-file -verify-diagnostics | FileCheck %s
3 func.func @correct_int_types_success() {
4 "test.int_types"() : () -> (i16, si32, ui64, i8)
5 "test.int_types"() : () -> (si16, si32, ui64, ui64)
6 "test.int_types"() : () -> (ui16, si32, ui64, si128)
12 func.func @wrong_int_type_signedness_failure() {
13 // expected-error @+1 {{result #1 must be 32-bit signed integer, but got 'ui32'}}
14 "test.int_types"() : () -> (ui16, ui32, ui64, si8)
20 func.func @wrong_int_type_signedness_failure() {
21 // expected-error @+1 {{result #2 must be 64-bit unsigned integer, but got 'si64'}}
22 "test.int_types"() : () -> (ui16, si32, si64, ui8)
28 func.func @wrong_int_type_failure() {
29 // expected-error @+1 {{result #0 must be 16-bit integer, but got 'f16'}}
30 "test.int_types"() : () -> (f16, si32, ui64, i16)
36 func.func @wrong_int_type_failure() {
37 // expected-error @+1 {{result #3 must be integer, but got 'f64'}}
38 "test.int_types"() : () -> (i16, si32, ui64, f64)
44 // CHECK-LABEL: @complex_f64_success
45 func.func @complex_f64_success() {
46 "test.complex_f64"() : () -> (complex<f64>)
52 // CHECK-LABEL: @complex_f64_tensor_success
53 func.func @complex_f64_tensor_success() {
54 "test.complex_f64_tensor"() : () -> (tensor<complex<f64>>)
60 func.func @complex_f64_failure() {
61 // expected-error@+1 {{op result #0 must be complex type with 64-bit float elements, but got 'f64'}}
62 "test.complex_f64"() : () -> (f64)
68 // CHECK-LABEL: @tuple_success
69 func.func @tuple_success() {
70 "test.tuple_32_bit"() : () -> (tuple<i32>)
76 // CHECK-LABEL: @tuple_mixed_success
77 func.func @tuple_mixed_success() {
78 "test.tuple_32_bit"() : () -> (tuple<i32, f32>)
84 func.func @tuple_empty_success() {
85 "test.tuple_32_bit"() : () -> (tuple<>)
91 func.func @tuple_wrong_type_scalar() {
92 // expected-error@+1 {{must be tuple with any combination of 32-bit signless integer or 32-bit float values}}
93 "test.tuple_32_bit"() : () -> (tuple<i64>)
99 func.func @tuple_wrong_type_tensor() {
100 // expected-error@+1 {{must be tuple with any combination of 32-bit signless integer or 32-bit float values}}
101 "test.tuple_32_bit"() : () -> (tuple<tensor<i32>>)
107 // CHECK-LABEL: @nested_tuple_empty_success
108 func.func @nested_tuple_empty_success() {
109 "test.nested_tuple_32_bit"() : () -> (tuple<>)
115 // CHECK-LABEL: @nested_tuple_one_level_success
116 func.func @nested_tuple_one_level_success() {
117 "test.nested_tuple_32_bit"() : () -> (tuple<i32>)
123 // CHECK-LABEL: @nested_tuple_multi_level_success
124 func.func @nested_tuple_multi_level_success() {
125 "test.nested_tuple_32_bit"() : () -> (tuple<i32, tuple<i32, tuple<i32>>>)
131 // CHECK-LABEL: @nested_tuple_multi_level_mixed_success
132 func.func @nested_tuple_multi_level_mixed_success() {
133 "test.nested_tuple_32_bit"() : () -> (tuple<i32, tuple<f32, tuple<i32>>>)
139 func.func @nested_tuple_multi_level_wrong_type() {
140 // expected-error@+1 {{must be nested tuple with any combination of 32-bit signless integer or 32-bit float values}}
141 "test.nested_tuple_32_bit"() : () -> (tuple<i32, tuple<i32, tuple<i64>>>)
147 // CHECK-LABEL: func @rank_less_than_2_I8_F32_memref_success
148 func.func @rank_less_than_2_I8_F32_memref_success() {
149 "test.rank_less_than_2_I8_F32_memref"() : () -> (memref<i8>)
150 "test.rank_less_than_2_I8_F32_memref"() : () -> (memref<3xi8>)
151 "test.rank_less_than_2_I8_F32_memref"() : () -> (memref<f32>)
152 "test.rank_less_than_2_I8_F32_memref"() : () -> (memref<1xf32>)
158 func.func @rank_less_than_2_I8_F32_memref_bad_type() {
159 // expected-error@+1 {{must be 0D/1D memref of 8-bit signless integer or 32-bit float values}}
160 "test.rank_less_than_2_I8_F32_memref"() : () -> (memref<i16>)
166 func.func @rank_less_than_2_I8_F32_memref_bad_rank() {
167 // expected-error@+1 {{must be 0D/1D memref of 8-bit signless integer or 32-bit float values}}
168 "test.rank_less_than_2_I8_F32_memref"() : () -> (memref<1x2xi8>)
174 func.func @nd_tensor_of_success(%arg0: tensor<f32>, %arg1: tensor<10xf32>, %arg2: tensor<20x30xi16>, %arg3: tensor<40x50x60xi16>, %arg4: tensor<70x80x90x100xi16>) {
175 "test.nd_tensor_of"(%arg0, %arg1, %arg2, %arg3, %arg4) : (tensor<f32>, tensor<10xf32>, tensor<20x30xi16>, tensor<40x50x60xi16>, tensor<70x80x90x100xi16>) -> ()
181 func.func @nd_tensor_of_success_wrong_type_0d(%arg0: tensor<f32>, %arg1: tensor<10xf32>, %arg2: tensor<20x30xi16>, %arg3: tensor<40x50x60xi16>, %arg4: tensor<70x80x90x100xi32>) {
182 // expected-error @+1 {{'test.nd_tensor_of' op operand #0 must be 0D tensor of 32-bit float values}}
183 "test.nd_tensor_of"(%arg1, %arg1, %arg2, %arg3, %arg4) : (tensor<10xf32>, tensor<10xf32>, tensor<20x30xi16>, tensor<40x50x60xi16>, tensor<70x80x90x100xi32>) -> ()
189 func.func @nd_tensor_of_success_wrong_type_4d(%arg0: tensor<f32>, %arg1: tensor<10xf32>, %arg2: tensor<20x30xi16>, %arg3: tensor<40x50x60xi16>, %arg4: tensor<70x80x90x100xi32>) {
190 // expected-error @+1 {{'test.nd_tensor_of' op operand #4 must be 4D tensor of 16-bit signless integer values}}
191 "test.nd_tensor_of"(%arg0, %arg1, %arg2, %arg3, %arg3) : (tensor<f32>, tensor<10xf32>, tensor<20x30xi16>, tensor<40x50x60xi16>, tensor<40x50x60xi16>) -> ()
197 func.func @ranked_tensor_success(%arg0: tensor<i8>, %arg1: tensor<1xi32>, %arg2: tensor<?x?xf32>) {
198 "test.ranked_tensor_op"(%arg0) : (tensor<i8>) -> ()
199 "test.ranked_tensor_op"(%arg1) : (tensor<1xi32>) -> ()
200 "test.ranked_tensor_op"(%arg2) : (tensor<?x?xf32>) -> ()
206 func.func @ranked_tensor_success(%arg0: tensor<*xf32>) {
207 // expected-error @+1 {{must be ranked tensor of any type values}}
208 "test.ranked_tensor_op"(%arg0) : (tensor<*xf32>) -> ()
214 func.func @ranked_tensor_success(%arg0: vector<2xf32>) {
215 // expected-error @+1 {{must be ranked tensor of any type values}}
216 "test.ranked_tensor_op"(%arg0) : (vector<2xf32>) -> ()
222 func.func @multi_tensor_rank_of_success(%arg0: tensor<i8>, %arg1: tensor<i32>, %arg2: tensor<f32>, %arg3: tensor<1xi8>, %arg4: tensor<1xi32>, %arg5: tensor<1xf32>) {
223 "test.multi_tensor_rank_of"(%arg0) : (tensor<i8>) -> ()
224 "test.multi_tensor_rank_of"(%arg1) : (tensor<i32>) -> ()
225 "test.multi_tensor_rank_of"(%arg2) : (tensor<f32>) -> ()
226 "test.multi_tensor_rank_of"(%arg3) : (tensor<1xi8>) -> ()
227 "test.multi_tensor_rank_of"(%arg4) : (tensor<1xi32>) -> ()
228 "test.multi_tensor_rank_of"(%arg5) : (tensor<1xf32>) -> ()
234 func.func @multi_tensor_rank_of_wrong_unranked_type(%arg0: tensor<2x2xi8>) {
235 // expected-error @+1 {{'test.multi_tensor_rank_of' op operand #0 must be 0D/1D tensor of 8-bit signless integer or 32-bit signless integer or 32-bit float values}}
236 "test.multi_tensor_rank_of"(%arg0) : (tensor<2x2xi8>) -> ()
242 func.func @multi_tensor_rank_of_wrong_element_type(%arg0: tensor<2xi16>) {
243 // expected-error @+1 {{'test.multi_tensor_rank_of' op operand #0 must be 0D/1D tensor of 8-bit signless integer or 32-bit signless integer or 32-bit float values}}
244 "test.multi_tensor_rank_of"(%arg0) : (tensor<2xi16>) -> ()
250 // CHECK-LABEL: @fixed_element_types
251 func.func @fixed_element_types(%ti32: tensor<* x i32>, %tf32: tensor<* x f32>, %mi32 : memref<2x3xi32>, %vf32 : vector<2xf32>) {
252 "test.arg_and_res_have_fixed_element_types"(%ti32, %tf32) : (tensor<* x i32>, tensor<* x f32>) -> tensor<* x i16>
253 "test.arg_and_res_have_fixed_element_types"(%mi32, %vf32) : (memref<2x3xi32>, vector<2xf32>) -> memref<1x2xi16>
259 func.func @fixed_element_types(%arg0: tensor<* x i32>, %arg1: tensor<* x f32>) {
260 // expected-error@+1 {{'res' is 16-bit signless integer}}
261 "test.arg_and_res_have_fixed_element_types"(%arg0, %arg1) : (tensor<* x i32>, tensor<* x f32>) -> tensor<* x i32>
267 func.func @fixed_element_types(%arg0: tensor<* x i32>, %arg1: tensor<* x f32>) {
268 // expected-error@+1 {{fixed type combination}}
269 "test.arg_and_res_have_fixed_element_types"(%arg1, %arg0) : (tensor<* x f32>, tensor<* x i32>) -> tensor<* x i16>
275 // CHECK-LABEL: same_element_types_success
276 func.func @same_element_types_success(%ti32: tensor<* x i32>, %i32 : i32, %mi32 : memref<2x3xi32>) {
277 "test.operands_have_same_element_type"(%ti32, %ti32): (tensor<* x i32>, tensor<* x i32>) -> ()
278 "test.operands_have_same_element_type"(%i32, %ti32): (i32, tensor<* x i32>) -> ()
279 "test.operands_have_same_element_type"(%i32, %mi32): (i32, memref<2x3xi32>) -> ()
286 func.func @same_element_types_failure(%arg0: tensor<* x i32>, %arg1: tensor<* x f32>) {
287 // expected-error@+1 {{verify that all of {x, y} have same element type}}
288 "test.operands_have_same_element_type"(%arg1, %arg0): (tensor<* x f32>, tensor<* x i32>) -> ()
294 // CHECK-LABEL: same_element_types_success
295 func.func @same_element_types_success(%ti32: tensor<* x i32>, %tf32: tensor<* x f32>) {
296 "test.operand0_and_result_have_same_element_type"(%tf32, %ti32) : (tensor<* x f32>, tensor<* x i32>) -> tensor<* x f32>
297 "test.operand0_and_result_have_same_element_type"(%tf32, %ti32) : (tensor<* x f32>, tensor<* x i32>) -> memref<2x3xf32>
298 "test.operand0_and_result_have_same_element_type"(%tf32, %ti32) : (tensor<* x f32>, tensor<* x i32>) -> f32
304 func.func @same_element_types_failure(%arg0: tensor<* x i32>, %arg1: tensor<* x f32>) {
305 // expected-error@+1 {{all of {x, res} have same element type}}
306 "test.operand0_and_result_have_same_element_type"(%arg1, %arg0) : (tensor<* x f32>, tensor<* x i32>) -> tensor<* x i32>
312 // CHECK-LABEL: same_types
313 func.func @same_types(%ti32: tensor<* x i32>, %tf32: tensor<* x f32>) {
314 "test.operands_have_same_type"(%ti32, %ti32) : (tensor<* x i32>, tensor<* x i32>) -> ()
315 "test.operand0_and_result_have_same_type"(%ti32, %tf32) : (tensor<* x i32>, tensor<* x f32>) -> tensor<* x i32>
321 func.func @same_types_failure(%ti32: tensor<* x i32>, %i32: i32) {
322 // expected-error@+1 {{all of {x, y} have same type}}
323 "test.operands_have_same_type"(%ti32, %i32) : (tensor<* x i32>, i32) -> ()
329 func.func @same_types_element_mismatch(%ti32: tensor<* x i32>, %tf32: tensor<* x f32>) {
330 // expected-error@+1 {{all of {x, y} have same type}}
331 "test.operands_have_same_type"(%ti32, %tf32) : (tensor<* x i32>, tensor<* x f32>) -> ()
337 func.func @same_types_shape_mismatch(%arg0: tensor<1x2xi32>, %arg1: tensor<2x1xi32>) {
338 // expected-error@+1 {{all of {x, y} have same type}}
339 "test.operands_have_same_type"(%arg0, %arg1) : (tensor<1x2xi32>, tensor<2x1xi32>) -> ()
345 // CHECK-LABEL: same_rank_success
346 func.func @same_rank_success(%t1xi : tensor<1xi32>, %t2xf : tensor<2xf32>, %m3xi : memref<3xi32>, %t1x2xf : tensor<1x2xf32>, %t1x2xi : tensor<1x2xi32>) {
347 "test.operands_have_same_rank"(%t1xi, %t2xf) : (tensor<1xi32>, tensor<2xf32>) -> ()
348 "test.operands_have_same_rank"(%t1xi, %m3xi) : (tensor<1xi32>, memref<3xi32>) -> ()
349 "test.operand0_and_result_have_same_rank"(%t1xi, %t1x2xf) : (tensor<1xi32>, tensor<1x2xf32>) -> (tensor<3xf32>)
350 "test.operand0_and_result_have_same_rank"(%t1x2xi, %t1x2xf) : (tensor<1x2xi32>, tensor<1x2xf32>) -> (tensor<3x3xf64>)
356 func.func @same_rank_failure(%arg0: tensor<1xi32>, %arg1: tensor<1x2xf32>) {
357 // expected-error@+1 {{all of {x, y} have same rank}}
358 "test.operands_have_same_rank"(%arg0, %arg1) : (tensor<1xi32>, tensor<1x2xf32>) -> ()
364 func.func @same_rank_failure(%arg0: tensor<1xi32>, %arg1: tensor<1x2xf32>) {
365 // expected-error@+1 {{all of {x, res} have same rank}}
366 "test.operand0_and_result_have_same_rank"(%arg0, %arg1) : (tensor<1xi32>, tensor<1x2xf32>) -> (tensor<i32>)
372 func.func @same_rank_failure(%arg0: tensor<1x2xi32>, %arg1: tensor<1x2xf32>) {
373 // expected-error@+1 {{all of {x, res} have same rank}}
374 "test.operand0_and_result_have_same_rank"(%arg0, %arg1) : (tensor<1x2xi32>, tensor<1x2xf32>) -> (tensor<3xi32>)
380 // CHECK-LABEL: same_rank_if_known_success
381 func.func @same_rank_if_known_success(%t1xi : tensor<1xi32>, %t2xf : tensor<2xf32>, %m3xi : memref<3xi32>, %t1x2xf : tensor<1x2xf32>, %tuxi : tensor<*xi32>) {
382 %0 = "test.operands_and_result_have_same_rank"(%t1xi, %t2xf) : (tensor<1xi32>, tensor<2xf32>) -> (tensor<3xf64>)
383 %1 = "test.operands_and_result_have_same_rank"(%t1xi, %m3xi) : (tensor<1xi32>, memref<3xi32>) -> (tensor<3xi64>)
384 %3 = "test.operands_and_result_have_same_rank"(%tuxi, %t2xf) : (tensor<*xi32>, tensor<2xf32>) -> (tensor<2xf32>)
385 %4 = "test.operands_and_result_have_same_rank"(%t1x2xf, %tuxi) : (tensor<1x2xf32>, tensor<*xi32>) -> (tensor<1x2xf64>)
391 func.func @same_rank_if_known_failure(%arg0: tensor<1xi32>, %arg1: tensor<1x2xf32>) {
392 // expected-error@+1 {{operands don't have matching ranks}}
393 %0 = "test.operands_and_result_have_same_rank"(%arg0, %arg1) : (tensor<1xi32>, tensor<1x2xf32>) -> (tensor<*xf32>)
399 func.func @same_rank_if_known_failure(%arg0: tensor<1xi32>, %arg1: tensor<1x2xf32>) {
400 // expected-error@+1 {{result type has different rank than operands}}
401 %0 = "test.operands_and_result_have_same_rank"(%arg1, %arg1) : (tensor<1x2xf32>, tensor<1x2xf32>) -> (tensor<1x2x3xf32>)
407 // CHECK-LABEL: same_shape_success
408 func.func @same_shape_success(%t2x3: tensor<2x3xi32>, %m2x3: memref<2x3xf32>, %v2x3 : vector<2x3xi32>, %t4x5 : tensor<4x5xi32>) {
409 "test.operand0_and_result_have_same_shape"(%t2x3, %t4x5) : (tensor<2x3xi32>, tensor<4x5xi32>) -> (tensor<2x3xf32>)
410 "test.operand0_and_result_have_same_shape"(%t2x3, %t4x5) : (tensor<2x3xi32>, tensor<4x5xi32>) -> (memref<2x3xf32>)
411 "test.operand0_and_result_have_same_shape"(%t2x3, %t4x5) : (tensor<2x3xi32>, tensor<4x5xi32>) -> (vector<2x3xf32>)
417 func.func @same_shape_failure(%t2x3: tensor<2x3xi32>, %t4x5 : tensor<4x5xi32>) {
418 // expected-error@+1 {{all of {x, res} have same shape}}
419 "test.operand0_and_result_have_same_shape"(%t2x3, %t4x5) : (tensor<2x3xi32>, tensor<4x5xi32>) -> (tensor<1x3xf32>)
425 // CHECK-LABEL: same_element_count_success
426 func.func @same_element_count_success(%arg0: tensor<36xi32>, %arg1: tensor<1x2xf32>, %arg3: tensor<f32>) {
427 "test.operand0_and_result_have_same_element_count"(%arg0, %arg1) : (tensor<36xi32>, tensor<1x2xf32>) -> (tensor<3x4x3xf32>)
428 "test.operand0_and_result_have_same_element_count"(%arg0, %arg1) : (tensor<36xi32>, tensor<1x2xf32>) -> (tensor<3x12xf64>)
429 "test.operand0_and_result_have_same_element_count"(%arg3, %arg1) : (tensor<f32>, tensor<1x2xf32>) -> (memref<1x1x1xi32>)
435 func.func @same_element_count_failure(%arg0: tensor<1xi32>, %arg1: tensor<1x2xf32>) {
436 // expected-error@+1 {{all of {x, res} have same element count}}
437 "test.operand0_and_result_have_same_element_count"(%arg0, %arg1) : (tensor<1xi32>, tensor<1x2xf32>) -> (tensor<2xi32>)
443 func.func @four_equals_five() {
444 // expected-error@+1 {{failed to verify that 4 equals 5}}
445 "test.four_equals_five"() : () -> ()
451 func.func @operand_rank_equals_result_size_success(%arg : tensor<1x2x3x4xi32>) {
452 "test.operand_rank_equals_result_size"(%arg) : (tensor<1x2x3x4xi32>) -> tensor<4xi32>
453 "test.operand_rank_equals_result_size"(%arg) : (tensor<1x2x3x4xi32>) -> memref<2x2xf32>
459 func.func @operand_rank_equals_result_size_failure(%arg : tensor<1x2x3x4xi32>) {
460 // expected-error@+1 {{failed to verify that operand rank equals result size}}
461 "test.operand_rank_equals_result_size"(%arg) : (tensor<1x2x3x4xi32>) -> tensor<2xi32>
467 func.func @same_types_element_mismatch(%arg0: tensor<* x i32>, %arg1: tensor<* x f32>) {
468 // expected-error@+1 {{op failed to verify that all of {x, res} have same type}}
469 "test.operand0_and_result_have_same_type"(%arg0, %arg1) : (tensor<* x i32>, tensor<* x f32>) -> tensor<* x f32>
475 func.func @same_types_shape_mismatch(%arg0: tensor<1x2xi32>, %arg1: tensor<2x1xi32>) {
476 // expected-error@+1 {{op failed to verify that all of {x, res} have same type}}
477 "test.operand0_and_result_have_same_type"(%arg0, %arg1) : (tensor<1x2xi32>, tensor<2x1xi32>) -> tensor<2x1xi32>
483 func.func @does_not_have_i32(%arg0: tensor<1x2xi32>, %arg1: none) {
484 // expected-error@+1 {{either both none type operands or first is not none}}
485 "test.if_first_operand_is_none_then_so_is_second"(%arg1, %arg0) : (none, tensor<1x2xi32>) -> ()
491 func.func @does_not_have_static_memref(%arg0: memref<?xi32>) {
492 // expected-error@+1 {{'test.takes_static_memref' op operand #0 must be statically shaped memref of any type values}}
493 "test.takes_static_memref"(%arg0) : (memref<?xi32>) -> ()
498 func.func @elements_attr_not_i32_f32() {
499 // expected-error@+1 {{32-bit signless integer elements attribute}}
500 "test.i32ElementsAttr"() {attr = dense<[1.0, 20.0]>:tensor<2xf32>} : () -> ()
506 func.func @elements_attr_not_i32_i64() {
507 // expected-error@+1 {{32-bit signless integer elements attribute}}
508 "test.i32ElementsAttr"() {attr = dense<[1, 20]>:tensor<2xi64>} : () -> ()
515 func.func @elements_attr_i32(%arg0: tensor<1x2xi32>) {
516 "test.i32ElementsAttr"() {attr = dense<[1, 2]>:tensor<2xi32>} : () -> ()
522 func.func @elements_attr_index() {
523 "test.indexElementsAttr"() {attr = dense<[1, 2]>:tensor<2xindex>} : () -> ()
529 func.func @elements_attr_not_index() {
530 // expected-error@+1 {{index elements attribute}}
531 "test.indexElementsAttr"() {attr = dense<[1, 2]>:tensor<2xi32>} : () -> ()
537 // CHECK-LABEL: @struct_success
538 func.func @struct_success() {
539 "test.simple_struct"() : () -> (!test.struct<{a, i32}, {b, f64}>)
545 // CHECK-LABEL: @struct_with_field_names_like_types
546 func.func @struct_with_field_names_like_types() {
547 "test.struct_with_field_names_like_types"() : () -> (!test.struct<{i32, i32}, {f64, f64}>)
553 func.func @struct_bad_keywords() {
554 // expected-error@+1 {{expected valid keyword}}
555 "test.struct_bad_keywords"() : () -> (!test.struct<{42, i32}>)