1204 lines · plain
1// RUN: mlir-opt -allow-unregistered-dialect -split-input-file %s -verify-diagnostics2 3func.func @dma_start_not_enough_operands() {4 // expected-error@+1 {{expected at least 4 operands}}5 "memref.dma_start"() : () -> ()6}7 8// -----9 10func.func @dma_no_src_memref(%m : f32, %tag : f32, %c0 : index) {11 // expected-error@+1 {{expected source to be of memref type}}12 memref.dma_start %m[%c0], %m[%c0], %c0, %tag[%c0] : f32, f32, f3213}14 15// -----16 17func.func @dma_start_not_enough_operands_for_src(18 %src: memref<2x2x2xf32>, %idx: index) {19 // expected-error@+1 {{expected at least 7 operands}}20 "memref.dma_start"(%src, %idx, %idx, %idx) : (memref<2x2x2xf32>, index, index, index) -> ()21}22 23// -----24 25func.func @dma_start_src_index_wrong_type(26 %src: memref<2x2xf32>, %idx: index, %dst: memref<2xf32,1>,27 %tag: memref<i32,2>, %flt: f32) {28 // expected-error@+1 {{expected source indices to be of index type}}29 "memref.dma_start"(%src, %idx, %flt, %dst, %idx, %tag, %idx)30 : (memref<2x2xf32>, index, f32, memref<2xf32,1>, index, memref<i32,2>, index) -> ()31}32 33// -----34 35func.func @dma_no_dst_memref(%m : f32, %tag : f32, %c0 : index) {36 %mref = memref.alloc() : memref<8 x f32>37 // expected-error@+1 {{expected destination to be of memref type}}38 memref.dma_start %mref[%c0], %m[%c0], %c0, %tag[%c0] : memref<8 x f32>, f32, f3239}40 41// -----42 43func.func @dma_start_not_enough_operands_for_dst(44 %src: memref<2x2xf32>, %idx: index, %dst: memref<2xf32,1>,45 %tag: memref<i32,2>) {46 // expected-error@+1 {{expected at least 7 operands}}47 "memref.dma_start"(%src, %idx, %idx, %dst, %idx, %idx)48 : (memref<2x2xf32>, index, index, memref<2xf32,1>, index, index) -> ()49}50 51// -----52 53func.func @dma_start_dst_index_wrong_type(54 %src: memref<2x2xf32>, %idx: index, %dst: memref<2xf32,1>,55 %tag: memref<i32,2>, %flt: f32) {56 // expected-error@+1 {{expected destination indices to be of index type}}57 "memref.dma_start"(%src, %idx, %idx, %dst, %flt, %tag, %idx)58 : (memref<2x2xf32>, index, index, memref<2xf32,1>, f32, memref<i32,2>, index) -> ()59}60 61// -----62 63func.func @dma_start_dst_index_wrong_type(64 %src: memref<2x2xf32>, %idx: index, %dst: memref<2xf32,1>,65 %tag: memref<i32,2>, %flt: f32) {66 // expected-error@+1 {{expected num elements to be of index type}}67 "memref.dma_start"(%src, %idx, %idx, %dst, %idx, %flt, %tag)68 : (memref<2x2xf32>, index, index, memref<2xf32,1>, index, f32, memref<i32,2>) -> ()69}70 71// -----72 73func.func @dma_no_tag_memref(%tag : f32, %c0 : index) {74 %mref = memref.alloc() : memref<8 x f32>75 // expected-error@+1 {{expected tag to be of memref type}}76 memref.dma_start %mref[%c0], %mref[%c0], %c0, %tag[%c0] : memref<8 x f32>, memref<8 x f32>, f3277}78 79// -----80 81func.func @dma_start_not_enough_operands_for_tag(82 %src: memref<2x2xf32>, %idx: index, %dst: memref<2xf32,1>,83 %tag: memref<2xi32,2>) {84 // expected-error@+1 {{expected at least 8 operands}}85 "memref.dma_start"(%src, %idx, %idx, %dst, %idx, %idx, %tag)86 : (memref<2x2xf32>, index, index, memref<2xf32,1>, index, index, memref<2xi32,2>) -> ()87}88 89// -----90 91func.func @dma_start_dst_index_wrong_type(92 %src: memref<2x2xf32>, %idx: index, %dst: memref<2xf32,1>,93 %tag: memref<2xi32,2>, %flt: f32) {94 // expected-error@+1 {{expected tag indices to be of index type}}95 "memref.dma_start"(%src, %idx, %idx, %dst, %idx, %idx, %tag, %flt)96 : (memref<2x2xf32>, index, index, memref<2xf32,1>, index, index, memref<2xi32,2>, f32) -> ()97}98 99// -----100 101func.func @dma_start_too_many_operands(102 %src: memref<2x2xf32>, %idx: index, %dst: memref<2xf32,1>,103 %tag: memref<i32,2>) {104 // expected-error@+1 {{incorrect number of operands}}105 "memref.dma_start"(%src, %idx, %idx, %dst, %idx, %idx, %tag, %idx, %idx, %idx)106 : (memref<2x2xf32>, index, index, memref<2xf32,1>, index, index, memref<i32,2>, index, index, index) -> ()107}108 109 110// -----111 112func.func @dma_start_wrong_stride_type(113 %src: memref<2x2xf32>, %idx: index, %dst: memref<2xf32,1>,114 %tag: memref<i32,2>, %flt: f32) {115 // expected-error@+1 {{expected stride and num elements per stride to be of type index}}116 "memref.dma_start"(%src, %idx, %idx, %dst, %idx, %idx, %tag, %idx, %flt)117 : (memref<2x2xf32>, index, index, memref<2xf32,1>, index, index, memref<i32,2>, index, f32) -> ()118}119 120// -----121 122func.func @dma_wait_wrong_index_type(%tag : memref<2x2xi32>, %idx: index, %flt: index) {123 // expected-error@+1 {{expected tagIndices to have the same number of elements as the tagMemRef rank, expected 2, but got 1}}124 "memref.dma_wait"(%tag, %flt, %idx) : (memref<2x2xi32>, index, index) -> ()125 return126}127 128// -----129 130func.func @transpose_not_permutation(%v : memref<?x?xf32, affine_map<(i, j)[off, M]->(off + M * i + j)>>) {131 // expected-error @+1 {{expected a permutation map}}132 memref.transpose %v (i, j) -> (i, i) : memref<?x?xf32, affine_map<(i, j)[off, M]->(off + M * i + j)>> to memref<?x?xf32, affine_map<(i, j)[off, M]->(off + M * i + j)>>133}134 135// -----136 137func.func @transpose_bad_rank(%v : memref<?x?xf32, affine_map<(i, j)[off, M]->(off + M * i + j)>>) {138 // expected-error @+1 {{expected a permutation map of same rank as the input}}139 memref.transpose %v (i) -> (i) : memref<?x?xf32, affine_map<(i, j)[off, M]->(off + M * i + j)>> to memref<?x?xf32, affine_map<(i, j)[off, M]->(off + M * i + j)>>140}141 142// -----143 144func.func @transpose_wrong_type(%v : memref<?x?xf32, affine_map<(i, j)[off, M]->(off + M * i + j)>>) {145 // expected-error @+1 {{result type 'memref<?x?xf32, affine_map<(d0, d1)[s0, s1] -> (d0 * s1 + s0 + d1)>>' is not equivalent to the canonical transposed input type 'memref<?x?xf32, affine_map<(d0, d1)[s0, s1] -> (d0 + s0 + d1 * s1)>>'}}146 memref.transpose %v (i, j) -> (j, i) : memref<?x?xf32, affine_map<(i, j)[off, M]->(off + M * i + j)>> to memref<?x?xf32, affine_map<(i, j)[off, M]->(off + M * i + j)>>147}148 149// -----150 151func.func @memref_reinterpret_cast_too_many_offsets(%in: memref<?xf32>) {152 // expected-error @+1 {{expected 1 offset values}}153 %out = memref.reinterpret_cast %in to154 offset: [0, 0], sizes: [10, 10], strides: [10, 1]155 : memref<?xf32> to memref<10x10xf32, strided<[10, 1], offset: 0>>156 return157}158 159// -----160 161func.func @memref_reinterpret_cast_incompatible_element_types(%in: memref<*xf32>) {162 // expected-error @+1 {{different element types specified}}163 %out = memref.reinterpret_cast %in to164 offset: [0], sizes: [10], strides: [1]165 : memref<*xf32> to memref<10xi32, strided<[1], offset: 0>>166 return167}168 169// -----170 171func.func @memref_reinterpret_cast_incompatible_memory_space(%in: memref<*xf32>) {172 // expected-error @+1 {{different memory spaces specified}}173 %out = memref.reinterpret_cast %in to174 offset: [0], sizes: [10], strides: [1]175 : memref<*xf32> to memref<10xi32, strided<[1], offset: 0>, 2>176 return177}178 179// -----180 181func.func @memref_reinterpret_cast_offset_mismatch(%in: memref<?xf32>) {182 // expected-error @+1 {{expected result type with offset = 1 instead of 2}}183 %out = memref.reinterpret_cast %in to184 offset: [1], sizes: [10], strides: [1]185 : memref<?xf32> to memref<10xf32, strided<[1], offset: 2>>186 return187}188 189// -----190 191func.func @memref_reinterpret_cast_size_mismatch(%in: memref<*xf32>) {192 // expected-error @+1 {{expected result type with size = 10 instead of 1 in dim = 0}}193 %out = memref.reinterpret_cast %in to194 offset: [0], sizes: [10], strides: [1]195 : memref<*xf32> to memref<1xf32, strided<[1], offset: 0>>196 return197}198 199// -----200 201func.func @memref_reinterpret_cast_offset_mismatch(%in: memref<?xf32>) {202 // expected-error @+1 {{expected result type with stride = 2 instead of 1 in dim = 0}}203 %out = memref.reinterpret_cast %in to204 offset: [2], sizes: [10], strides: [2]205 : memref<?xf32> to memref<10xf32, strided<[1], offset: 2>>206 return207}208 209// -----210 211func.func @memref_reinterpret_cast_no_map_but_offset(%in: memref<?xf32>) {212 // expected-error @+1 {{expected result type with offset = 2 instead of 0}}213 %out = memref.reinterpret_cast %in to offset: [2], sizes: [10], strides: [1]214 : memref<?xf32> to memref<10xf32>215 return216}217 218// -----219 220func.func @memref_reinterpret_cast_offset_mismatch_dynamic(%in: memref<?xf32>, %offset : index) {221 // expected-error @+1 {{expected result type with offset = dynamic instead of 0}}222 %out = memref.reinterpret_cast %in to offset: [%offset], sizes: [10], strides: [1]223 : memref<?xf32> to memref<10xf32>224 return225}226 227// -----228 229func.func @memref_reinterpret_cast_no_map_but_stride(%in: memref<?xf32>) {230 // expected-error @+1 {{expected result type with stride = 10 instead of 1 in dim = 0}}231 %out = memref.reinterpret_cast %in to offset: [0], sizes: [10], strides: [10]232 : memref<?xf32> to memref<10xf32>233 return234}235 236// -----237 238func.func @memref_reinterpret_cast_no_map_but_strides(%in: memref<?x?xf32>) {239 // expected-error @+1 {{expected result type with stride = 42 instead of 10 in dim = 0}}240 %out = memref.reinterpret_cast %in to241 offset: [0], sizes: [9, 10], strides: [42, 1]242 : memref<?x?xf32> to memref<9x10xf32>243 return244}245 246// -----247 248func.func @memref_reshape_element_type_mismatch(249 %buf: memref<*xf32>, %shape: memref<1xi32>) {250 // expected-error @+1 {{element types of source and destination memref types should be the same}}251 memref.reshape %buf(%shape) : (memref<*xf32>, memref<1xi32>) -> memref<?xi32>252}253 254// -----255 256func.func @memref_reshape_dst_ranked_shape_unranked(257 %buf: memref<*xf32>, %shape: memref<?xi32>) {258 // expected-error @+1 {{cannot use shape operand with dynamic length to reshape to statically-ranked memref type}}259 memref.reshape %buf(%shape) : (memref<*xf32>, memref<?xi32>) -> memref<?xf32>260}261 262// -----263 264func.func @memref_reshape_dst_shape_rank_mismatch(265 %buf: memref<*xf32>, %shape: memref<1xi32>) {266 // expected-error @+1 {{length of shape operand differs from the result's memref rank}}267 memref.reshape %buf(%shape)268 : (memref<*xf32>, memref<1xi32>) -> memref<?x?xf32>269}270 271// -----272 273func.func @memref_reshape_src_affine_map_is_not_identity(274 %buf: memref<4x4xf32, strided<[3, 2], offset: 0>>,275 %shape: memref<1xi32>) {276 // expected-error @+1 {{source memref type should have identity affine map}}277 memref.reshape %buf(%shape)278 : (memref<4x4xf32, strided<[3, 2], offset: 0>>, memref<1xi32>)279 -> memref<8xf32>280}281 282// -----283 284func.func @memref_reshape_result_affine_map_is_not_identity(285 %buf: memref<4x4xf32>, %shape: memref<1xi32>) {286 // expected-error @+1 {{result memref type should have identity affine map}}287 memref.reshape %buf(%shape)288 : (memref<4x4xf32>, memref<1xi32>) -> memref<8xf32, strided<[2], offset: 0>>289}290 291// -----292 293// expected-error @+1 {{type should be static shaped memref}}294memref.global @foo : i32295 296// -----297 298// expected-error @+1 {{type should be static shaped memref}}299memref.global @foo : i32 = 5300 301// -----302 303// expected-error @+1 {{type should be static shaped memref}}304memref.global @foo : memref<*xf32>305 306// -----307 308// expected-error @+1 {{type should be static shaped memref}}309memref.global @foo : memref<?x?xf32>310 311// -----312 313// expected-error @+1 {{initial value should be a unit or elements attribute}}314memref.global @foo : memref<2x2xf32> = "foo"315 316// -----317 318// expected-error @+1 {{inferred shape of elements literal ([2]) does not match type ([2, 2])}}319memref.global @foo : memref<2x2xf32> = dense<[0.0, 1.0]>320 321// -----322 323// expected-error @+1 {{expected valid '@'-identifier for symbol name}}324memref.global "private" "public" @foo : memref<2x2xf32> = "foo"325 326// -----327 328// expected-error @+1 {{expected valid '@'-identifier for symbol name}}329memref.global constant external @foo : memref<2x2xf32> = "foo"330 331// -----332 333// constant qualifier must be after visibility.334// expected-error @+1 {{expected valid '@'-identifier for symbol name}}335memref.global constant "private" @foo : memref<2x2xf32> = "foo"336 337 338// -----339 340// expected-error @+1 {{op visibility expected to be one of ["public", "private", "nested"], but got "priate"}}341memref.global "priate" constant @memref5 : memref<2xf32> = uninitialized342 343// -----344 345// expected-error @+1 {{op initial value element expected to be of type 'f16', but was of type 'f32'}}346"memref.global"() <{constant, initial_value = dense<1.000000e+00> : tensor<1xf32>, sym_name = "memref6", sym_visibility = "private", type = memref<1xf16>}> : () -> ()347 348// -----349 350// expected-error @+1 {{op initial value shape expected to be 1, 2 but was 2, 2}}351"memref.global"() <{constant, initial_value = dense<1.000000e+00> : tensor<2x2xf16>, sym_name = "memref7", sym_visibility = "private", type = memref<1x2xf16>}> : () -> ()352 353// -----354 355func.func @nonexistent_global_memref() {356 // expected-error @+1 {{'gv' does not reference a valid global memref}}357 %0 = memref.get_global @gv : memref<3xf32>358 return359}360 361// -----362 363func.func private @foo()364 365func.func @nonexistent_global_memref() {366 // expected-error @+1 {{'foo' does not reference a valid global memref}}367 %0 = memref.get_global @foo : memref<3xf32>368 return369}370 371// -----372 373memref.global @gv : memref<3xi32>374 375func.func @mismatched_types() {376 // expected-error @+1 {{result type 'memref<3xf32>' does not match type 'memref<3xi32>' of the global memref @gv}}377 %0 = memref.get_global @gv : memref<3xf32>378 return379}380 381// -----382 383// expected-error @+1 {{'memref.global' op attribute 'alignment' failed to satisfy constraint: 64-bit signless integer attribute whose value is positive and whose value is a power of two > 0}}384memref.global "private" @gv : memref<4xf32> = dense<1.0> { alignment = 63 }385 386// -----387 388func.func @copy_different_shape(%arg0: memref<2xf32>, %arg1: memref<3xf32>) {389 // expected-error @+1 {{op requires the same shape for all operands}}390 memref.copy %arg0, %arg1 : memref<2xf32> to memref<3xf32>391 return392}393 394// -----395 396func.func @copy_different_eltype(%arg0: memref<2xf32>, %arg1: memref<2xf16>) {397 // expected-error @+1 {{op requires the same element type for all operands}}398 memref.copy %arg0, %arg1 : memref<2xf32> to memref<2xf16>399 return400}401 402// -----403 404func.func @expand_shape(%arg0: memref<?x?xf32>, %sz0: index, %sz1: index) {405 // expected-error @+1 {{invalid number of reassociation groups: found 1, expected 2}}406 %0 = memref.expand_shape %arg0 [[0, 1]] output_shape [%sz0, 5, %sz1] : memref<?x?xf32> into memref<?x5x?xf32>407 return408}409 410// -----411 412func.func @expand_shape(%arg0: memref<f32>) {413 // expected-error @+1 {{rank 0 memrefs can only be extended/collapsed with/from ones}}414 %0 = memref.expand_shape %arg0 [] output_shape [1, 2] : memref<f32> into memref<1x2xf32>415 return416}417 418// -----419 420func.func @expand_shape_illegal_output_shape(%arg0: memref<2xf32>) {421 // expected-error @+1 {{expected number of static shape bounds to be equal to the output rank (3) but found 2 inputs instead}}422 %0 = memref.expand_shape %arg0 [[0, 1, 2]] output_shape [1, 2] : memref<2xf32> into memref<1x1x2xf32>423 return424}425 426// -----427 428func.func @collapse_shape_out_of_bounds(%arg0: memref<?x?xf32>) {429 // expected-error @+1 {{op reassociation index 2 is out of bounds}}430 %0 = memref.collapse_shape %arg0 [[0, 1, 2]] : memref<?x?xf32> into memref<?xf32>431}432 433// -----434 435func.func @expand_shape_out_of_bounds(%arg0: memref<?xf32>, %sz0: index) {436 // expected-error @+1 {{op reassociation index 2 is out of bounds}}437 %0 = memref.expand_shape %arg0 [[0, 1, 2]] output_shape [4, %sz0] : memref<?xf32> into memref<4x?xf32>438}439 440// -----441 442func.func @expand_shape_invalid_result_layout(443 %arg0: memref<30x20xf32, strided<[4000, 2], offset: 100>>) {444 // expected-error @+1 {{expected expanded type to be 'memref<2x15x20xf32, strided<[60000, 4000, 2], offset: 100>>' but found 'memref<2x15x20xf32, strided<[5000, 4000, 2], offset: 100>>'}}445 %0 = memref.expand_shape %arg0 [[0, 1], [2]] output_shape [2, 15, 20] :446 memref<30x20xf32, strided<[4000, 2], offset: 100>>447 into memref<2x15x20xf32, strided<[5000, 4000, 2], offset: 100>>448}449 450// -----451 452func.func @collapse_shape_mismatch_indices_num(%arg0: memref<?x?x?xf32>) {453 // expected-error @+1 {{invalid number of reassociation groups: found 1, expected 2}}454 %0 = memref.collapse_shape %arg0 [[0, 1]] :455 memref<?x?x?xf32> into memref<?x?xf32, strided<[?, 1], offset: 0>>456}457 458// -----459 460func.func @collapse_shape_invalid_reassociation(%arg0: memref<?x?x?xf32>) {461 // expected-error @+1 {{reassociation indices must be contiguous}}462 %0 = memref.collapse_shape %arg0 [[0, 1], [1, 2]] :463 memref<?x?x?xf32> into memref<?x?xf32, strided<[?, 1], offset: 0>>464}465 466// -----467 468// An (invalid) attempt at using collapse_shape to increase the rank might look469// like this. Verify that a sensible error is emitted in this case.470func.func @collapse_shape_invalid_reassociation_expansion(%arg0: memref<?xf32>) {471 // expected-error @+1 {{'memref.collapse_shape' op has source rank 1 and result rank 2. This is not a collapse (1 < 2)}}472 %0 = memref.collapse_shape %arg0 [[0], [0]] :473 memref<?xf32> into memref<?x?xf32>474}475 476// -----477 478// An (invalid) attempt at using expand_shape to reduce the rank might look479// like this. Verify that a sensible error is emitted in this case.480func.func @expand_shape_invalid_reassociation(%arg0: memref<2x3x1xf32>) {481 // expected-error @+1 {{'memref.expand_shape' op has source rank 3 and result rank 2. This is not an expansion (3 > 2)}}482 %0 = memref.expand_shape %arg0 [[0], [1], [1]] output_shape [2, 3] :483 memref<2x3x1xf32> into memref<2x3xf32>484}485 486// -----487 488func.func @collapse_shape_invalid_reassociation_expansion(%arg0: memref<?x?xf32>) {489 // expected-error @+1 {{reassociation indices must be contiguous}}490 %0 = memref.collapse_shape %arg0 [[1], [0]] :491 memref<?x?xf32> into memref<?x?xf32>492}493 494// -----495 496func.func @collapse_shape_reshaping_non_contiguous(497 %arg0: memref<3x4x5xf32, strided<[270, 50, 10], offset: 0>>) {498 // expected-error @+1 {{invalid source layout map or collapsing non-contiguous dims}}499 %0 = memref.collapse_shape %arg0 [[0, 1], [2]] :500 memref<3x4x5xf32, strided<[270, 50, 10], offset: 0>>501 into memref<12x5xf32, strided<[50, 1], offset: 0>>502 return503}504 505// -----506 507func.func @collapse_shape_wrong_collapsed_type(%arg0: memref<?x?x?xf32>) {508 // expected-error @+1 {{expected collapsed type to be 'memref<?x?xf32>' but found 'memref<?x?xf32, affine_map<(d0, d1)[s0] -> (d0 * s0 + d1)>>'}}509 %0 = memref.collapse_shape %arg0 [[0, 1], [2]] :510 memref<?x?x?xf32> into memref<?x?xf32, affine_map<(d0, d1)[s0] -> (d0 * s0 + d1)>>511}512 513// -----514 515func.func @expand_shape_illegal_static_memref516 (%arg0: memref<2x3x20xf32>) -> memref<2x3x2x4x5xf32> {517 // expected-error @+1 {{collapsed dim size (20) must equal reassociation group size (40)}}518 %0 = memref.expand_shape %arg0 [[0], [1], [2, 3, 4]] output_shape [2, 3, 2, 4, 5]519 : memref<2x3x20xf32> into memref<2x3x2x4x5xf32>520 return %0 : memref<2x3x2x4x5xf32>521}522 523// -----524 525func.func @collapse_shape_illegal_static_memref526 (%arg0: memref<2x3x2x4x5xf32>) -> memref<2x3x20xf32> {527 // expected-error @+1 {{collapsed dim size (20) must equal reassociation group size (40)}}528 %0 = memref.collapse_shape %arg0 [[0], [1], [2, 3, 4]]529 : memref<2x3x2x4x5xf32> into memref<2x3x20xf32>530 return %0 : memref<2x3x20xf32>531}532 533// -----534 535func.func @expand_shape_illegal_mixed_memref(%arg0 : memref<?x?xf32>, %sz0: index)536 -> memref<?x4x5xf32> {537 // expected-error @+1 {{collapsed dim (1) must be dynamic if and only if reassociation group is dynamic}}538 %0 = memref.expand_shape %arg0 [[0, 1], [2]] output_shape [%sz0, 4, 5]539 : memref<?x?xf32> into memref<?x4x5xf32>540 return %0 : memref<?x4x5xf32>541}542 543// -----544 545func.func @expand_shape_illegal_mixed_memref_2(%arg0 : memref<?x?xf32>, %sz0: index)546 -> memref<?x4x5xf32> {547 // expected-error @+1 {{collapsed dim (1) must be dynamic if and only if reassociation group is dynamic}}548 %0 = memref.expand_shape %arg0 [[0], [1, 2]] output_shape [%sz0, 4, 5]549 : memref<?x?xf32> into memref<?x4x5xf32>550 return %0 : memref<?x4x5xf32>551}552 553// -----554 555func.func @expand_shape_invalid_static_dim_size(%arg0 : memref<?x21xf32>, %sz0: index)556 -> memref<?x4x5xf32> {557 // expected-error @+1 {{collapsed dim size (21) must equal reassociation group size (20)}}558 %0 = memref.expand_shape %arg0 [[0], [1, 2]] output_shape [%sz0, 4, 5]559 : memref<?x21xf32> into memref<?x4x5xf32>560 return %0 : memref<?x4x5xf32>561}562 563// -----564 565func.func @collapse_shape_illegal_mixed_memref(%arg0 : memref<?x4x5xf32>)566 -> memref<?x?xf32> {567 // expected-error @+1 {{collapsed dim (1) must be dynamic if and only if reassociation group is dynamic}}568 %0 = memref.collapse_shape %arg0 [[0, 1], [2]]569 : memref<?x4x5xf32> into memref<?x?xf32>570 return %0 : memref<?x?xf32>571}572 573// -----574 575func.func @collapse_shape_illegal_mixed_memref_2(%arg0 : memref<?x4x5xf32>)576 -> memref<?x?xf32> {577 // expected-error @+1 {{collapsed dim (1) must be dynamic if and only if reassociation group is dynamic}}578 %0 = memref.collapse_shape %arg0 [[0], [1, 2]]579 : memref<?x4x5xf32> into memref<?x?xf32>580 return %0 : memref<?x?xf32>581}582 583// -----584 585func.func @invalid_view(%arg0 : index, %arg1 : index, %arg2 : index) {586 %0 = memref.alloc() : memref<2048xi8>587 // expected-error@+1 {{expected SSA operand}}588 %1 = memref.view %0[][%arg0, %arg1]589 : memref<2048xi8> to memref<?x?xf32>590 return591}592 593// -----594 595func.func @invalid_view(%arg0 : index, %arg1 : index, %arg2 : index) {596 %0 = memref.alloc() : memref<2048xi8, affine_map<(d0) -> (d0 floordiv 8, d0 mod 8)>>597 // expected-error@+1 {{unsupported map for base memref type}}598 %1 = memref.view %0[%arg2][%arg0, %arg1]599 : memref<2048xi8, affine_map<(d0) -> (d0 floordiv 8, d0 mod 8)>> to600 memref<?x?xf32, affine_map<(d0, d1)[s0] -> (d0 * 4 + d1 + s0)>>601 return602}603 604// -----605 606func.func @invalid_view(%arg0 : index, %arg1 : index, %arg2 : index) {607 %0 = memref.alloc() : memref<2048xi8>608 // expected-error@+1 {{unsupported map for result memref type}}609 %1 = memref.view %0[%arg2][%arg0, %arg1]610 : memref<2048xi8> to memref<?x?xf32, affine_map<(d0, d1)[s0] -> (d0, d1, s0)>>611 return612}613 614// -----615 616func.func @invalid_view(%arg0 : index, %arg1 : index, %arg2 : index) {617 %0 = memref.alloc() : memref<2048xi8, 2>618 // expected-error@+1 {{different memory spaces}}619 %1 = memref.view %0[%arg2][%arg0, %arg1] : memref<2048xi8, 2> to memref<?x?xf32, 1>620 return621}622 623// -----624 625func.func @invalid_view(%arg0 : index, %arg1 : index, %arg2 : index) {626 %0 = memref.alloc() : memref<2048xi8>627 // expected-error@+1 {{incorrect number of size operands for type}}628 %1 = memref.view %0[%arg2][%arg0]629 : memref<2048xi8> to memref<?x?xf32>630 return631}632 633// -----634 635func.func @invalid_subview(%input: memref<4x1024xf32>) -> memref<2x256xf32, strided<[1024, 1], offset: 2304>> {636 // expected-error@+1 {{expected offsets to be non-negative, but got -1}}637 %0 = memref.subview %input[-1, 256] [2, 256] [1, 1] : memref<4x1024xf32> to memref<2x256xf32, strided<[1024, 1], offset: 2304>>638 return %0 : memref<2x256xf32, strided<[1024, 1], offset: 2304>>639}640 641// -----642 643func.func @invalid_subview(%input: memref<4x1024xf32>) -> memref<2x256xf32, strided<[1024, 1], offset: 2304>> {644 // expected-error@+1 {{expected sizes to be non-negative, but got -1}}645 %0 = memref.subview %input[2, 256] [-1, 256] [1, 1] : memref<4x1024xf32> to memref<2x256xf32, strided<[1024, 1], offset: 2304>>646 return %0 : memref<2x256xf32, strided<[1024, 1], offset: 2304>>647}648 649// -----650 651func.func @invalid_subview(%arg0 : index, %arg1 : index, %arg2 : index) {652 %0 = memref.alloc() : memref<8x16x4xf32>653 // expected-error@+1 {{expected mixed offsets rank to match mixed sizes rank (2 vs 3) so the rank of the result type is well-formed}}654 %1 = memref.subview %0[0, 0][2, 2, 2][1, 1, 1]655 : memref<8x16x4xf32> to memref<8x16x4xf32>656 return657}658 659// -----660 661// This test is not written in the op's assembly format, to reproduce a mismatch662// between the rank of static_offsets and the number of Values sent as the663// dynamic offsets.664func.func @invalid_subview(%arg0 : memref<?x128xi8, 1>) {665 %0 = memref.alloc() :memref<1xf32>666 // expected-error@+1 {{expected the number of 'offsets' to match the number of dynamic entries in 'static_offsets' (0 vs 1)}}667 "memref.subview"(%0) <{operandSegmentSizes = array<i32: 1, 0, 0, 0>, static_offsets = array<i64: -9223372036854775808>, static_sizes = array<i64: 1>, static_strides = array<i64: 1>}> : (memref<1xf32>) -> memref<1xf32, strided<[1], offset: ?>>668 return669}670 671// -----672 673func.func @invalid_subview(%arg0 : index, %arg1 : index, %arg2 : index) {674 %0 = memref.alloc() : memref<8x16x4xf32>675 // expected-error@+1 {{expected mixed sizes rank to match mixed strides rank (3 vs 2) so the rank of the result type is well-formed}}676 %1 = memref.subview %0[0, 0, 0][2, 2, 2][1, 1]677 : memref<8x16x4xf32> to memref<8x16x4xf32>678 return679}680 681// -----682 683func.func @invalid_subview(%arg0 : index, %arg1 : index, %arg2 : index) {684 %0 = memref.alloc() : memref<8x16x4xf32>685 // expected-error@+1 {{expected mixed sizes rank to match mixed strides rank (3 vs 2) so the rank of the result type is well-formed}}686 %1 = memref.reinterpret_cast %0 to offset: [0], sizes: [2, 2, 2], strides:[1, 1]687 : memref<8x16x4xf32> to memref<8x16x4xf32>688 return689}690 691// -----692 693func.func @invalid_subview(%arg0 : index, %arg1 : index, %arg2 : index) {694 %0 = memref.alloc() : memref<8x16x4xf32, strided<[64, 4, 1], offset: 0>, 2>695 // expected-error@+1 {{different memory spaces}}696 %1 = memref.subview %0[0, 0, 0][%arg2, %arg2, %arg2][1, 1, 1]697 : memref<8x16x4xf32, strided<[64, 4, 1], offset: 0>, 2> to698 memref<8x?x4xf32, affine_map<(d0, d1, d2)[s0] -> (d0 * s0 + d1 * 4 + d2)>>699 return700}701 702// -----703 704func.func @invalid_subview(%arg0 : index, %arg1 : index, %arg2 : index) {705 %0 = memref.alloc() : memref<8x16x4xf32, affine_map<(d0, d1, d2) -> (d0 + d1, d1 + d2, d2)>>706 // expected-error@+1 {{is not strided}}707 %1 = memref.subview %0[0, 0, 0][%arg2, %arg2, %arg2][1, 1, 1]708 : memref<8x16x4xf32, affine_map<(d0, d1, d2) -> (d0 + d1, d1 + d2, d2)>> to709 memref<8x?x4xf32, strided<[?, 4, 1], offset: 0>>710 return711}712 713// -----714 715func.func @invalid_subview(%arg0 : index, %arg1 : index, %arg2 : index) {716 %0 = memref.alloc() : memref<8x16x4xf32>717 // expected-error@+1 {{expected 3 offset values}}718 %1 = memref.subview %0[%arg0, %arg1, 0, 0][%arg2, 0, 0, 0][1, 1, 1, 1]719 : memref<8x16x4xf32> to720 memref<8x?x4xf32, strided<[?, ?, 4], offset: 0>>721 return722}723 724// -----725 726func.func @invalid_subview(%arg0 : index, %arg1 : index, %arg2 : index) {727 %0 = memref.alloc() : memref<8x16x4xf32>728 // expected-error@+1 {{expected result element type to be 'f32', but got 'memref<8x16x4xi32>'}}729 %1 = memref.subview %0[0, 0, 0][8, 16, 4][1, 1, 1]730 : memref<8x16x4xf32> to731 memref<8x16x4xi32>732 return733}734 735// -----736 737func.func @invalid_subview(%arg0 : index, %arg1 : index, %arg2 : index) {738 %0 = memref.alloc() : memref<8x16x4xf32>739 // expected-error@+1 {{expected result rank to be smaller or equal to the source rank, but got 'memref<8x16x4x3xf32>'}}740 %1 = memref.subview %0[0, 0, 0][8, 16, 4][1, 1, 1]741 : memref<8x16x4xf32> to742 memref<8x16x4x3xf32>743 return744}745 746// -----747 748func.func @invalid_subview(%arg0: memref<10xf32>) {749 // expected-error@+1 {{offset 0 is out-of-bounds: 10 >= 10}}750 %0 = memref.subview %arg0 [10][1][1] : memref<10xf32> to memref<1xf32, strided<[1], offset: 10>>751 return752}753 754// -----755 756func.func @invalid_subview(%arg0: memref<9xf32>) {757 // expected-error@+1 {{slice along dimension 0 runs out-of-bounds: 9 >= 9}}758 %0 = memref.subview %arg0 [3][4][2] : memref<9xf32> to memref<4xf32, strided<[2], offset: 3>>759 return760}761 762// -----763 764func.func @invalid_rank_reducing_subview(%arg0 : index, %arg1 : index, %arg2 : index) {765 %0 = memref.alloc() : memref<8x16x4xf32>766 // expected-error@+1 {{expected result type to be 'memref<8x16x4xf32, strided<[64, 4, 1]>>' or a rank-reduced version. (mismatch of result sizes)}}767 %1 = memref.subview %0[0, 0, 0][8, 16, 4][1, 1, 1]768 : memref<8x16x4xf32> to memref<16x4xf32>769 return770}771 772// -----773 774func.func @invalid_rank_reducing_subview(%arg0 : index, %arg1 : index, %arg2 : index) {775 %0 = memref.alloc() : memref<8x16x4xf32>776 // expected-error@+1 {{expected result type to be 'memref<8x16x4xf32, strided<[64, 4, 1], offset: 8>>' or a rank-reduced version. (mismatch of result sizes)}}777 %1 = memref.subview %0[0, 2, 0][8, 16, 4][1, 1, 1]778 : memref<8x16x4xf32> to memref<16x4xf32>779 return780}781 782// -----783 784func.func @invalid_rank_reducing_subview(%arg0 : memref<?x?xf32>, %arg1 : index, %arg2 : index) {785 // expected-error@+1 {{expected result type to be 'memref<?x1xf32, strided<[?, 1], offset: ?>>' or a rank-reduced version. (mismatch of result layout)}}786 %0 = memref.subview %arg0[0, %arg1][%arg2, 1][1, 1] : memref<?x?xf32> to memref<?xf32>787 return788}789 790// -----791 792#map0 = affine_map<(d0, d1)[s0] -> (d0 * 16 + d1)>793 794func.func @subview_bad_offset_1(%arg0: memref<16x16xf32>) {795 %c0 = arith.constant 0 : index796 %c8 = arith.constant 8 : index797 // expected-error @+1 {{expected result type to be 'memref<8x8xf32, strided<[16, 1], offset: ?>>' or a rank-reduced version}}798 %s2 = memref.subview %arg0[%c8, %c8][8, 8][1, 1] : memref<16x16xf32> to memref<8x8xf32, #map0>799 return800}801 802// -----803 804#map0 = affine_map<(d0, d1)[s0] -> (d0 * 16 + d1 + 136)>805 806func.func @subview_bad_offset_2(%arg0: memref<16x16xf32>) {807 %c0 = arith.constant 0 : index808 %c8 = arith.constant 8 : index809 // expected-error @+1 {{expected result type to be 'memref<8x8xf32, strided<[16, 1], offset: ?>>' or a rank-reduced version}}810 %s2 = memref.subview %arg0[%c8, 8][8, 8][1, 1] : memref<16x16xf32> to memref<8x8xf32, #map0>811 return812}813 814// -----815 816func.func @subview_bad_offset_3(%arg0: memref<16x16xf32>) {817 %c0 = arith.constant 0 : index818 %c8 = arith.constant 8 : index819 // expected-error @+1 {{expected result type to be 'memref<8x8xf32, strided<[16, 1], offset: ?>>' or a rank-reduced version}}820 %s2 = memref.subview %arg0[%c8, 8][8, 8][1, 1] : memref<16x16xf32> to memref<8x8xf32, strided<[16, 1], offset: 437>>821 return822}823 824// -----825 826func.func @invalid_memref_cast(%arg0 : memref<12x4x16xf32, strided<[64, 16, 1], offset: 0>>) {827 // expected-error@+1{{operand type 'memref<12x4x16xf32, strided<[64, 16, 1]>>' and result type 'memref<12x4x16xf32, strided<[128, 32, 2]>>' are cast incompatible}}828 %0 = memref.cast %arg0 : memref<12x4x16xf32, strided<[64, 16, 1], offset: 0>> to memref<12x4x16xf32, strided<[128, 32, 2], offset: 0>>829 return830}831 832// -----833 834func.func @invalid_memref_cast(%arg0 : memref<12x4x16xf32, strided<[64, 16, 1], offset: 0>>) {835 // expected-error@+1{{operand type 'memref<12x4x16xf32, strided<[64, 16, 1]>>' and result type 'memref<12x4x16xf32, strided<[64, 16, 1], offset: 16>>' are cast incompatible}}836 %0 = memref.cast %arg0 : memref<12x4x16xf32, strided<[64, 16, 1], offset: 0>> to memref<12x4x16xf32, strided<[64, 16, 1], offset: 16>>837 return838}839 840// -----841 842// incompatible element types843func.func @invalid_memref_cast() {844 %0 = memref.alloc() : memref<2x5xf32, 0>845 // expected-error@+1 {{operand type 'memref<2x5xf32>' and result type 'memref<*xi32>' are cast incompatible}}846 %1 = memref.cast %0 : memref<2x5xf32, 0> to memref<*xi32>847 return848}849 850// -----851 852func.func @invalid_prefetch_rw(%i : index) {853 %0 = memref.alloc() : memref<10xf32>854 // expected-error@+1 {{rw specifier has to be 'read' or 'write'}}855 memref.prefetch %0[%i], rw, locality<0>, data : memref<10xf32>856 return857}858 859// -----860 861func.func @invalid_prefetch_cache_type(%i : index) {862 %0 = memref.alloc() : memref<10xf32>863 // expected-error@+1 {{cache type has to be 'data' or 'instr'}}864 memref.prefetch %0[%i], read, locality<0>, false : memref<10xf32>865 return866}867 868// -----869 870func.func @invalid_prefetch_locality_hint(%i : index) {871 %0 = memref.alloc() : memref<10xf32>872 // expected-error@+1 {{32-bit signless integer attribute whose minimum value is 0 whose maximum value is 3}}873 memref.prefetch %0[%i], read, locality<5>, data : memref<10xf32>874 return875}876 877// -----878 879// incompatible memory space880func.func @invalid_memref_cast() {881 %0 = memref.alloc() : memref<2x5xf32, 0>882 // expected-error@+1 {{operand type 'memref<2x5xf32>' and result type 'memref<*xf32, 1>' are cast incompatible}}883 %1 = memref.cast %0 : memref<2x5xf32, 0> to memref<*xf32, 1>884 return885}886 887// -----888 889// unranked to unranked890func.func @invalid_memref_cast() {891 %0 = memref.alloc() : memref<2x5xf32, 0>892 %1 = memref.cast %0 : memref<2x5xf32, 0> to memref<*xf32, 0>893 // expected-error@+1 {{operand type 'memref<*xf32>' and result type 'memref<*xf32>' are cast incompatible}}894 %2 = memref.cast %1 : memref<*xf32, 0> to memref<*xf32, 0>895 return896}897 898// -----899 900// alignment is not power of 2.901func.func @assume_alignment(%0: memref<4x4xf16>) {902 // expected-error@+1 {{alignment must be power of 2}}903 %1 = memref.assume_alignment %0, 12 : memref<4x4xf16>904 return905}906 907// -----908 909// 0 alignment value.910func.func @assume_alignment(%0: memref<4x4xf16>) {911 // expected-error@+1 {{attribute 'alignment' failed to satisfy constraint: 32-bit signless integer attribute whose value is positive}}912 %1 = memref.assume_alignment %0, 0 : memref<4x4xf16>913 return914}915 916// -----917 918"alloca_without_scoped_alloc_parent"() ({919 memref.alloca() : memref<1xf32>920 // expected-error@-1 {{requires an ancestor op with AutomaticAllocationScope trait}}921 func.return922}) : () -> ()923 924// -----925 926func.func @bad_alloc_wrong_dynamic_dim_count() {927^bb0:928 %0 = arith.constant 7 : index929 // Test alloc with wrong number of dynamic dimensions.930 // expected-error@+1 {{dimension operand count does not equal memref dynamic dimension count}}931 %1 = memref.alloc(%0)[%0] : memref<2x4xf32, affine_map<(d0, d1)[s0] -> ((d0 + s0), d1)>, 1>932 return933}934 935// -----936 937func.func @bad_alloc_wrong_symbol_count() {938^bb0:939 %0 = arith.constant 7 : index940 // Test alloc with wrong number of symbols941 // expected-error@+1 {{symbol operand count does not equal memref symbol count}}942 %1 = memref.alloc(%0) : memref<2x?xf32, affine_map<(d0, d1)[s0] -> ((d0 + s0), d1)>, 1>943 return944}945 946// -----947 948func.func @load_invalid_memref_indexes() {949 %0 = memref.alloca() : memref<10xi32>950 %c0 = arith.constant 0 : index951 // expected-error@+1 {{incorrect number of indices for load, expected 1 but got 2}}952 %1 = memref.load %0[%c0, %c0] : memref<10xi32>953}954 955// -----956 957func.func @test_store_zero_results() {958^bb0:959 %0 = memref.alloc() : memref<1024x64xf32, affine_map<(d0, d1) -> (d0, d1)>, 1>960 %1 = arith.constant 0 : index961 %2 = arith.constant 1 : index962 %3 = memref.load %0[%1, %2] : memref<1024x64xf32, affine_map<(d0, d1) -> (d0, d1)>, 1>963 // Test that store returns zero results.964 %4 = memref.store %3, %0[%1, %2] : memref<1024x64xf32, affine_map<(d0, d1) -> (d0, d1)>, 1> // expected-error {{cannot name an operation with no results}}965 return966}967 968// -----969 970func.func @test_store_zero_results2(%x: i32, %p: memref<i32>) {971 "memref.store"(%x,%p) : (i32, memref<i32>) -> i32 // expected-error {{'memref.store' op requires zero results}}972 return973}974 975// -----976 977func.func @invalid_load_alignment(%memref: memref<4xi32>) {978 %c0 = arith.constant 0 : index979 // expected-error @below {{'memref.load' op attribute 'alignment' failed to satisfy constraint: 64-bit signless integer attribute whose value is positive and whose value is a power of two > 0}}980 %val = memref.load %memref[%c0] { alignment = -1 } : memref<4xi32>981 return982}983 984// -----985 986func.func @invalid_store_alignment(%memref: memref<4xi32>, %val: i32) {987 %c0 = arith.constant 0 : index988 // expected-error @below {{'memref.store' op attribute 'alignment' failed to satisfy constraint: 64-bit signless integer attribute whose value is positive and whose value is a power of two > 0}}989 memref.store %val, %memref[%c0] { alignment = 3 } : memref<4xi32>990 return991}992 993// -----994 995func.func @invalid_alloc_alignment() {996 // expected-error @below {{'memref.alloc' op attribute 'alignment' failed to satisfy constraint: 64-bit signless integer attribute whose value is positive and whose value is a power of two > 0}}997 %0 = memref.alloc() {alignment = 3} : memref<4xf32>998 return999}1000 1001// -----1002 1003func.func @invalid_realloc_alignment(%src: memref<4xf32>) {1004 // expected-error @below {{'memref.realloc' op attribute 'alignment' failed to satisfy constraint: 64-bit signless integer attribute whose value is positive and whose value is a power of two > 0}}1005 %0 = memref.realloc %src {alignment = 7} : memref<4xf32> to memref<8xf32>1006 return1007}1008 1009// -----1010 1011func.func @test_alloc_memref_map_rank_mismatch() {1012^bb0:1013 // expected-error@+1 {{memref layout mismatch between rank and affine map: 2 != 1}}1014 %0 = memref.alloc() : memref<1024x64xf32, affine_map<(d0) -> (d0)>, 1>1015 return1016}1017 1018// -----1019 1020func.func @rank(%0: f32) {1021 // expected-error@+1 {{'memref.rank' op operand #0 must be ranked or unranked memref of any type values}}1022 "memref.rank"(%0): (f32)->index1023 return1024}1025 1026// -----1027 1028#map = affine_map<(d0, d1, d2)[s0, s1, s2, s3] -> (s0 + d0 * s1 + d1 * s2 + d2 * s3)>1029func.func @illegal_num_offsets(%arg0 : memref<?x?x?xf32>, %arg1 : index, %arg2 : index) {1030 // expected-error@+1 {{expected 3 offset values}}1031 %0 = memref.subview %arg0[0, 0] [%arg1, %arg2] [1, 1] : memref<?x?x?xf32> to memref<?x?x?xf32, #map>1032}1033 1034// -----1035 1036func.func @atomic_rmw_idxs_rank_mismatch(%I: memref<16x10xf32>, %i : index, %val : f32) {1037 // expected-error@+1 {{expects the number of subscripts to be equal to memref rank}}1038 %x = memref.atomic_rmw addf %val, %I[%i] : (f32, memref<16x10xf32>) -> f321039 return1040}1041 1042// -----1043 1044func.func @atomic_rmw_expects_float(%I: memref<16x10xi32>, %i : index, %val : i32) {1045 // expected-error@+1 {{expects a floating-point type}}1046 %x = memref.atomic_rmw addf %val, %I[%i, %i] : (i32, memref<16x10xi32>) -> i321047 return1048}1049 1050// -----1051 1052func.func @atomic_rmw_expects_int(%I: memref<16x10xf32>, %i : index, %val : f32) {1053 // expected-error@+1 {{expects an integer type}}1054 %x = memref.atomic_rmw addi %val, %I[%i, %i] : (f32, memref<16x10xf32>) -> f321055 return1056}1057 1058// -----1059 1060func.func @generic_atomic_rmw_wrong_arg_num(%I: memref<10xf32>, %i : index) {1061 // expected-error@+1 {{expected single number of entry block arguments}}1062 %x = memref.generic_atomic_rmw %I[%i] : memref<10xf32> {1063 ^bb0(%arg0 : f32, %arg1 : f32):1064 %c1 = arith.constant 1.0 : f321065 memref.atomic_yield %c1 : f321066 }1067 return1068}1069 1070// -----1071 1072func.func @generic_atomic_rmw_wrong_arg_type(%I: memref<10xf32>, %i : index) {1073 // expected-error@+1 {{expected block argument of the same type result type}}1074 %x = memref.generic_atomic_rmw %I[%i] : memref<10xf32> {1075 ^bb0(%old_value : i32):1076 %c1 = arith.constant 1.0 : f321077 memref.atomic_yield %c1 : f321078 }1079 return1080}1081 1082// -----1083 1084func.func @generic_atomic_rmw_result_type_mismatch(%I: memref<10xf32>, %i : index) {1085 // expected-error@+1 {{failed to verify that result type matches element type of memref}}1086 %0 = "memref.generic_atomic_rmw"(%I, %i) ({1087 ^bb0(%old_value: f32):1088 %c1 = arith.constant 1.0 : f321089 memref.atomic_yield %c1 : f321090 }) : (memref<10xf32>, index) -> i321091 return1092}1093 1094// -----1095 1096func.func @generic_atomic_rmw_has_side_effects(%I: memref<10xf32>, %i : index) {1097 // expected-error@+4 {{should contain only operations with no side effects}}1098 %x = memref.generic_atomic_rmw %I[%i] : memref<10xf32> {1099 ^bb0(%old_value : f32):1100 %c1 = arith.constant 1.0 : f321101 %buf = memref.alloc() : memref<2048xf32>1102 memref.atomic_yield %c1 : f321103 }1104}1105 1106// -----1107 1108func.func @atomic_yield_type_mismatch(%I: memref<10xf32>, %i : index) {1109 // expected-error@+4 {{op types mismatch between yield op: 'i32' and its parent: 'f32'}}1110 %x = memref.generic_atomic_rmw %I[%i] : memref<10xf32> {1111 ^bb0(%old_value : f32):1112 %c1 = arith.constant 1 : i321113 memref.atomic_yield %c1 : i321114 }1115 return1116}1117 1118// -----1119 1120#map0 = affine_map<(d0) -> (d0 floordiv 8, d0 mod 8)>1121func.func @memref_realloc_layout(%src : memref<256xf32, #map0>) -> memref<?xf32>{1122 // expected-error@+1 {{unsupported layout}}1123 %0 = memref.realloc %src : memref<256xf32, #map0> to memref<?xf32>1124 return %0 : memref<?xf32>1125}1126 1127// -----1128 1129func.func @memref_realloc_sizes_1(%src : memref<2xf32>) -> memref<?xf32>{1130 // expected-error@+1 {{missing dimension operand}}1131 %0 = memref.realloc %src : memref<2xf32> to memref<?xf32>1132 return %0 : memref<?xf32>1133}1134 1135// -----1136 1137func.func @memref_realloc_sizes_2(%src : memref<?xf32>, %d : index)1138 -> memref<4xf32>{1139 // expected-error@+1 {{unnecessary dimension operand}}1140 %0 = memref.realloc %src(%d) : memref<?xf32> to memref<4xf32>1141 return %0 : memref<4xf32>1142}1143 1144// -----1145 1146func.func @memref_realloc_type(%src : memref<256xf32>) -> memref<?xi32>{1147 // expected-error@+1 {{different element types}}1148 %0 = memref.realloc %src : memref<256xf32> to memref<?xi32>1149 return %0 : memref<?xi32>1150}1151 1152// -----1153 1154// Asking the dimension of a 0-D shape doesn't make sense.1155func.func @dim_0_ranked(%arg : memref<f32>, %arg1 : index) {1156 memref.dim %arg, %arg1 : memref<f32> // expected-error {{'memref.dim' op operand #0 must be unranked.memref of any type values or non-0-ranked.memref of any type values, but got 'memref<f32>'}}1157 return1158}1159 1160// -----1161 1162func.func @subview_invalid_strides(%m: memref<7x22x333x4444xi32>) {1163 // expected-error @below{{expected result type to be 'memref<7x11x333x4444xi32, strided<[32556744, 2959704, 4444, 1]>>' or a rank-reduced version. (mismatch of result layout)}}1164 %subview = memref.subview %m[0, 0, 0, 0] [7, 11, 333, 4444] [1, 2, 1, 1]1165 : memref<7x22x333x4444xi32> to memref<7x11x333x4444xi32>1166 return1167}1168 1169// -----1170 1171func.func @subview_invalid_strides_rank_reduction(%m: memref<7x22x333x4444xi32>) {1172 // expected-error @below{{expected result type to be 'memref<7x11x1x4444xi32, strided<[32556744, 2959704, 4444, 1]>>' or a rank-reduced version. (mismatch of result layout)}}1173 %subview = memref.subview %m[0, 0, 0, 0] [7, 11, 1, 4444] [1, 2, 1, 1]1174 : memref<7x22x333x4444xi32> to memref<7x11x4444xi32>1175 return1176}1177 1178// -----1179 1180func.func @expand_shape_invalid_output_shape(1181 %arg0: memref<30x20xf32, strided<[4000, 2], offset: 100>>) {1182 // expected-error @+1 {{invalid output shape provided at pos 2}}1183 %0 = memref.expand_shape %arg0 [[0, 1], [2]] output_shape [2, 15, 21] :1184 memref<30x20xf32, strided<[4000, 2], offset: 100>>1185 into memref<2x15x20xf32, strided<[60000, 4000, 2], offset: 100>>1186 return1187}1188 1189// -----1190 1191func.func @distinct_objects_types_mismatch(%arg0: memref<?xf32>, %arg1: memref<?xi32>) -> (memref<?xi32>, memref<?xf32>) {1192 // expected-error @+1 {{operand types and result types must match}}1193 %0, %1 = "memref.distinct_objects"(%arg0, %arg1) : (memref<?xf32>, memref<?xi32>) -> (memref<?xi32>, memref<?xf32>)1194 return %0, %1 : memref<?xi32>, memref<?xf32>1195}1196 1197// -----1198 1199func.func @distinct_objects_0_operands() {1200 // expected-error @+1 {{expected at least one operand}}1201 "memref.distinct_objects"() : () -> ()1202 return1203}1204