xref: /llvm-project/mlir/test/Dialect/MemRef/invalid.mlir (revision dbe159b3f74ea41e16782fe5708756507d4a014f)
1// RUN: mlir-opt -allow-unregistered-dialect -split-input-file %s -verify-diagnostics
2
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, f32
13}
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, f32
39}
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>, f32
77}
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  return
126}
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 to
154           offset: [0, 0], sizes: [10, 10], strides: [10, 1]
155           : memref<?xf32> to memref<10x10xf32, strided<[10, 1], offset: 0>>
156  return
157}
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 to
164           offset: [0], sizes: [10], strides: [1]
165         : memref<*xf32> to memref<10xi32, strided<[1], offset: 0>>
166  return
167}
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 to
174           offset: [0], sizes: [10], strides: [1]
175         : memref<*xf32> to memref<10xi32, strided<[1], offset: 0>, 2>
176  return
177}
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 to
184           offset: [1], sizes: [10], strides: [1]
185         : memref<?xf32> to memref<10xf32, strided<[1], offset: 2>>
186  return
187}
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 to
194           offset: [0], sizes: [10], strides: [1]
195         : memref<*xf32> to memref<1xf32, strided<[1], offset: 0>>
196  return
197}
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 to
204           offset: [2], sizes: [10], strides: [2]
205         : memref<?xf32> to memref<10xf32, strided<[1], offset: 2>>
206  return
207}
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  return
216}
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  return
225}
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  return
234}
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 to
241           offset: [0], sizes: [9, 10], strides: [42, 1]
242         : memref<?x?xf32> to memref<9x10xf32>
243  return
244}
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 : i32
295
296// -----
297
298// expected-error @+1 {{type should be static shaped memref}}
299memref.global @foo : i32 = 5
300
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>  = uninitialized
342
343// -----
344
345func.func @nonexistent_global_memref() {
346  // expected-error @+1 {{'gv' does not reference a valid global memref}}
347  %0 = memref.get_global @gv : memref<3xf32>
348  return
349}
350
351// -----
352
353func.func private @foo()
354
355func.func @nonexistent_global_memref() {
356  // expected-error @+1 {{'foo' does not reference a valid global memref}}
357  %0 = memref.get_global @foo : memref<3xf32>
358  return
359}
360
361// -----
362
363memref.global @gv : memref<3xi32>
364
365func.func @mismatched_types() {
366  // expected-error @+1 {{result type 'memref<3xf32>' does not match type 'memref<3xi32>' of the global memref @gv}}
367  %0 = memref.get_global @gv : memref<3xf32>
368  return
369}
370
371// -----
372
373// expected-error @+1 {{alignment attribute value 63 is not a power of 2}}
374memref.global "private" @gv : memref<4xf32> = dense<1.0> { alignment = 63 }
375
376// -----
377
378func.func @copy_different_shape(%arg0: memref<2xf32>, %arg1: memref<3xf32>) {
379  // expected-error @+1 {{op requires the same shape for all operands}}
380  memref.copy %arg0, %arg1 : memref<2xf32> to memref<3xf32>
381  return
382}
383
384// -----
385
386func.func @copy_different_eltype(%arg0: memref<2xf32>, %arg1: memref<2xf16>) {
387  // expected-error @+1 {{op requires the same element type for all operands}}
388  memref.copy %arg0, %arg1 : memref<2xf32> to memref<2xf16>
389  return
390}
391
392// -----
393
394func.func @expand_shape(%arg0: memref<?x?xf32>, %sz0: index, %sz1: index) {
395  // expected-error @+1 {{invalid number of reassociation groups: found 1, expected 2}}
396  %0 = memref.expand_shape %arg0 [[0, 1]] output_shape [%sz0, 5, %sz1] : memref<?x?xf32> into memref<?x5x?xf32>
397  return
398}
399
400// -----
401
402func.func @expand_shape(%arg0: memref<f32>) {
403  // expected-error @+1 {{rank 0 memrefs can only be extended/collapsed with/from ones}}
404  %0 = memref.expand_shape %arg0 [] output_shape [1, 2] : memref<f32> into memref<1x2xf32>
405  return
406}
407
408// -----
409
410func.func @expand_shape_illegal_output_shape(%arg0: memref<2xf32>) {
411  // expected-error @+1 {{expected number of static shape bounds to be equal to the output rank (3) but found 2 inputs instead}}
412  %0 = memref.expand_shape %arg0 [[0, 1, 2]] output_shape [1, 2] : memref<2xf32> into memref<1x1x2xf32>
413  return
414}
415
416// -----
417
418func.func @collapse_shape_out_of_bounds(%arg0: memref<?x?xf32>) {
419  // expected-error @+1 {{op reassociation index 2 is out of bounds}}
420  %0 = memref.collapse_shape %arg0 [[0, 1, 2]] : memref<?x?xf32> into memref<?xf32>
421}
422
423// -----
424
425func.func @expand_shape_out_of_bounds(%arg0: memref<?xf32>, %sz0: index) {
426  // expected-error @+1 {{op reassociation index 2 is out of bounds}}
427  %0 = memref.expand_shape %arg0 [[0, 1, 2]] output_shape [4, %sz0] : memref<?xf32> into memref<4x?xf32>
428}
429
430// -----
431
432func.func @expand_shape_invalid_result_layout(
433    %arg0: memref<30x20xf32, strided<[4000, 2], offset: 100>>) {
434  // 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>>'}}
435  %0 = memref.expand_shape %arg0 [[0, 1], [2]] output_shape [2, 15, 20] :
436      memref<30x20xf32, strided<[4000, 2], offset: 100>>
437      into memref<2x15x20xf32, strided<[5000, 4000, 2], offset: 100>>
438}
439
440// -----
441
442func.func @collapse_shape_mismatch_indices_num(%arg0: memref<?x?x?xf32>) {
443  // expected-error @+1 {{invalid number of reassociation groups: found 1, expected 2}}
444  %0 = memref.collapse_shape %arg0 [[0, 1]] :
445    memref<?x?x?xf32> into memref<?x?xf32, strided<[?, 1], offset: 0>>
446}
447
448// -----
449
450func.func @collapse_shape_invalid_reassociation(%arg0: memref<?x?x?xf32>) {
451  // expected-error @+1 {{reassociation indices must be contiguous}}
452  %0 = memref.collapse_shape %arg0 [[0, 1], [1, 2]] :
453    memref<?x?x?xf32> into memref<?x?xf32, strided<[?, 1], offset: 0>>
454}
455
456// -----
457
458// An (invalid) attempt at using collapse_shape to increase the rank might look
459// like this. Verify that a sensible error is emitted in this case.
460func.func @collapse_shape_invalid_reassociation_expansion(%arg0: memref<?xf32>) {
461  // expected-error @+1 {{'memref.collapse_shape' op has source rank 1 and result rank 2. This is not a collapse (1 < 2)}}
462  %0 = memref.collapse_shape %arg0 [[0], [0]] :
463    memref<?xf32> into memref<?x?xf32>
464}
465
466// -----
467
468// An (invalid) attempt at using expand_shape to reduce the rank might look
469// like this. Verify that a sensible error is emitted in this case.
470func.func @expand_shape_invalid_reassociation(%arg0: memref<2x3x1xf32>) {
471  // expected-error @+1 {{'memref.expand_shape' op has source rank 3 and result rank 2. This is not an expansion (3 > 2)}}
472  %0 = memref.expand_shape %arg0 [[0], [1], [1]] output_shape [2, 3] :
473    memref<2x3x1xf32> into memref<2x3xf32>
474}
475
476// -----
477
478func.func @collapse_shape_invalid_reassociation_expansion(%arg0: memref<?x?xf32>) {
479  // expected-error @+1 {{reassociation indices must be contiguous}}
480  %0 = memref.collapse_shape %arg0 [[1], [0]] :
481    memref<?x?xf32> into memref<?x?xf32>
482}
483
484// -----
485
486func.func @collapse_shape_reshaping_non_contiguous(
487    %arg0: memref<3x4x5xf32, strided<[270, 50, 10], offset: 0>>) {
488  // expected-error @+1 {{invalid source layout map or collapsing non-contiguous dims}}
489  %0 = memref.collapse_shape %arg0 [[0, 1], [2]] :
490      memref<3x4x5xf32, strided<[270, 50, 10], offset: 0>>
491      into memref<12x5xf32, strided<[50, 1], offset: 0>>
492  return
493}
494
495// -----
496
497func.func @collapse_shape_wrong_collapsed_type(%arg0: memref<?x?x?xf32>) {
498  // expected-error @+1 {{expected collapsed type to be 'memref<?x?xf32>' but found 'memref<?x?xf32, affine_map<(d0, d1)[s0] -> (d0 * s0 + d1)>>'}}
499  %0 = memref.collapse_shape %arg0 [[0, 1], [2]] :
500    memref<?x?x?xf32> into memref<?x?xf32, affine_map<(d0, d1)[s0] -> (d0 * s0 + d1)>>
501}
502
503// -----
504
505func.func @expand_shape_illegal_static_memref
506  (%arg0: memref<2x3x20xf32>) -> memref<2x3x2x4x5xf32> {
507  // expected-error @+1 {{collapsed dim size (20) must equal reassociation group size (40)}}
508  %0 = memref.expand_shape %arg0 [[0], [1], [2, 3, 4]] output_shape [2, 3, 2, 4, 5]
509      : memref<2x3x20xf32> into memref<2x3x2x4x5xf32>
510  return %0 : memref<2x3x2x4x5xf32>
511}
512
513// -----
514
515func.func @collapse_shape_illegal_static_memref
516  (%arg0: memref<2x3x2x4x5xf32>) -> memref<2x3x20xf32> {
517  // expected-error @+1 {{collapsed dim size (20) must equal reassociation group size (40)}}
518  %0 = memref.collapse_shape %arg0 [[0], [1], [2, 3, 4]]
519      : memref<2x3x2x4x5xf32> into memref<2x3x20xf32>
520  return %0 : memref<2x3x20xf32>
521}
522
523// -----
524
525func.func @expand_shape_illegal_mixed_memref(%arg0 : memref<?x?xf32>, %sz0: index)
526    -> memref<?x4x5xf32> {
527  // expected-error @+1 {{collapsed dim (1) must be dynamic if and only if reassociation group is dynamic}}
528  %0 = memref.expand_shape %arg0 [[0, 1], [2]] output_shape [%sz0, 4, 5]
529      : memref<?x?xf32> into memref<?x4x5xf32>
530  return %0 : memref<?x4x5xf32>
531}
532
533// -----
534
535func.func @expand_shape_illegal_mixed_memref_2(%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_invalid_static_dim_size(%arg0 : memref<?x21xf32>, %sz0: index)
546    -> memref<?x4x5xf32> {
547  // expected-error @+1 {{collapsed dim size (21) must equal reassociation group size (20)}}
548  %0 = memref.expand_shape %arg0 [[0], [1, 2]] output_shape [%sz0, 4, 5]
549      : memref<?x21xf32> into memref<?x4x5xf32>
550  return %0 : memref<?x4x5xf32>
551}
552
553// -----
554
555func.func @collapse_shape_illegal_mixed_memref(%arg0 : memref<?x4x5xf32>)
556    -> memref<?x?xf32> {
557  // expected-error @+1 {{collapsed dim (1) must be dynamic if and only if reassociation group is dynamic}}
558  %0 = memref.collapse_shape %arg0 [[0, 1], [2]]
559      : memref<?x4x5xf32> into memref<?x?xf32>
560  return %0 : memref<?x?xf32>
561}
562
563// -----
564
565func.func @collapse_shape_illegal_mixed_memref_2(%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 @invalid_view(%arg0 : index, %arg1 : index, %arg2 : index) {
576  %0 = memref.alloc() : memref<2048xi8>
577  // expected-error@+1 {{expected SSA operand}}
578  %1 = memref.view %0[][%arg0, %arg1]
579    : memref<2048xi8> to memref<?x?xf32>
580  return
581}
582
583// -----
584
585func.func @invalid_view(%arg0 : index, %arg1 : index, %arg2 : index) {
586  %0 = memref.alloc() : memref<2048xi8, affine_map<(d0) -> (d0 floordiv 8, d0 mod 8)>>
587  // expected-error@+1 {{unsupported map for base memref type}}
588  %1 = memref.view %0[%arg2][%arg0, %arg1]
589    : memref<2048xi8, affine_map<(d0) -> (d0 floordiv 8, d0 mod 8)>> to
590      memref<?x?xf32, affine_map<(d0, d1)[s0] -> (d0 * 4 + d1 + s0)>>
591  return
592}
593
594// -----
595
596func.func @invalid_view(%arg0 : index, %arg1 : index, %arg2 : index) {
597  %0 = memref.alloc() : memref<2048xi8>
598  // expected-error@+1 {{unsupported map for result memref type}}
599  %1 = memref.view %0[%arg2][%arg0, %arg1]
600    : memref<2048xi8> to memref<?x?xf32, affine_map<(d0, d1)[s0] -> (d0, d1, s0)>>
601  return
602}
603
604// -----
605
606func.func @invalid_view(%arg0 : index, %arg1 : index, %arg2 : index) {
607  %0 = memref.alloc() : memref<2048xi8, 2>
608  // expected-error@+1 {{different memory spaces}}
609  %1 = memref.view %0[%arg2][%arg0, %arg1] :  memref<2048xi8, 2> to memref<?x?xf32, 1>
610  return
611}
612
613// -----
614
615func.func @invalid_view(%arg0 : index, %arg1 : index, %arg2 : index) {
616  %0 = memref.alloc() : memref<2048xi8>
617  // expected-error@+1 {{incorrect number of size operands for type}}
618  %1 = memref.view %0[%arg2][%arg0]
619    : memref<2048xi8> to memref<?x?xf32>
620  return
621}
622
623// -----
624
625func.func @invalid_subview(%input: memref<4x1024xf32>) -> memref<2x256xf32, strided<[1024, 1], offset: 2304>> {
626  // expected-error@+1 {{expected offsets to be non-negative, but got -1}}
627  %0 = memref.subview %input[-1, 256] [2, 256] [1, 1] : memref<4x1024xf32> to memref<2x256xf32, strided<[1024, 1], offset: 2304>>
628  return %0 : memref<2x256xf32, strided<[1024, 1], offset: 2304>>
629}
630
631// -----
632
633func.func @invalid_subview(%input: memref<4x1024xf32>) -> memref<2x256xf32, strided<[1024, 1], offset: 2304>> {
634  // expected-error@+1 {{expected sizes to be non-negative, but got -1}}
635  %0 = memref.subview %input[2, 256] [-1, 256] [1, 1] : memref<4x1024xf32> to memref<2x256xf32, strided<[1024, 1], offset: 2304>>
636  return %0 : memref<2x256xf32, strided<[1024, 1], offset: 2304>>
637}
638
639// -----
640
641func.func @invalid_subview(%arg0 : index, %arg1 : index, %arg2 : index) {
642  %0 = memref.alloc() : memref<8x16x4xf32>
643  // 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}}
644  %1 = memref.subview %0[0, 0][2, 2, 2][1, 1, 1]
645    : memref<8x16x4xf32> to memref<8x16x4xf32>
646  return
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 sizes rank to match mixed strides rank (3 vs 2) so the rank of the result type is well-formed}}
654  %1 = memref.subview %0[0, 0, 0][2, 2, 2][1, 1]
655    : memref<8x16x4xf32> to memref<8x16x4xf32>
656  return
657}
658
659// -----
660
661func.func @invalid_subview(%arg0 : index, %arg1 : index, %arg2 : index) {
662  %0 = memref.alloc() : memref<8x16x4xf32>
663  // 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}}
664  %1 = memref.reinterpret_cast %0 to offset: [0], sizes: [2, 2, 2], strides:[1, 1]
665    : memref<8x16x4xf32> to memref<8x16x4xf32>
666  return
667}
668
669// -----
670
671func.func @invalid_subview(%arg0 : index, %arg1 : index, %arg2 : index) {
672  %0 = memref.alloc() : memref<8x16x4xf32, strided<[64, 4, 1], offset: 0>, 2>
673  // expected-error@+1 {{different memory spaces}}
674  %1 = memref.subview %0[0, 0, 0][%arg2, %arg2, %arg2][1, 1, 1]
675    : memref<8x16x4xf32, strided<[64, 4, 1], offset: 0>, 2> to
676      memref<8x?x4xf32, affine_map<(d0, d1, d2)[s0] -> (d0 * s0 + d1 * 4 + d2)>>
677  return
678}
679
680// -----
681
682func.func @invalid_subview(%arg0 : index, %arg1 : index, %arg2 : index) {
683  %0 = memref.alloc() : memref<8x16x4xf32, affine_map<(d0, d1, d2) -> (d0 + d1, d1 + d2, d2)>>
684  // expected-error@+1 {{is not strided}}
685  %1 = memref.subview %0[0, 0, 0][%arg2, %arg2, %arg2][1, 1, 1]
686    : memref<8x16x4xf32, affine_map<(d0, d1, d2) -> (d0 + d1, d1 + d2, d2)>> to
687      memref<8x?x4xf32, strided<[?, 4, 1], offset: 0>>
688  return
689}
690
691// -----
692
693func.func @invalid_subview(%arg0 : index, %arg1 : index, %arg2 : index) {
694  %0 = memref.alloc() : memref<8x16x4xf32>
695  // expected-error@+1 {{expected 3 offset values}}
696  %1 = memref.subview %0[%arg0, %arg1, 0, 0][%arg2, 0, 0, 0][1, 1, 1, 1]
697    : memref<8x16x4xf32> to
698      memref<8x?x4xf32, strided<[?, ?, 4], offset: 0>>
699  return
700}
701
702// -----
703
704func.func @invalid_subview(%arg0 : index, %arg1 : index, %arg2 : index) {
705  %0 = memref.alloc() : memref<8x16x4xf32>
706  // expected-error@+1 {{expected result element type to be 'f32'}}
707  %1 = memref.subview %0[0, 0, 0][8, 16, 4][1, 1, 1]
708    : memref<8x16x4xf32> to
709      memref<8x16x4xi32>
710  return
711}
712
713// -----
714
715func.func @invalid_subview(%arg0 : index, %arg1 : index, %arg2 : index) {
716  %0 = memref.alloc() : memref<8x16x4xf32>
717  // expected-error@+1 {{expected result rank to be smaller or equal to the source rank.}}
718  %1 = memref.subview %0[0, 0, 0][8, 16, 4][1, 1, 1]
719    : memref<8x16x4xf32> to
720      memref<8x16x4x3xi32>
721  return
722}
723
724// -----
725
726func.func @invalid_rank_reducing_subview(%arg0 : index, %arg1 : index, %arg2 : index) {
727  %0 = memref.alloc() : memref<8x16x4xf32>
728  // expected-error@+1 {{expected result type to be 'memref<8x16x4xf32, strided<[64, 4, 1]>>' or a rank-reduced version. (mismatch of result sizes)}}
729  %1 = memref.subview %0[0, 0, 0][8, 16, 4][1, 1, 1]
730    : memref<8x16x4xf32> to memref<16x4xf32>
731  return
732}
733
734// -----
735
736func.func @invalid_rank_reducing_subview(%arg0 : index, %arg1 : index, %arg2 : index) {
737  %0 = memref.alloc() : memref<8x16x4xf32>
738  // 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)}}
739  %1 = memref.subview %0[0, 2, 0][8, 16, 4][1, 1, 1]
740    : memref<8x16x4xf32> to memref<16x4xf32>
741  return
742}
743
744// -----
745
746func.func @invalid_rank_reducing_subview(%arg0 : memref<?x?xf32>, %arg1 : index, %arg2 : index) {
747  // expected-error@+1 {{expected result type to be 'memref<?x1xf32, strided<[?, 1], offset: ?>>' or a rank-reduced version. (mismatch of result layout)}}
748  %0 = memref.subview %arg0[0, %arg1][%arg2, 1][1, 1] : memref<?x?xf32> to memref<?xf32>
749  return
750}
751
752// -----
753
754#map0 = affine_map<(d0, d1)[s0] -> (d0 * 16 + d1)>
755
756func.func @subview_bad_offset_1(%arg0: memref<16x16xf32>) {
757  %c0 = arith.constant 0 : index
758  %c8 = arith.constant 8 : index
759  // expected-error @+1 {{expected result type to be 'memref<8x8xf32, strided<[16, 1], offset: ?>>' or a rank-reduced version}}
760  %s2 = memref.subview %arg0[%c8, %c8][8, 8][1, 1]  : memref<16x16xf32> to memref<8x8xf32, #map0>
761  return
762}
763
764// -----
765
766#map0 = affine_map<(d0, d1)[s0] -> (d0 * 16 + d1 + 136)>
767
768func.func @subview_bad_offset_2(%arg0: memref<16x16xf32>) {
769  %c0 = arith.constant 0 : index
770  %c8 = arith.constant 8 : index
771  // expected-error @+1 {{expected result type to be 'memref<8x8xf32, strided<[16, 1], offset: ?>>' or a rank-reduced version}}
772  %s2 = memref.subview %arg0[%c8, 8][8, 8][1, 1]  : memref<16x16xf32> to memref<8x8xf32, #map0>
773  return
774}
775
776// -----
777
778func.func @subview_bad_offset_3(%arg0: memref<16x16xf32>) {
779  %c0 = arith.constant 0 : index
780  %c8 = arith.constant 8 : index
781  // expected-error @+1 {{expected result type to be 'memref<8x8xf32, strided<[16, 1], offset: ?>>' or a rank-reduced version}}
782  %s2 = memref.subview %arg0[%c8, 8][8, 8][1, 1]  : memref<16x16xf32> to memref<8x8xf32, strided<[16, 1], offset: 437>>
783  return
784}
785
786// -----
787
788func.func @invalid_memref_cast(%arg0 : memref<12x4x16xf32, strided<[64, 16, 1], offset: 0>>) {
789  // expected-error@+1{{operand type 'memref<12x4x16xf32, strided<[64, 16, 1]>>' and result type 'memref<12x4x16xf32, strided<[128, 32, 2]>>' are cast incompatible}}
790  %0 = memref.cast %arg0 : memref<12x4x16xf32, strided<[64, 16, 1], offset: 0>> to memref<12x4x16xf32, strided<[128, 32, 2], offset: 0>>
791  return
792}
793
794// -----
795
796func.func @invalid_memref_cast(%arg0 : memref<12x4x16xf32, strided<[64, 16, 1], offset: 0>>) {
797  // 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}}
798  %0 = memref.cast %arg0 : memref<12x4x16xf32, strided<[64, 16, 1], offset: 0>> to memref<12x4x16xf32, strided<[64, 16, 1], offset: 16>>
799  return
800}
801
802// -----
803
804// incompatible element types
805func.func @invalid_memref_cast() {
806  %0 = memref.alloc() : memref<2x5xf32, 0>
807  // expected-error@+1 {{operand type 'memref<2x5xf32>' and result type 'memref<*xi32>' are cast incompatible}}
808  %1 = memref.cast %0 : memref<2x5xf32, 0> to memref<*xi32>
809  return
810}
811
812// -----
813
814func.func @invalid_prefetch_rw(%i : index) {
815  %0 = memref.alloc() : memref<10xf32>
816  // expected-error@+1 {{rw specifier has to be 'read' or 'write'}}
817  memref.prefetch %0[%i], rw, locality<0>, data  : memref<10xf32>
818  return
819}
820
821// -----
822
823func.func @invalid_prefetch_cache_type(%i : index) {
824  %0 = memref.alloc() : memref<10xf32>
825  // expected-error@+1 {{cache type has to be 'data' or 'instr'}}
826  memref.prefetch %0[%i], read, locality<0>, false  : memref<10xf32>
827  return
828}
829
830// -----
831
832func.func @invalid_prefetch_locality_hint(%i : index) {
833  %0 = memref.alloc() : memref<10xf32>
834  // expected-error@+1 {{32-bit signless integer attribute whose minimum value is 0 whose maximum value is 3}}
835  memref.prefetch %0[%i], read, locality<5>, data  : memref<10xf32>
836  return
837}
838
839// -----
840
841// incompatible memory space
842func.func @invalid_memref_cast() {
843  %0 = memref.alloc() : memref<2x5xf32, 0>
844  // expected-error@+1 {{operand type 'memref<2x5xf32>' and result type 'memref<*xf32, 1>' are cast incompatible}}
845  %1 = memref.cast %0 : memref<2x5xf32, 0> to memref<*xf32, 1>
846  return
847}
848
849// -----
850
851// unranked to unranked
852func.func @invalid_memref_cast() {
853  %0 = memref.alloc() : memref<2x5xf32, 0>
854  %1 = memref.cast %0 : memref<2x5xf32, 0> to memref<*xf32, 0>
855  // expected-error@+1 {{operand type 'memref<*xf32>' and result type 'memref<*xf32>' are cast incompatible}}
856  %2 = memref.cast %1 : memref<*xf32, 0> to memref<*xf32, 0>
857  return
858}
859
860// -----
861
862// alignment is not power of 2.
863func.func @assume_alignment(%0: memref<4x4xf16>) {
864  // expected-error@+1 {{alignment must be power of 2}}
865  memref.assume_alignment %0, 12 : memref<4x4xf16>
866  return
867}
868
869// -----
870
871// 0 alignment value.
872func.func @assume_alignment(%0: memref<4x4xf16>) {
873  // expected-error@+1 {{attribute 'alignment' failed to satisfy constraint: 32-bit signless integer attribute whose value is positive}}
874  memref.assume_alignment %0, 0 : memref<4x4xf16>
875  return
876}
877
878// -----
879
880"alloca_without_scoped_alloc_parent"() ({
881  memref.alloca() : memref<1xf32>
882  // expected-error@-1 {{requires an ancestor op with AutomaticAllocationScope trait}}
883  func.return
884}) : () -> ()
885
886// -----
887
888func.func @bad_alloc_wrong_dynamic_dim_count() {
889^bb0:
890  %0 = arith.constant 7 : index
891  // Test alloc with wrong number of dynamic dimensions.
892  // expected-error@+1 {{dimension operand count does not equal memref dynamic dimension count}}
893  %1 = memref.alloc(%0)[%0] : memref<2x4xf32, affine_map<(d0, d1)[s0] -> ((d0 + s0), d1)>, 1>
894  return
895}
896
897// -----
898
899func.func @bad_alloc_wrong_symbol_count() {
900^bb0:
901  %0 = arith.constant 7 : index
902  // Test alloc with wrong number of symbols
903  // expected-error@+1 {{symbol operand count does not equal memref symbol count}}
904  %1 = memref.alloc(%0) : memref<2x?xf32, affine_map<(d0, d1)[s0] -> ((d0 + s0), d1)>, 1>
905  return
906}
907
908// -----
909
910func.func @load_invalid_memref_indexes() {
911  %0 = memref.alloca() : memref<10xi32>
912  %c0 = arith.constant 0 : index
913  // expected-error@+1 {{incorrect number of indices for load, expected 1 but got 2}}
914  %1 = memref.load %0[%c0, %c0] : memref<10xi32>
915}
916
917// -----
918
919func.func @test_store_zero_results() {
920^bb0:
921  %0 = memref.alloc() : memref<1024x64xf32, affine_map<(d0, d1) -> (d0, d1)>, 1>
922  %1 = arith.constant 0 : index
923  %2 = arith.constant 1 : index
924  %3 = memref.load %0[%1, %2] : memref<1024x64xf32, affine_map<(d0, d1) -> (d0, d1)>, 1>
925  // Test that store returns zero results.
926  %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}}
927  return
928}
929
930// -----
931
932func.func @test_store_zero_results2(%x: i32, %p: memref<i32>) {
933  "memref.store"(%x,%p) : (i32, memref<i32>) -> i32  // expected-error {{'memref.store' op requires zero results}}
934  return
935}
936
937// -----
938
939func.func @test_alloc_memref_map_rank_mismatch() {
940^bb0:
941  // expected-error@+1 {{memref layout mismatch between rank and affine map: 2 != 1}}
942  %0 = memref.alloc() : memref<1024x64xf32, affine_map<(d0) -> (d0)>, 1>
943  return
944}
945
946// -----
947
948func.func @rank(%0: f32) {
949  // expected-error@+1 {{'memref.rank' op operand #0 must be ranked or unranked memref of any type values}}
950  "memref.rank"(%0): (f32)->index
951  return
952}
953
954// -----
955
956#map = affine_map<(d0, d1, d2)[s0, s1, s2, s3] -> (s0 + d0 * s1 + d1 * s2 + d2 * s3)>
957func.func @illegal_num_offsets(%arg0 : memref<?x?x?xf32>, %arg1 : index, %arg2 : index) {
958  // expected-error@+1 {{expected 3 offset values}}
959  %0 = memref.subview %arg0[0, 0] [%arg1, %arg2] [1, 1] : memref<?x?x?xf32> to memref<?x?x?xf32, #map>
960}
961
962// -----
963
964func.func @atomic_rmw_idxs_rank_mismatch(%I: memref<16x10xf32>, %i : index, %val : f32) {
965  // expected-error@+1 {{expects the number of subscripts to be equal to memref rank}}
966  %x = memref.atomic_rmw addf %val, %I[%i] : (f32, memref<16x10xf32>) -> f32
967  return
968}
969
970// -----
971
972func.func @atomic_rmw_expects_float(%I: memref<16x10xi32>, %i : index, %val : i32) {
973  // expected-error@+1 {{expects a floating-point type}}
974  %x = memref.atomic_rmw addf %val, %I[%i, %i] : (i32, memref<16x10xi32>) -> i32
975  return
976}
977
978// -----
979
980func.func @atomic_rmw_expects_int(%I: memref<16x10xf32>, %i : index, %val : f32) {
981  // expected-error@+1 {{expects an integer type}}
982  %x = memref.atomic_rmw addi %val, %I[%i, %i] : (f32, memref<16x10xf32>) -> f32
983  return
984}
985
986// -----
987
988func.func @generic_atomic_rmw_wrong_arg_num(%I: memref<10xf32>, %i : index) {
989  // expected-error@+1 {{expected single number of entry block arguments}}
990  %x = memref.generic_atomic_rmw %I[%i] : memref<10xf32> {
991    ^bb0(%arg0 : f32, %arg1 : f32):
992      %c1 = arith.constant 1.0 : f32
993      memref.atomic_yield %c1 : f32
994  }
995  return
996}
997
998// -----
999
1000func.func @generic_atomic_rmw_wrong_arg_type(%I: memref<10xf32>, %i : index) {
1001  // expected-error@+1 {{expected block argument of the same type result type}}
1002  %x = memref.generic_atomic_rmw %I[%i] : memref<10xf32> {
1003    ^bb0(%old_value : i32):
1004      %c1 = arith.constant 1.0 : f32
1005      memref.atomic_yield %c1 : f32
1006  }
1007  return
1008}
1009
1010// -----
1011
1012func.func @generic_atomic_rmw_result_type_mismatch(%I: memref<10xf32>, %i : index) {
1013 // expected-error@+1 {{failed to verify that result type matches element type of memref}}
1014 %0 = "memref.generic_atomic_rmw"(%I, %i) ({
1015    ^bb0(%old_value: f32):
1016      %c1 = arith.constant 1.0 : f32
1017      memref.atomic_yield %c1 : f32
1018    }) : (memref<10xf32>, index) -> i32
1019  return
1020}
1021
1022// -----
1023
1024func.func @generic_atomic_rmw_has_side_effects(%I: memref<10xf32>, %i : index) {
1025  // expected-error@+4 {{should contain only operations with no side effects}}
1026  %x = memref.generic_atomic_rmw %I[%i] : memref<10xf32> {
1027    ^bb0(%old_value : f32):
1028      %c1 = arith.constant 1.0 : f32
1029      %buf = memref.alloc() : memref<2048xf32>
1030      memref.atomic_yield %c1 : f32
1031  }
1032}
1033
1034// -----
1035
1036func.func @atomic_yield_type_mismatch(%I: memref<10xf32>, %i : index) {
1037  // expected-error@+4 {{op types mismatch between yield op: 'i32' and its parent: 'f32'}}
1038  %x = memref.generic_atomic_rmw %I[%i] : memref<10xf32> {
1039    ^bb0(%old_value : f32):
1040      %c1 = arith.constant 1 : i32
1041      memref.atomic_yield %c1 : i32
1042  }
1043  return
1044}
1045
1046// -----
1047
1048#map0 = affine_map<(d0) -> (d0 floordiv 8, d0 mod 8)>
1049func.func @memref_realloc_layout(%src : memref<256xf32, #map0>) -> memref<?xf32>{
1050  // expected-error@+1 {{unsupported layout}}
1051  %0 = memref.realloc %src : memref<256xf32, #map0> to memref<?xf32>
1052  return %0 : memref<?xf32>
1053}
1054
1055// -----
1056
1057func.func @memref_realloc_sizes_1(%src : memref<2xf32>) -> memref<?xf32>{
1058  // expected-error@+1 {{missing dimension operand}}
1059  %0 = memref.realloc %src : memref<2xf32> to memref<?xf32>
1060  return %0 : memref<?xf32>
1061}
1062
1063// -----
1064
1065func.func @memref_realloc_sizes_2(%src : memref<?xf32>, %d : index)
1066  -> memref<4xf32>{
1067  // expected-error@+1 {{unnecessary dimension operand}}
1068  %0 = memref.realloc %src(%d) : memref<?xf32> to memref<4xf32>
1069  return %0 : memref<4xf32>
1070}
1071
1072// -----
1073
1074func.func @memref_realloc_type(%src : memref<256xf32>) -> memref<?xi32>{
1075  // expected-error@+1 {{different element types}}
1076  %0 = memref.realloc %src : memref<256xf32> to memref<?xi32>
1077  return %0 : memref<?xi32>
1078}
1079
1080// -----
1081
1082// Asking the dimension of a 0-D shape doesn't make sense.
1083func.func @dim_0_ranked(%arg : memref<f32>, %arg1 : index) {
1084  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>'}}
1085  return
1086}
1087
1088// -----
1089
1090func.func @subview_invalid_strides(%m: memref<7x22x333x4444xi32>) {
1091  // expected-error @below{{expected result type to be 'memref<7x11x333x4444xi32, strided<[32556744, 2959704, 4444, 1]>>' or a rank-reduced version. (mismatch of result layout)}}
1092  %subview = memref.subview %m[0, 0, 0, 0] [7, 11, 333, 4444] [1, 2, 1, 1]
1093      : memref<7x22x333x4444xi32> to memref<7x11x333x4444xi32>
1094  return
1095}
1096
1097// -----
1098
1099func.func @subview_invalid_strides_rank_reduction(%m: memref<7x22x333x4444xi32>) {
1100  // expected-error @below{{expected result type to be 'memref<7x11x1x4444xi32, strided<[32556744, 2959704, 4444, 1]>>' or a rank-reduced version. (mismatch of result layout)}}
1101  %subview = memref.subview %m[0, 0, 0, 0] [7, 11, 1, 4444] [1, 2, 1, 1]
1102      : memref<7x22x333x4444xi32> to memref<7x11x4444xi32>
1103  return
1104}
1105
1106// -----
1107
1108func.func @expand_shape_invalid_output_shape(
1109    %arg0: memref<30x20xf32, strided<[4000, 2], offset: 100>>) {
1110  // expected-error @+1 {{invalid output shape provided at pos 2}}
1111  %0 = memref.expand_shape %arg0 [[0, 1], [2]] output_shape [2, 15, 21] :
1112      memref<30x20xf32, strided<[4000, 2], offset: 100>>
1113      into memref<2x15x20xf32, strided<[60000, 4000, 2], offset: 100>>
1114  return
1115}
1116