/
invalid.mlir
364 lines (272 loc) · 12.1 KB
/
invalid.mlir
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
// RUN: mlir-opt -split-input-file %s -verify-diagnostics
func @transpose_not_permutation(%v : memref<?x?xf32, affine_map<(i, j)[off, M]->(off + M * i + j)>>) {
// expected-error @+1 {{expected a permutation map}}
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)>>
}
// -----
func @transpose_bad_rank(%v : memref<?x?xf32, affine_map<(i, j)[off, M]->(off + M * i + j)>>) {
// expected-error @+1 {{expected a permutation map of same rank as the input}}
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)>>
}
// -----
func @transpose_wrong_type(%v : memref<?x?xf32, affine_map<(i, j)[off, M]->(off + M * i + j)>>) {
// expected-error @+1 {{output type 'memref<?x?xf32, affine_map<(d0, d1)[s0, s1] -> (d0 * s1 + s0 + d1)>>' does not match transposed input type 'memref<?x?xf32, affine_map<(d0, d1)[s0, s1] -> (d0 * s1 + s0 + d1)>>'}}
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)>>
}
// -----
func @memref_reinterpret_cast_too_many_offsets(%in: memref<?xf32>) {
// expected-error @+1 {{expected <= 1 offset values}}
%out = memref.reinterpret_cast %in to
offset: [0, 0], sizes: [10, 10], strides: [10, 1]
: memref<?xf32> to memref<10x10xf32, offset: 0, strides: [10, 1]>
return
}
// -----
func @memref_reinterpret_cast_incompatible_element_types(%in: memref<*xf32>) {
// expected-error @+1 {{different element types specified}}
%out = memref.reinterpret_cast %in to
offset: [0], sizes: [10], strides: [1]
: memref<*xf32> to memref<10xi32, offset: 0, strides: [1]>
return
}
// -----
func @memref_reinterpret_cast_incompatible_memory_space(%in: memref<*xf32>) {
// expected-error @+1 {{different memory spaces specified}}
%out = memref.reinterpret_cast %in to
offset: [0], sizes: [10], strides: [1]
: memref<*xf32> to memref<10xi32, offset: 0, strides: [1], 2>
return
}
// -----
func @memref_reinterpret_cast_offset_mismatch(%in: memref<?xf32>) {
// expected-error @+1 {{expected result type with offset = 2 instead of 1}}
%out = memref.reinterpret_cast %in to
offset: [1], sizes: [10], strides: [1]
: memref<?xf32> to memref<10xf32, offset: 2, strides: [1]>
return
}
// -----
func @memref_reinterpret_cast_size_mismatch(%in: memref<*xf32>) {
// expected-error @+1 {{expected result type with size = 10 instead of 1 in dim = 0}}
%out = memref.reinterpret_cast %in to
offset: [0], sizes: [10], strides: [1]
: memref<*xf32> to memref<1xf32, offset: 0, strides: [1]>
return
}
// -----
func @memref_reinterpret_cast_offset_mismatch(%in: memref<?xf32>) {
// expected-error @+1 {{expected result type with stride = 2 instead of 1 in dim = 0}}
%out = memref.reinterpret_cast %in to
offset: [2], sizes: [10], strides: [2]
: memref<?xf32> to memref<10xf32, offset: 2, strides: [1]>
return
}
// -----
func @memref_reinterpret_cast_offset_mismatch(%in: memref<?xf32>) {
%c0 = constant 0 : index
%c10 = constant 10 : index
// expected-error @+1 {{expected result type with size = 10 instead of -1 in dim = 0}}
%out = memref.reinterpret_cast %in to
offset: [%c0], sizes: [10, %c10], strides: [%c10, 1]
: memref<?xf32> to memref<?x?xf32, offset: ?, strides: [?, 1]>
return
}
// -----
func @memref_reshape_element_type_mismatch(
%buf: memref<*xf32>, %shape: memref<1xi32>) {
// expected-error @+1 {{element types of source and destination memref types should be the same}}
memref.reshape %buf(%shape) : (memref<*xf32>, memref<1xi32>) -> memref<?xi32>
}
// -----
func @memref_reshape_dst_ranked_shape_unranked(
%buf: memref<*xf32>, %shape: memref<?xi32>) {
// expected-error @+1 {{cannot use shape operand with dynamic length to reshape to statically-ranked memref type}}
memref.reshape %buf(%shape) : (memref<*xf32>, memref<?xi32>) -> memref<?xf32>
}
// -----
func @memref_reshape_dst_shape_rank_mismatch(
%buf: memref<*xf32>, %shape: memref<1xi32>) {
// expected-error @+1 {{length of shape operand differs from the result's memref rank}}
memref.reshape %buf(%shape)
: (memref<*xf32>, memref<1xi32>) -> memref<?x?xf32>
}
// -----
func @memref_reshape_src_affine_map_is_not_identity(
%buf: memref<4x4xf32, offset: 0, strides: [3, 2]>,
%shape: memref<1xi32>) {
// expected-error @+1 {{source memref type should have identity affine map}}
memref.reshape %buf(%shape)
: (memref<4x4xf32, offset: 0, strides: [3, 2]>, memref<1xi32>)
-> memref<8xf32>
}
// -----
func @memref_reshape_result_affine_map_is_not_identity(
%buf: memref<4x4xf32>, %shape: memref<1xi32>) {
// expected-error @+1 {{result memref type should have identity affine map}}
memref.reshape %buf(%shape)
: (memref<4x4xf32>, memref<1xi32>) -> memref<8xf32, offset: 0, strides: [2]>
}
// -----
// expected-error @+1 {{type should be static shaped memref}}
memref.global @foo : i32
// -----
// expected-error @+1 {{type should be static shaped memref}}
memref.global @foo : i32 = 5
// -----
// expected-error @+1 {{type should be static shaped memref}}
memref.global @foo : memref<*xf32>
// -----
// expected-error @+1 {{type should be static shaped memref}}
memref.global @foo : memref<?x?xf32>
// -----
// expected-error @+1 {{initial value should be a unit or elements attribute}}
memref.global @foo : memref<2x2xf32> = "foo"
// -----
// expected-error @+1 {{inferred shape of elements literal ([2]) does not match type ([2, 2])}}
memref.global @foo : memref<2x2xf32> = dense<[0.0, 1.0]>
// -----
// expected-error @+1 {{expected valid '@'-identifier for symbol name}}
memref.global "private" "public" @foo : memref<2x2xf32> = "foo"
// -----
// expected-error @+1 {{expected valid '@'-identifier for symbol name}}
memref.global constant external @foo : memref<2x2xf32> = "foo"
// -----
// constant qualifier must be after visibility.
// expected-error @+1 {{expected valid '@'-identifier for symbol name}}
memref.global constant "private" @foo : memref<2x2xf32> = "foo"
// -----
// expected-error @+1 {{op visibility expected to be one of ["public", "private", "nested"], but got "priate"}}
memref.global "priate" constant @memref5 : memref<2xf32> = uninitialized
// -----
func @nonexistent_global_memref() {
// expected-error @+1 {{'gv' does not reference a valid global memref}}
%0 = memref.get_global @gv : memref<3xf32>
return
}
// -----
func @foo()
func @nonexistent_global_memref() {
// expected-error @+1 {{'foo' does not reference a valid global memref}}
%0 = memref.get_global @foo : memref<3xf32>
return
}
// -----
memref.global @gv : memref<3xi32>
func @mismatched_types() {
// expected-error @+1 {{result type 'memref<3xf32>' does not match type 'memref<3xi32>' of the global memref @gv}}
%0 = memref.get_global @gv : memref<3xf32>
return
}
// -----
func @copy_different_shape(%arg0: memref<2xf32>, %arg1: memref<3xf32>) {
// expected-error @+1 {{op requires the same shape for all operands}}
memref.copy %arg0, %arg1 : memref<2xf32> to memref<3xf32>
return
}
// -----
func @copy_different_eltype(%arg0: memref<2xf32>, %arg1: memref<2xf16>) {
// expected-error @+1 {{op requires the same element type for all operands}}
memref.copy %arg0, %arg1 : memref<2xf32> to memref<2xf16>
return
}
// -----
func @expand_shape(%arg0: memref<f32>) {
// expected-error @+1 {{expected non-zero memref ranks}}
%0 = memref.expand_shape %arg0 [[0]] : memref<f32> into memref<f32>
}
// -----
func @collapse_shape_to_higher_rank(%arg0: memref<f32>) {
// expected-error @+1 {{expected the type 'memref<f32>' to have higher rank than the type = 'memref<1xf32>'}}
%0 = memref.collapse_shape %arg0 [[0]] : memref<f32> into memref<1xf32>
}
// -----
func @expand_shape_to_smaller_rank(%arg0: memref<1xf32>) {
// expected-error @+1 {{expected the type 'memref<f32>' to have higher rank than the type = 'memref<1xf32>'}}
%0 = memref.expand_shape %arg0 [[0]] : memref<1xf32> into memref<f32>
}
// -----
func @collapse_shape(%arg0: memref<?xf32>) {
// expected-error @+1 {{expected to collapse or expand dims}}
%0 = memref.collapse_shape %arg0 [[0]] : memref<?xf32> into memref<?xf32>
}
// -----
func @collapse_shape_mismatch_indices_num(%arg0: memref<?x?x?xf32>) {
// expected-error @+1 {{expected rank of the collapsed type(2) to be the number of reassociation maps(1)}}
%0 = memref.collapse_shape %arg0 [[0, 1]] :
memref<?x?x?xf32> into memref<?x?xf32, offset: 0, strides: [?, 1]>
}
// -----
func @collapse_shape_invalid_reassociation(%arg0: memref<?x?x?xf32>) {
// expected-error @+1 {{expected reassociation map #1 to be valid and contiguous}}
%0 = memref.collapse_shape %arg0 [[0, 1], [1, 2]] :
memref<?x?x?xf32> into memref<?x?xf32, offset: 0, strides: [?, 1]>
}
// -----
func @collapse_shape_wrong_collapsed_type(%arg0: memref<?x?x?xf32>) {
// expected-error @+1 {{expected collapsed type to be 'memref<?x?xf32>', but got 'memref<?x?xf32, affine_map<(d0, d1)[s0] -> (d0 * s0 + d1)>>'}}
%0 = memref.collapse_shape %arg0 [[0, 1], [2]] :
memref<?x?x?xf32> into memref<?x?xf32, affine_map<(d0, d1)[s0] -> (d0 * s0 + d1)>>
}
// -----
func @expand_shape_illegal_dynamic_memref
(%arg0: memref<?x?x?xf32>) -> memref<?x?x?x4x?xf32> {
// expected-error @+1 {{invalid to have a single dimension (2) expanded into multiple dynamic dims (2,4)}}
%0 = memref.expand_shape %arg0 [[0], [1], [2, 3, 4]]
: memref<?x?x?xf32> into memref<?x?x?x4x?xf32>
return %0 : memref<?x?x?x4x?xf32>
}
// -----
func @expand_shape_illegal_static_memref
(%arg0: memref<2x3x20xf32>) -> memref<2x3x2x4x5xf32> {
// expected-error @+1 {{expected dimension 2 of collapsed type to be static value of 40}}
%0 = memref.expand_shape %arg0 [[0], [1], [2, 3, 4]]
: memref<2x3x20xf32> into memref<2x3x2x4x5xf32>
return %0 : memref<2x3x2x4x5xf32>
}
// -----
func @collapse_shape_illegal_static_memref
(%arg0: memref<2x3x2x4x5xf32>) -> memref<2x3x20xf32> {
// expected-error @+1 {{expected dimension 2 of collapsed type to be static value of 40}}
%0 = memref.collapse_shape %arg0 [[0], [1], [2, 3, 4]]
: memref<2x3x2x4x5xf32> into memref<2x3x20xf32>
return %0 : memref<2x3x20xf32>
}
// -----
func @expand_shape_illegal_mixed_memref(%arg0 : memref<?x?xf32>)
-> memref<?x4x5xf32> {
// expected-error @+1 {{expected dimension 1 of collapsed type to be static value of 5}}
%0 = memref.expand_shape %arg0 [[0, 1], [2]]
: memref<?x?xf32> into memref<?x4x5xf32>
return %0 : memref<?x4x5xf32>
}
// -----
func @expand_shape_illegal_mixed_memref_2(%arg0 : memref<?x?xf32>)
-> memref<?x4x5xf32> {
// expected-error @+1 {{expected dimension 1 of collapsed type to be static value of 20}}
%0 = memref.expand_shape %arg0 [[0], [1, 2]]
: memref<?x?xf32> into memref<?x4x5xf32>
return %0 : memref<?x4x5xf32>
}
// -----
func @collapse_shape_illegal_mixed_memref(%arg0 : memref<?x4x5xf32>)
-> memref<?x?xf32> {
// expected-error @+1 {{expected dimension 1 of collapsed type to be static value of 5}}
%0 = memref.collapse_shape %arg0 [[0, 1], [2]]
: memref<?x4x5xf32> into memref<?x?xf32>
return %0 : memref<?x?xf32>
}
// -----
func @collapse_shape_illegal_mixed_memref_2(%arg0 : memref<?x4x5xf32>)
-> memref<?x?xf32> {
// expected-error @+1 {{expected dimension 1 of collapsed type to be static value of 20}}
%0 = memref.collapse_shape %arg0 [[0], [1, 2]]
: memref<?x4x5xf32> into memref<?x?xf32>
return %0 : memref<?x?xf32>
}
// -----
func @static_stride_to_dynamic_stride(%arg0 : memref<?x?x?xf32>, %arg1 : index,
%arg2 : index) -> memref<?x?xf32, offset:?, strides: [?, ?]> {
// expected-error @+1 {{expected result type to be 'memref<1x?x?xf32, affine_map<(d0, d1, d2)[s0, s1, s2] -> (d0 * s1 + s0 + d1 * s2 + d2)>>' or a rank-reduced version. (mismatch of result sizes)}}
%0 = memref.subview %arg0[0, 0, 0] [1, %arg1, %arg2] [1, 1, 1] : memref<?x?x?xf32> to memref<?x?xf32, offset: ?, strides: [?, ?]>
return %0 : memref<?x?xf32, offset: ?, strides: [?, ?]>
}