684 lines · plain
1// RUN: mlir-opt %s -split-input-file -verify-diagnostics2 3// Asking the dimension of a 0-D shape doesn't make sense.4func.func @dim_0_ranked(%arg : tensor<f32>, %arg1 : index) {5 tensor.dim %arg, %arg1 : tensor<f32> // expected-error {{'tensor.dim' op operand #0 must be non-0-ranked or unranked tensor, but got 'tensor<f32>'}}6 return7}8 9// -----10 11func.func @tensor.cast_mismatching_constants(%arg0: tensor<1xf32>) {12 // expected-error@+1 {{operand type 'tensor<1xf32>' and result type 'tensor<2xf32>' are cast incompatible}}13 %0 = tensor.cast %arg0 : tensor<1xf32> to tensor<2xf32>14 return15}16 17// -----18 19func.func @concat_empty() {20 // expected-error@+1 {{requires at least one input}}21 %0 = tensor.concat dim(0) : () -> tensor<1x2x3xf32>22 return23}24 25// -----26 27func.func @concat_rank_mismatch(%arg0: tensor<1xf32>, %arg1: tensor<1xf32>) {28 // expected-error@+1 {{rank of concatenated inputs must match result rank}}29 %0 = tensor.concat dim(0) %arg0, %arg1 : (tensor<1xf32>, tensor<1xf32>) -> tensor<2x1xf32>30 return31}32 33// -----34 35func.func @concat_dim_out_of_range(%arg0: tensor<3xf32>) {36 // expected-error@+1 {{concatenation dim must be less than the tensor rank}}37 %0 = tensor.concat dim(1) %arg0 : (tensor<3xf32>) -> tensor<3xf32>38 return39}40 41// -----42 43func.func @concat_element_type_mismatch(%arg0: tensor<3xf32>, %arg1: tensor<3xi32>) {44 // expected-error@+1 {{inputs and result element type must match}}45 %0 = tensor.concat dim(0) %arg0, %arg1 : (tensor<3xf32>, tensor<3xi32>) -> tensor<3xf32>46 return47}48 49// -----50 51func.func @concat_incompatible_input_types(%arg0: tensor<3x4xf32>, %arg1: tensor<4x5xf32>) {52 // expected-error@+1 {{static concatenation size mismatch along non-concatenated dimension 1}}53 %0 = tensor.concat dim(0) %arg0, %arg1 : (tensor<3x4xf32>, tensor<4x5xf32>) -> tensor<7x5xf32>54 return55}56 57// -----58 59func.func @concat_static_shape_mismatch(%arg0: tensor<3xf32>) {60 // expected-error@+1 {{result type 'tensor<7xf32>'does not match inferred shape 'tensor<6xf32>' static sizes}}61 %0 = tensor.concat dim(0) %arg0, %arg0 : (tensor<3xf32>, tensor<3xf32>) -> tensor<7xf32>62 return63}64 65// -----66 67func.func @extract_too_many_indices(%arg0: tensor<?xf32>) {68 // expected-error@+1 {{incorrect number of indices for extract_element}}69 %0 = tensor.extract %arg0[] : tensor<?xf32>70 return71}72 73// -----74 75func.func @insert_too_many_indices(%arg0: f32, %arg1: tensor<?xf32>) {76 // expected-error@+1 {{incorrect number of indices}}77 %0 = tensor.insert %arg0 into %arg1[] : tensor<?xf32>78 return79}80 81// -----82 83func.func @tensor.from_elements_wrong_result_type() {84 // expected-error@+2 {{'tensor.from_elements' invalid kind of type specified: expected builtin.tensor, but found 'tensor<*xi32>'}}85 %c0 = arith.constant 0 : i3286 %0 = tensor.from_elements %c0 : tensor<*xi32>87 return88}89 90// -----91 92func.func @tensor.from_elements_wrong_elements_count() {93 // expected-error@+2 {{number of operands and types do not match: got 1 operands and 2 types}}94 %c0 = arith.constant 0 : index95 %0 = tensor.from_elements %c0 : tensor<2xindex>96 return97}98 99// -----100 101func.func @tensor.generate(%m : index)102 -> tensor<?x3x?xf32> {103 // expected-error @+1 {{must have as many index operands as dynamic extents in the result type}}104 %tnsr = tensor.generate %m {105 ^bb0(%i : index, %j : index, %k : index):106 %elem = arith.constant 8.0 : f32107 tensor.yield %elem : f32108 } : tensor<?x3x?xf32>109 return %tnsr : tensor<?x3x?xf32>110}111 112// -----113 114func.func @tensor.generate(%m : index, %n : index)115 -> tensor<?x3x?xf32> {116 // expected-error @+1 {{must have one body argument per input dimension}}117 %tnsr = tensor.generate %m, %n {118 ^bb0(%i : index, %j : index):119 %elem = arith.constant 8.0 : f32120 tensor.yield %elem : f32121 } : tensor<?x3x?xf32>122 return %tnsr : tensor<?x3x?xf32>123}124 125// -----126 127func.func @tensor.generate(%m : index, %n : index)128 -> tensor<?x3x?xf32> {129 // expected-error @+1 {{all body arguments must be index}}130 %tnsr = tensor.generate %m, %n {131 ^bb0(%i : index, %j : index, %k : i64):132 %elem = arith.constant 8.0 : f32133 tensor.yield %elem : f32134 } : tensor<?x3x?xf32>135 return %tnsr : tensor<?x3x?xf32>136}137 138// -----139 140func.func @tensor.generate(%m : index, %n : index)141 -> tensor<?x3x?xf32> {142 // expected-error @+4 {{'func.return' op expects parent op 'func.func'}}143 %tnsr = tensor.generate %m, %n {144 ^bb0(%i : index, %j : index, %k : index):145 %elem = arith.constant 8.0 : f32146 func.return %elem : f32147 } : tensor<?x3x?xf32>148 return %tnsr : tensor<?x3x?xf32>149}150 151// -----152 153func.func @tensor.generate(%m : index, %n : index)154 -> tensor<?x3x?xf32> {155 // expected-error @+1 {{body must be terminated with a `yield` operation of the tensor element type}}156 %tnsr = tensor.generate %m, %n {157 ^bb0(%i : index, %j : index, %k : index):158 %elem = arith.constant 8 : i32159 tensor.yield %elem : i32160 } : tensor<?x3x?xf32>161 return %tnsr : tensor<?x3x?xf32>162}163 164// -----165 166func.func @tensor.reshape_element_type_mismatch(167 %buf: tensor<*xf32>, %shape: tensor<1xi32>) {168 // expected-error @+1 {{element types of source and destination tensor types should be the same}}169 tensor.reshape %buf(%shape) : (tensor<*xf32>, tensor<1xi32>) -> tensor<?xi32>170}171 172// -----173 174func.func @tensor.reshape_dst_ranked_shape_unranked(175 %buf: tensor<*xf32>, %shape: tensor<?xi32>) {176 // expected-error @+1 {{cannot use shape operand with dynamic length to reshape to statically-ranked tensor type}}177 tensor.reshape %buf(%shape) : (tensor<*xf32>, tensor<?xi32>) -> tensor<?xf32>178}179 180// -----181 182func.func @tensor.reshape_dst_shape_rank_mismatch(183 %buf: tensor<*xf32>, %shape: tensor<1xi32>) {184 // expected-error @+1 {{length of shape operand differs from the result's tensor rank}}185 tensor.reshape %buf(%shape)186 : (tensor<*xf32>, tensor<1xi32>) -> tensor<?x?xf32>187}188 189// -----190 191func.func @tensor.reshape_num_elements_mismatch(192 %buf: tensor<1xf32>, %shape: tensor<1xi32>) {193 // expected-error @+1 {{source and destination tensor should have the same number of elements}}194 tensor.reshape %buf(%shape)195 : (tensor<1xf32>, tensor<1xi32>) -> tensor<10xf32>196}197 198// -----199 200func.func @extract_slice_wrong_result_rank(%t: tensor<?xf32>, %idx : index) {201 // expected-error @+1 {{expected rank to be smaller or equal to the other rank.}}202 %0 = tensor.extract_slice %t[0][4][1] : tensor<?xf32> to tensor<?x?xf32>203 return204}205 206// -----207 208func.func @extract_slice_wrong_result_rank(%t: tensor<?xf32>, %idx : index) {209 // expected-error @+1 {{expected element type to be 'f32'}}210 %0 = tensor.extract_slice %t[0][4][1] : tensor<?xf32> to tensor<4xi8>211 return212}213 214 215// -----216 217func.func @extract_slice_size_and_output_dim_mismatch_static_size(%t: tensor<16xf32>) {218 // expected-error @+1 {{expected type to be 'tensor<4xf32>' or a rank-reduced version. (size mismatch)}}219 %0 = tensor.extract_slice %t[0][4][1]220 : tensor<16xf32> to tensor<6xf32>221 return222}223 224// -----225 226func.func @extract_slice_size_and_output_dim_mismatch_dynamic_size(%t: tensor<?xf32>, %idx : index) {227 // expected-error @+2 {{expected type to be 'tensor<?xf32>' or a rank-reduced version. (size mismatch)}}228 %c4 = arith.constant 4 : index229 %0 = tensor.extract_slice %t[0][%c4][1] : tensor<?xf32> to tensor<4xi8>230 return231}232 233// -----234 235func.func @extract_slice_wrong_static_type(%t: tensor<8x16x4xf32>, %idx : index) {236 // expected-error @+1 {{expected type to be 'tensor<?x4x4xf32>' or a rank-reduced version. (size mismatch)}}237 %0 = tensor.extract_slice %t[0, 0, 0][%idx, 4, 4][1, 1, 1]238 : tensor<8x16x4xf32> to tensor<4x4x4xf32>239 return240}241 242// -----243 244func.func @extract_slice_wrong_dynamic_type(%t: tensor<8x16x4xf32>, %idx : index) {245 // expected-error @+1 {{expected type to be 'tensor<4x4x4xf32>' or a rank-reduced version. (size mismatch)}}246 %0 = tensor.extract_slice %t[0, 2, 0][4, 4, 4][1, 1, 1]247 : tensor<8x16x4xf32> to tensor<?x4x4xf32>248 return249}250 251// -----252 253func.func @illegal_num_offsets(%arg0 : tensor<?x?x?xf32>, %arg1 : index, %arg2 : index) {254 // expected-error@+1 {{expected 3 offset values}}255 %0 = tensor.extract_slice %arg0[0, 0] [%arg1, %arg2] [1, 1] : tensor<?x?x?xf32> to tensor<?x?x?xf32>256 return257}258 259// -----260 261func.func @extract_slice_offset_out_of_bounds(%arg0: tensor<10xf32>) {262 // expected-error@+1 {{offset 0 is out-of-bounds: 10 >= 10}}263 %0 = tensor.extract_slice %arg0 [10][1][1] : tensor<10xf32> to tensor<1xf32>264 return265}266 267// -----268 269func.func @extract_slice_runs_out_of_bounds(%arg0: tensor<9xf32>) {270 // expected-error@+1 {{slice along dimension 0 runs out-of-bounds: 9 >= 9}}271 %0 = tensor.extract_slice %arg0 [3][4][2] : tensor<9xf32> to tensor<4xf32>272 return273}274 275// -----276 277func.func @insert_slice_wrong_result_rank(%t1: tensor<?xf32>, %t2: tensor<?x?xf32>, %idx : index) {278 // expected-error @+1 {{expected rank to be smaller or equal to the other rank.}}279 %0 = tensor.insert_slice %t2 into %t1[0][4][1] : tensor<?x?xf32> into tensor<?xf32>280 281 return282}283 284// -----285 286func.func @insert_slice_wrong_result_rank(%t1: tensor<4xi8>, %t2: tensor<?xf32>, %idx : index) {287 // expected-error @+1 {{expected element type to be 'f32'}}288 %0 = tensor.insert_slice %t1 into %t2[0][4][1] : tensor<4xi8> into tensor<?xf32>289 290 return291}292 293// -----294 295func.func @insert_slice_wrong_static_type(%t1: tensor<4x4x4xf32>, %t2: tensor<8x16x4xf32>, %idx : index) {296 // expected-error @+1 {{expected type to be 'tensor<?x4x4xf32>' or a rank-reduced version. (size mismatch)}}297 %0 = tensor.insert_slice %t1 into %t2[0, 0, 0][%idx, 4, 4][1, 1, 1]298 : tensor<4x4x4xf32> into tensor<8x16x4xf32>299 300 return301}302 303// -----304 305func.func @insert_slice_wrong_dynamic_type(%t1: tensor<?x4x4xf32>, %t2: tensor<8x16x4xf32>, %idx : index) {306 // expected-error @+1 {{expected type to be 'tensor<4x4x4xf32>' or a rank-reduced version. (size mismatch)}}307 %0 = tensor.insert_slice %t1 into %t2[0, 2, 0][4, 4, 4][1, 1, 1]308 : tensor<?x4x4xf32> into tensor<8x16x4xf32>309 310 return311}312 313// -----314 315func.func @insert_slice_offset_out_of_bounds(%arg0: tensor<1xf32>, %arg1: tensor<10xf32>) {316 // expected-error@+1 {{offset 0 is out-of-bounds: 10 >= 10}}317 %0 = tensor.insert_slice %arg0 into %arg1 [10][1][1] : tensor<1xf32> into tensor<10xf32>318 return319}320 321// -----322 323func.func @insert_slice_runs_out_of_bounds(%arg0: tensor<4xf32>, %arg1: tensor<9xf32>) {324 // expected-error@+1 {{slice along dimension 0 runs out-of-bounds: 9 >= 9}}325 %0 = tensor.insert_slice %arg0 into %arg1 [3][4][2] : tensor<4xf32> into tensor<9xf32>326 return327}328 329// -----330 331func.func @illegal_expanding_reshape_static_tensor332 (%arg0: tensor<2x3x20xf32>) -> tensor<2x3x2x4x5xf32> {333 // expected-error @+1 {{expected dimension 2 of collapsed type to be static value of 40}}334 %0 = tensor.expand_shape %arg0 [[0], [1], [2, 3, 4]] output_shape [2, 3, 2, 4, 5]335 : tensor<2x3x20xf32> into tensor<2x3x2x4x5xf32>336 return %0 : tensor<2x3x2x4x5xf32>337}338 339// -----340 341func.func @illegal_collapsing_reshape_static_tensor342 (%arg0: tensor<2x3x2x4x5xf32>) -> tensor<2x3x20xf32> {343 // expected-error @+1 {{expected dimension 2 of collapsed type to be static value of 40}}344 %0 = tensor.collapse_shape %arg0 [[0], [1], [2, 3, 4]]345 : tensor<2x3x2x4x5xf32> into tensor<2x3x20xf32>346 return %0 : tensor<2x3x20xf32>347}348 349// -----350 351func.func @illegal_expanding_reshape_mixed_tensor(%arg0 : tensor<?x?xf32>, %sz0: index)352 -> tensor<?x4x5xf32> {353 // expected-error @+1 {{expected dimension 1 of collapsed type to be static value of 5}}354 %0 = tensor.expand_shape %arg0 [[0, 1], [2]] output_shape [%sz0, 4, 5]355 : tensor<?x?xf32> into tensor<?x4x5xf32>356 return %0 : tensor<?x4x5xf32>357}358 359// -----360 361func.func @illegal_expanding_reshape_mixed_tensor_2(%arg0 : tensor<?x?xf32>, %sz0: index)362 -> tensor<?x4x5xf32> {363 // expected-error @+1 {{expected dimension 1 of collapsed type to be static value of 20}}364 %0 = tensor.expand_shape %arg0 [[0], [1, 2]] output_shape [%sz0, 4, 5]365 : tensor<?x?xf32> into tensor<?x4x5xf32>366 return %0 : tensor<?x4x5xf32>367}368 369// -----370 371func.func @expand_shape_illegal_output_shape(%arg0: tensor<2xf32>) {372 // expected-error @+1 {{expected number of static shape dims to be equal to the output rank (3) but found 2 inputs instead}}373 %0 = tensor.expand_shape %arg0 [[0, 1, 2]] output_shape [1, 2] : tensor<2xf32> into tensor<1x1x2xf32>374 return375}376 377 378// -----379 380func.func @illegal_collapsing_reshape_mixed_tensor(%arg0 : tensor<?x4x5xf32>) -> tensor<?x?xf32> {381 // expected-error @+1 {{expected dimension 1 of collapsed type to be static value of 5}}382 %0 = tensor.collapse_shape %arg0 [[0, 1], [2]]383 : tensor<?x4x5xf32> into tensor<?x?xf32>384 return %0 : tensor<?x?xf32>385}386 387// -----388 389func.func @illegal_collapsing_reshape_mixed_tensor_2(%arg0 : tensor<?x4x5xf32>)390 -> tensor<?x?xf32> {391 // expected-error @+1 {{expected dimension 1 of collapsed type to be static value of 20}}392 %0 = tensor.collapse_shape %arg0 [[0], [1, 2]]393 : tensor<?x4x5xf32> into tensor<?x?xf32>394 return %0 : tensor<?x?xf32>395}396 397// -----398 399func.func @rank(%0: f32) {400 // expected-error@+1 {{'tensor.rank' op operand #0 must be tensor of any type values}}401 "tensor.rank"(%0): (f32)->index402 return403}404 405// -----406 407func.func @illegal_num_offsets(%arg0 : tensor<?x?xf32>, %arg1 : tensor<?x?x?xf32>,408 %arg2 : index, %arg3 : index) {409 // expected-error@+1 {{expected 3 offset values}}410 %0 = tensor.insert_slice %arg0 into %arg1[0, 0] [%arg2, %arg3] [1, 1] : tensor<?x?xf32> into tensor<?x?x?xf32>411 return412}413 414// -----415 416 417func.func @pad_result_type(%arg0: tensor<?x2x3x4xi32>, %arg1: index, %arg2: i32) -> tensor<?x?x?x8xf32> {418 // expected-error @+1 {{specified type 'tensor<?x?x?x8xf32>' does not match the inferred type 'tensor<?x?x?x9xi32>}}419 %0 = tensor.pad %arg0 low[1, %arg1, 2, 2] high[1, 2, %arg1, 3] {420 ^bb0(%arg3: index, %arg4: index):421 tensor.yield %arg2 : i32422 } : tensor<?x2x3x4xi32> to tensor<?x?x?x8xf32>423 return %0 : tensor<?x?x?x8xf32>424}425 426// -----427 428func.func @pad_number_of_block_args(%arg0: tensor<?x4xi32>, %arg1: i32) -> tensor<?x9xi32> {429 // expected-error @+1 {{expected the block to have 2 arguments}}430 %0 = tensor.pad %arg0 low[1, 2] high[2, 3] {431 ^bb0(%arg2: index, %arg3: index, %arg4: index):432 tensor.yield %arg1 : i32433 } : tensor<?x4xi32> to tensor<?x9xi32>434 return %0 : tensor<?x9xi32>435}436 437// -----438 439func.func @pad_block_args(%arg0: tensor<?x4xi32>, %arg1: i32) -> tensor<?x9xi32> {440 // expected-error @+1 {{op expected block argument 1 to be an index}}441 %0 = tensor.pad %arg0 low[1, 2] high[2, 3] {442 ^bb0(%arg2: i32, %arg3: i32):443 tensor.yield %arg1 : i32444 } : tensor<?x4xi32> to tensor<?x9xi32>445 return %0 : tensor<?x9xi32>446}447 448// -----449 450func.func @pad_yield_type(%arg0: tensor<?x4xi32>, %arg1: i8) -> tensor<?x9xi32> {451 // expected-error @+1 {{op expected yield type to match shape element type}}452 %0 = tensor.pad %arg0 low[1, 2] high[2, 3] {453 ^bb0(%arg2: index, %arg3: index):454 tensor.yield %arg1 : i8455 } : tensor<?x4xi32> to tensor<?x9xi32>456 return %0 : tensor<?x9xi32>457}458 459// -----460 461func.func @invalid_splat(%v : f32) {462 // expected-error@+1 {{invalid kind of type specified: expected builtin.tensor, but found 'memref<8xf32>'}}463 tensor.splat %v : memref<8xf32>464 return465}466 467// -----468 469// expected-note@+1 {{prior use here}}470func.func @invalid_splat(%v : f32) {471 // expected-error@+1 {{expects different type than prior uses: 'i32' vs 'f32'}}472 %w = tensor.splat %v : tensor<1xi32>473 return474}475 476// -----477 478func.func @invalid_splat(%v: f32, %m: index) {479 // expected-error@+1 {{incorrect number of dynamic sizes, has 1, expected 2}}480 %w = tensor.splat %v[%m] : tensor<?x8x?xf32>481 return482}483 484// -----485 486func.func @gather_empty_dims(487 %source : tensor<4x5x6xf32>, %indices: tensor<1x2x3xindex>) {488 // expected-error@+1 {{gather_dims must be non-empty}}489 %out = tensor.gather %source[%indices] gather_dims([]):490 (tensor<4x5x6xf32>, tensor<1x2x3xindex>) -> tensor<1x2xf32>491 return492}493 494// -----495 496func.func @gather_coordinate_rank_overflow(497 %source : tensor<4x5x6xf32>, %indices: tensor<1x2x3xindex>) {498 // expected-error@+1 {{gather_dims overflow source rank}}499 %out = tensor.gather %source[%indices] gather_dims([0, 1, 2, 3]):500 (tensor<4x5x6xf32>, tensor<1x2x3xindex>) -> tensor<1x2xf32>501 return502}503 504// -----505 506func.func @gather_coordinate_rank_mismatch0(507 %source: tensor<4x5x6xf32>, %indices: tensor<index>) {508 // expected-error@+1 {{gather_dims length must match the size of last dimension of indices}}509 %out = tensor.gather %source[%indices] gather_dims([0, 1, 2]):510 (tensor<4x5x6xf32>, tensor<index>) -> tensor<1x2xf32>511}512 513// -----514 515func.func @gather_coordinate_rank_mismatch1(516 %source: tensor<4x5x6xf32>, %indices: tensor<1x2x2xindex>) {517 // expected-error@+1 {{gather_dims length must match the size of last dimension of indices}}518 %out = tensor.gather %source[%indices] gather_dims([0, 1, 2]):519 (tensor<4x5x6xf32>, tensor<1x2x2xindex>) -> tensor<1x2xf32>520}521 522// -----523 524func.func @gather_coordinate_negative(525 %source : tensor<4x5x6xf32>, %indices: tensor<1x2x1xindex>) {526 // expected-error@+1 {{gather_dims value must be non-negative}}527 %out = tensor.gather %source[%indices] gather_dims([-1]):528 (tensor<4x5x6xf32>, tensor<1x2x1xindex>) -> tensor<1x2x1xf32>529 return530}531 532// -----533 534func.func @gather_coordinate_overflow(535 %source : tensor<4x5x6xf32>, %indices: tensor<1x2x1xindex>) {536 // expected-error@+1 {{gather_dims value must be smaller than source rank}}537 %out = tensor.gather %source[%indices] gather_dims([42]):538 (tensor<4x5x6xf32>, tensor<1x2x1xindex>) -> tensor<1x2x1xf32>539 return540}541 542// -----543 544func.func @gather_coordinate_increase(545 %source : tensor<4x5x6xf32>, %indices: tensor<1x2x2xindex>) {546 // expected-error@+1 {{gather_dims values must be strictly increasing}}547 %out = tensor.gather %source[%indices] gather_dims([1, 0]):548 (tensor<4x5x6xf32>, tensor<1x2x2xindex>) -> tensor<1x2x1x1xf32>549 return550}551 552// -----553 554func.func @gather_wrong_result_type(555 %source : tensor<4x5x6xf32>, %indices: tensor<1x2x2xindex>) {556 // expected-error@+1 {{result type mismatch: expected 'tensor<1x2x1x5x1xf32>' or its rank-reduced variant 'tensor<1x2x5xf32>' (got: 'tensor<1x2x1xf32>')}}557 %out = tensor.gather %source[%indices] gather_dims([0, 2]):558 (tensor<4x5x6xf32>, tensor<1x2x2xindex>) -> tensor<1x2x1xf32>559 return560}561 562// -----563 564func.func @scatter_empty_dims(565 %source : tensor<f32>,566 %dest : tensor<4x5x6xf32>, %indices: tensor<1x2x3xindex>) {567 // expected-error@+1 {{scatter_dims must be non-empty}}568 %out = tensor.scatter %source into %dest[%indices] scatter_dims([]) unique:569 (tensor<f32>, tensor<4x5x6xf32>, tensor<1x2x3xindex>) -> tensor<1x2xf32>570 return571}572 573// -----574 575func.func @scatter_coordinate_rank_overflow(576 %source : tensor<f32>,577 %dest : tensor<4x5x6xf32>, %indices: tensor<1x2x3xindex>) {578 // expected-error@+1 {{scatter_dims overflow dest rank}}579 %out = tensor.scatter %source into %dest[%indices] scatter_dims([0, 1, 2, 3]) unique:580 (tensor<f32>, tensor<4x5x6xf32>, tensor<1x2x3xindex>) -> tensor<1x2xf32>581 return582}583 584// -----585 586func.func @scatter_coordinate_rank_mismatch0(587 %source : tensor<f32>,588 %dest : tensor<4x5x6xf32>, %indices: tensor<index>) {589 // expected-error@+1 {{scatter_dims length must match the size of last dimension of indices}}590 %out = tensor.scatter %source into %dest[%indices] scatter_dims([0, 1, 2]) unique:591 (tensor<f32>, tensor<4x5x6xf32>, tensor<index>) -> tensor<1x2xf32>592 return593}594 595// -----596 597func.func @scatter_coordinate_rank_mismatch1(598 %source : tensor<f32>,599 %dest : tensor<4x5x6xf32>, %indices: tensor<1x2x2xindex>) {600 // expected-error@+1 {{scatter_dims length must match the size of last dimension of indices}}601 %out = tensor.scatter %source into %dest[%indices] scatter_dims([0, 1, 2]) unique:602 (tensor<f32>, tensor<4x5x6xf32>, tensor<1x2x2xindex>) -> tensor<1x2xf32>603 return604}605 606// -----607 608func.func @scatter_coordinate_negative(609 %source : tensor<f32>,610 %dest : tensor<4x5x6xf32>, %indices: tensor<1x2x1xindex>) {611 // expected-error@+1 {{scatter_dims value must be non-negative}}612 %out = tensor.scatter %source into %dest[%indices] scatter_dims([-1]) unique:613 (tensor<f32>, tensor<4x5x6xf32>, tensor<1x2x1xindex>) -> tensor<1x2x1xf32>614 return615}616 617// -----618 619func.func @scatter_coordinate_overflow(620 %source : tensor<f32>,621 %dest : tensor<4x5x6xf32>, %indices: tensor<1x2x1xindex>) {622 // expected-error@+1 {{scatter_dims value must be smaller than dest rank}}623 %out = tensor.scatter %source into %dest[%indices] scatter_dims([42]) unique:624 (tensor<f32>, tensor<4x5x6xf32>, tensor<1x2x1xindex>) -> tensor<1x2x1xf32>625 return626}627 628// -----629 630func.func @scatter_coordinate_increase(631 %source : tensor<f32>,632 %dest : tensor<4x5x6xf32>, %indices: tensor<1x2x2xindex>) {633 // expected-error@+1 {{scatter_dims values must be strictly increasing}}634 %out = tensor.scatter %source into %dest[%indices] scatter_dims([1, 0]) unique:635 (tensor<f32>, tensor<4x5x6xf32>, tensor<1x2x2xindex>) -> tensor<1x2x1x1xf32>636 return637}638 639// -----640 641func.func @scatter_missing_unique(642 %source : tensor<f32>,643 %dest : tensor<4x5x6xf32>, %indices: tensor<1x2x2xindex>) {644 // expected-error@+1 {{requires 'unique' attribute to be set}}645 %out = tensor.scatter %source into %dest[%indices] scatter_dims([0, 2]):646 (tensor<f32>, tensor<4x5x6xf32>, tensor<1x2x2xindex>) -> tensor<1x2x1xf32>647 return648}649 650// -----651 652func.func @scatter_wrong_result_type(653 %source : tensor<f32>,654 %dest : tensor<4x5x6xf32>, %indices: tensor<1x2x2xindex>) {655 // expected-error@+1 {{source type mismatch: expected 'tensor<1x2x1x5x1xf32>' or its rank-reduced variant 'tensor<1x2x5xf32>' (got: 'tensor<f32>')}}656 %out = tensor.scatter %source into %dest[%indices] scatter_dims([0, 2]) unique:657 (tensor<f32>, tensor<4x5x6xf32>, tensor<1x2x2xindex>) -> tensor<1x2x1xf32>658 return659}660 661// -----662 663func.func @empty_wrong_number_of_operands(%sz : index) {664 // expected-error@+1 {{incorrect number of dynamic sizes, has 1, expected 2}}665 %out = tensor.empty(%sz) : tensor<2x?x?x5xf32>666 return667}668 669// -----670 671func.func @bitcast_index_0(%arg0 : tensor<?xi64>) -> tensor<?xindex> {672 // expected-error @+1 {{'tensor.bitcast' op result #0 must be tensor of signless integer or unsigned integer or signed integer or floating-point values, but got 'tensor<?xindex>'}}673 %0 = tensor.bitcast %arg0 : tensor<?xi64> to tensor<?xindex>674 return %0 : tensor<?xindex>675}676 677// -----678 679func.func @bitcast_index_1(%arg0 : tensor<?xindex>) -> tensor<?xi64> {680 // expected-error @+1 {{'tensor.bitcast' op operand #0 must be tensor of signless integer or unsigned integer or signed integer or floating-point values, but got 'tensor<?xindex>'}}681 %0 = tensor.bitcast %arg0 : tensor<?xindex> to tensor<?xi64>682 return %0 : tensor<?xi64>683}684