558 lines · plain
1// RUN: mlir-opt %s -split-input-file -verify-diagnostics | FileCheck %s2 3func.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)7 return8}9 10// -----11 12func.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)15 return16}17 18// -----19 20func.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)23 return24}25 26// -----27 28func.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)31 return32}33 34// -----35 36func.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)39 return40}41 42// -----43 44// CHECK-LABEL: @complex_f64_success45func.func @complex_f64_success() {46 "test.complex_f64"() : () -> (complex<f64>)47 return48}49 50// -----51 52// CHECK-LABEL: @complex_f64_tensor_success53func.func @complex_f64_tensor_success() {54 "test.complex_f64_tensor"() : () -> (tensor<complex<f64>>)55 return56}57 58// -----59 60func.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)63 return64}65 66// -----67 68// CHECK-LABEL: @tuple_success69func.func @tuple_success() {70 "test.tuple_32_bit"() : () -> (tuple<i32>)71 return72}73 74// -----75 76// CHECK-LABEL: @tuple_mixed_success77func.func @tuple_mixed_success() {78 "test.tuple_32_bit"() : () -> (tuple<i32, f32>)79 return80}81 82// -----83 84func.func @tuple_empty_success() {85 "test.tuple_32_bit"() : () -> (tuple<>)86 return87}88 89// -----90 91func.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>)94 return95}96 97// -----98 99func.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>>)102 return103}104 105// -----106 107// CHECK-LABEL: @nested_tuple_empty_success108func.func @nested_tuple_empty_success() {109 "test.nested_tuple_32_bit"() : () -> (tuple<>)110 return111}112 113// -----114 115// CHECK-LABEL: @nested_tuple_one_level_success116func.func @nested_tuple_one_level_success() {117 "test.nested_tuple_32_bit"() : () -> (tuple<i32>)118 return119}120 121// -----122 123// CHECK-LABEL: @nested_tuple_multi_level_success124func.func @nested_tuple_multi_level_success() {125 "test.nested_tuple_32_bit"() : () -> (tuple<i32, tuple<i32, tuple<i32>>>)126 return127}128 129// -----130 131// CHECK-LABEL: @nested_tuple_multi_level_mixed_success132func.func @nested_tuple_multi_level_mixed_success() {133 "test.nested_tuple_32_bit"() : () -> (tuple<i32, tuple<f32, tuple<i32>>>)134 return135}136 137// -----138 139func.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>>>)142 return143}144 145// -----146 147// CHECK-LABEL: func @rank_less_than_2_I8_F32_memref_success148func.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>)153 return154}155 156// -----157 158func.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>)161 return162}163 164// -----165 166func.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>)169 return170}171 172// -----173 174func.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>) -> ()176 return177}178 179// -----180 181func.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>) -> ()184 return185}186 187// -----188 189func.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>) -> ()192 return193}194 195// -----196 197func.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>) -> ()201 return202}203 204// -----205 206func.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>) -> ()209 return210}211 212// -----213 214func.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>) -> ()217 return218}219 220// -----221 222func.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>) -> ()229 return230}231 232// -----233 234func.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>) -> ()237 return238}239 240// -----241 242func.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>) -> ()245 return246}247 248// -----249 250// CHECK-LABEL: @fixed_element_types251func.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>254 return255}256 257// -----258 259func.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>262 return263}264 265// -----266 267func.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>270 return271}272 273// -----274 275// CHECK-LABEL: same_element_types_success276func.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>) -> ()280 return281}282 283 284// -----285 286func.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>) -> ()289 return290}291 292// -----293 294// CHECK-LABEL: same_element_types_success295func.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>) -> f32299 return300}301 302// -----303 304func.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>307 return308}309 310// -----311 312// CHECK-LABEL: same_types313func.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>316 return317}318 319// -----320 321func.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) -> ()324 return325}326 327// -----328 329func.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>) -> ()332 return333}334 335// -----336 337func.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>) -> ()340 return341}342 343// -----344 345// CHECK-LABEL: same_rank_success346func.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>)351 return352}353 354// -----355 356func.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>) -> ()359 return360}361 362// -----363 364func.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>)367 return368}369 370// -----371 372func.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>)375 return376}377 378// -----379 380// CHECK-LABEL: same_rank_if_known_success381func.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>)386 return387}388 389// -----390 391func.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>)394 return395}396 397// -----398 399func.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>)402 return403}404 405// -----406 407// CHECK-LABEL: same_shape_success408func.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>)412 return413}414 415// -----416 417func.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>)420 return421}422 423// -----424 425// CHECK-LABEL: same_element_count_success426func.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>)430 return431}432 433// -----434 435func.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>)438 return439}440 441// -----442 443func.func @four_equals_five() {444 // expected-error@+1 {{failed to verify that 4 equals 5}}445 "test.four_equals_five"() : () -> ()446 return447}448 449// -----450 451func.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>454 return455}456 457// -----458 459func.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>462 return463}464 465// -----466 467func.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>470 return471}472 473// -----474 475func.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>478 return479}480 481// -----482 483func.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>) -> ()486 return487}488 489// -----490 491func.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>) -> ()494}495 496// -----497 498func.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>} : () -> ()501 return502}503 504// -----505 506func.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>} : () -> ()509 return510}511 512 513// -----514 515func.func @elements_attr_i32(%arg0: tensor<1x2xi32>) {516 "test.i32ElementsAttr"() {attr = dense<[1, 2]>:tensor<2xi32>} : () -> ()517 return518}519 520// -----521 522func.func @elements_attr_index() {523 "test.indexElementsAttr"() {attr = dense<[1, 2]>:tensor<2xindex>} : () -> ()524 return525}526 527// -----528 529func.func @elements_attr_not_index() {530 // expected-error@+1 {{index elements attribute}}531 "test.indexElementsAttr"() {attr = dense<[1, 2]>:tensor<2xi32>} : () -> ()532 return533}534 535// -----536 537// CHECK-LABEL: @struct_success538func.func @struct_success() {539 "test.simple_struct"() : () -> (!test.struct<{a, i32}, {b, f64}>)540 return541}542 543// -----544 545// CHECK-LABEL: @struct_with_field_names_like_types546func.func @struct_with_field_names_like_types() {547 "test.struct_with_field_names_like_types"() : () -> (!test.struct<{i32, i32}, {f64, f64}>)548 return549}550 551// -----552 553func.func @struct_bad_keywords() {554 // expected-error@+1 {{expected valid keyword}}555 "test.struct_bad_keywords"() : () -> (!test.struct<{42, i32}>)556 return557}558