1// RUN: mlir-opt %s | mlir-opt | FileCheck %s
2
3// CHECK-LABEL: func @vector_transfer_ops(
4func @vector_transfer_ops(%arg0: memref<?x?xf32>,
5                          %arg1 : memref<?x?xvector<4x3xf32>>,
6                          %arg2 : memref<?x?xvector<4x3xi32>>) {
7  // CHECK: %[[C3:.*]] = constant 3 : index
8  %c3 = constant 3 : index
9  %cst = constant 3.0 : f32
10  %f0 = constant 0.0 : f32
11  %c0 = constant 0 : i32
12  %vf0 = splat %f0 : vector<4x3xf32>
13  %v0 = splat %c0 : vector<4x3xi32>
14
15  //
16  // CHECK: vector.transfer_read
17  %0 = vector.transfer_read %arg0[%c3, %c3], %f0 {permutation_map = affine_map<(d0, d1)->(d0)>} : memref<?x?xf32>, vector<128xf32>
18  // CHECK: vector.transfer_read
19  %1 = vector.transfer_read %arg0[%c3, %c3], %f0 {permutation_map = affine_map<(d0, d1)->(d1, d0)>} : memref<?x?xf32>, vector<3x7xf32>
20  // CHECK: vector.transfer_read
21  %2 = vector.transfer_read %arg0[%c3, %c3], %cst {permutation_map = affine_map<(d0, d1)->(d0)>} : memref<?x?xf32>,  vector<128xf32>
22  // CHECK: vector.transfer_read
23  %3 = vector.transfer_read %arg0[%c3, %c3], %cst {permutation_map = affine_map<(d0, d1)->(d1)>} : memref<?x?xf32>,  vector<128xf32>
24  // CHECK: vector.transfer_read %{{.*}}[%[[C3]], %[[C3]]], %{{.*}} : memref<?x?xvector<4x3xf32>>, vector<1x1x4x3xf32>
25  %4 = vector.transfer_read %arg1[%c3, %c3], %vf0 {permutation_map = affine_map<(d0, d1)->(d0, d1)>} : memref<?x?xvector<4x3xf32>>, vector<1x1x4x3xf32>
26  // CHECK: vector.transfer_read %{{.*}}[%[[C3]], %[[C3]]], %{{.*}} {masked = [true, false]} : memref<?x?xvector<4x3xf32>>, vector<1x1x4x3xf32>
27  %5 = vector.transfer_read %arg1[%c3, %c3], %vf0 {masked = [true, false]} : memref<?x?xvector<4x3xf32>>, vector<1x1x4x3xf32>
28  // CHECK: vector.transfer_read %{{.*}}[%[[C3]], %[[C3]]], %{{.*}} : memref<?x?xvector<4x3xi32>>, vector<5x24xi8>
29  %6 = vector.transfer_read %arg2[%c3, %c3], %v0 : memref<?x?xvector<4x3xi32>>, vector<5x24xi8>
30
31
32  // CHECK: vector.transfer_write
33  vector.transfer_write %0, %arg0[%c3, %c3] {permutation_map = affine_map<(d0, d1)->(d0)>} : vector<128xf32>, memref<?x?xf32>
34  // CHECK: vector.transfer_write
35  vector.transfer_write %1, %arg0[%c3, %c3] {permutation_map = affine_map<(d0, d1)->(d1, d0)>} : vector<3x7xf32>, memref<?x?xf32>
36  // CHECK: vector.transfer_write %{{.*}}, %{{.*}}[%[[C3]], %[[C3]]] : vector<1x1x4x3xf32>, memref<?x?xvector<4x3xf32>>
37  vector.transfer_write %4, %arg1[%c3, %c3] {permutation_map = affine_map<(d0, d1)->(d0, d1)>} : vector<1x1x4x3xf32>, memref<?x?xvector<4x3xf32>>
38  // CHECK: vector.transfer_write %{{.*}}, %{{.*}}[%[[C3]], %[[C3]]] : vector<1x1x4x3xf32>, memref<?x?xvector<4x3xf32>>
39  vector.transfer_write %5, %arg1[%c3, %c3] {masked = [true, true]} : vector<1x1x4x3xf32>, memref<?x?xvector<4x3xf32>>
40  // CHECK: vector.transfer_write %{{.*}}, %{{.*}}[%[[C3]], %[[C3]]] : vector<5x24xi8>, memref<?x?xvector<4x3xi32>>
41  vector.transfer_write %6, %arg2[%c3, %c3] : vector<5x24xi8>, memref<?x?xvector<4x3xi32>>
42
43  return
44}
45
46// CHECK-LABEL: @vector_broadcast
47func @vector_broadcast(%a: f32, %b: vector<16xf32>, %c: vector<1x16xf32>, %d: vector<8x1xf32>) -> vector<8x16xf32> {
48  // CHECK: vector.broadcast %{{.*}} : f32 to vector<16xf32>
49  %0 = vector.broadcast %a : f32 to vector<16xf32>
50  // CHECK-NEXT: vector.broadcast %{{.*}} : vector<16xf32> to vector<8x16xf32>
51  %1 = vector.broadcast %b : vector<16xf32> to vector<8x16xf32>
52  // CHECK-NEXT: vector.broadcast %{{.*}} : vector<1x16xf32> to vector<8x16xf32>
53  %2 = vector.broadcast %c : vector<1x16xf32> to vector<8x16xf32>
54  // CHECK-NEXT: vector.broadcast %{{.*}} : vector<8x1xf32> to vector<8x16xf32>
55  %3 = vector.broadcast %d : vector<8x1xf32> to vector<8x16xf32>
56  return %3 : vector<8x16xf32>
57}
58
59// CHECK-LABEL: @shuffle1D
60func @shuffle1D(%a: vector<2xf32>, %b: vector<4xf32>) -> vector<2xf32> {
61  // CHECK: vector.shuffle %{{.*}}, %{{.*}}[0, 1, 2, 3] : vector<2xf32>, vector<2xf32>
62  %1 = vector.shuffle %a, %a[0, 1, 2, 3] : vector<2xf32>, vector<2xf32>
63  // CHECK-NEXT: vector.shuffle %{{.*}}, %{{.*}}[0, 1, 2] : vector<4xf32>, vector<4xf32>
64  %2 = vector.shuffle %1, %b[0, 1, 2] : vector<4xf32>, vector<4xf32>
65  // CHECK-NEXT: vector.shuffle %{{.*}}, %{{.*}}[0, 6] : vector<3xf32>, vector<4xf32>
66  %3 = vector.shuffle %2, %b[0, 6] : vector<3xf32>, vector<4xf32>
67  return %3 : vector<2xf32>
68}
69
70// CHECK-LABEL: @shuffle2D
71func @shuffle2D(%a: vector<1x4xf32>, %b: vector<2x4xf32>) -> vector<3x4xf32> {
72  // CHECK: vector.shuffle %{{.*}}, %{{.*}}[0, 1, 2] : vector<1x4xf32>, vector<2x4xf32>
73  %1 = vector.shuffle %a, %b[0, 1, 2] : vector<1x4xf32>, vector<2x4xf32>
74  return %1 : vector<3x4xf32>
75}
76
77// CHECK-LABEL: @extract_element
78func @extract_element(%a: vector<16xf32>) -> f32 {
79  // CHECK:      %[[C15:.*]] = constant 15 : i32
80  %c = constant 15 : i32
81  // CHECK-NEXT: vector.extractelement %{{.*}}[%[[C15]] : i32] : vector<16xf32>
82  %1 = vector.extractelement %a[%c : i32] : vector<16xf32>
83  return %1 : f32
84}
85
86// CHECK-LABEL: @extract
87func @extract(%arg0: vector<4x8x16xf32>) -> (vector<8x16xf32>, vector<16xf32>, f32) {
88  // CHECK: vector.extract {{.*}}[3] : vector<4x8x16xf32>
89  %1 = vector.extract %arg0[3] : vector<4x8x16xf32>
90  // CHECK-NEXT: vector.extract {{.*}}[3, 3] : vector<4x8x16xf32>
91  %2 = vector.extract %arg0[3, 3] : vector<4x8x16xf32>
92  // CHECK-NEXT: vector.extract {{.*}}[3, 3, 3] : vector<4x8x16xf32>
93  %3 = vector.extract %arg0[3, 3, 3] : vector<4x8x16xf32>
94  return %1, %2, %3 : vector<8x16xf32>, vector<16xf32>, f32
95}
96
97// CHECK-LABEL: @insert_element
98func @insert_element(%a: f32, %b: vector<16xf32>) -> vector<16xf32> {
99  // CHECK:      %[[C15:.*]] = constant 15 : i32
100  %c = constant 15 : i32
101  // CHECK-NEXT: vector.insertelement %{{.*}}, %{{.*}}[%[[C15]] : i32] : vector<16xf32>
102  %1 = vector.insertelement %a, %b[%c : i32] : vector<16xf32>
103  return %1 : vector<16xf32>
104}
105
106// CHECK-LABEL: @insert
107func @insert(%a: f32, %b: vector<16xf32>, %c: vector<8x16xf32>, %res: vector<4x8x16xf32>) -> vector<4x8x16xf32> {
108  // CHECK: vector.insert %{{.*}}, %{{.*}}[3] : vector<8x16xf32> into vector<4x8x16xf32>
109  %1 = vector.insert %c, %res[3] : vector<8x16xf32> into vector<4x8x16xf32>
110  // CHECK: vector.insert %{{.*}}, %{{.*}}[3, 3] : vector<16xf32> into vector<4x8x16xf32>
111  %2 = vector.insert %b, %res[3, 3] : vector<16xf32> into vector<4x8x16xf32>
112  // CHECK: vector.insert %{{.*}}, %{{.*}}[3, 3, 3] : f32 into vector<4x8x16xf32>
113  %3 = vector.insert %a, %res[3, 3, 3] : f32 into vector<4x8x16xf32>
114  return %3 : vector<4x8x16xf32>
115}
116
117// CHECK-LABEL: @outerproduct
118func @outerproduct(%arg0: vector<4xf32>, %arg1: vector<8xf32>, %arg2: vector<4x8xf32>) -> vector<4x8xf32> {
119  // CHECK: vector.outerproduct {{.*}} : vector<4xf32>, vector<8xf32>
120  %0 = vector.outerproduct %arg0, %arg1 : vector<4xf32>, vector<8xf32>
121  // CHECK: vector.outerproduct {{.*}}, {{.*}}, {{.*}} : vector<4xf32>, vector<8xf32>
122  %1 = vector.outerproduct %arg0, %arg1, %arg2 : vector<4xf32>, vector<8xf32>
123  return %1 : vector<4x8xf32>
124}
125
126// CHECK-LABEL: @insert_strided_slice
127func @insert_strided_slice(%a: vector<4x4xf32>, %b: vector<4x8x16xf32>) {
128  // CHECK: vector.insert_strided_slice %{{.*}}, %{{.*}} {offsets = [2, 2, 2], strides = [1, 1]} : vector<4x4xf32> into vector<4x8x16xf32>
129  %1 = vector.insert_strided_slice %a, %b {offsets = [2, 2, 2], strides = [1, 1]} : vector<4x4xf32> into vector<4x8x16xf32>
130  return
131}
132
133// CHECK-LABEL: @extract_strided_slice
134func @extract_strided_slice(%arg0: vector<4x8x16xf32>) -> vector<2x2x16xf32> {
135  // CHECK: vector.extract_strided_slice %{{.*}} {offsets = [2, 2], sizes = [2, 2], strides = [1, 1]} : vector<4x8x16xf32>
136  %1 = vector.extract_strided_slice %arg0 {offsets = [2, 2], sizes = [2, 2], strides = [1, 1]} : vector<4x8x16xf32> to vector<2x2x16xf32>
137  return %1: vector<2x2x16xf32>
138}
139
140#contraction_to_scalar_accesses = [
141  affine_map<(i) -> (i)>,
142  affine_map<(i) -> (i)>,
143  affine_map<(i) -> ()>
144]
145#contraction_to_scalar_trait = {
146  indexing_maps = #contraction_to_scalar_accesses,
147  iterator_types = ["reduction"]
148}
149// CHECK-LABEL: @contraction_to_scalar
150func @contraction_to_scalar(%arg0: vector<10xf32>, %arg1: vector<10xf32>) -> f32 {
151  // CHECK:      %[[C0:.*]] = constant 0.000000e+00 : f32
152  %f0 = constant 0.0: f32
153  // CHECK:      %[[X:.*]] = vector.contract {indexing_maps = [#{{.*}}, #{{.*}}, #{{.*}}], iterator_types = ["reduction"]} %{{.*}}, %{{.*}}, %[[C0]] : vector<10xf32>, vector<10xf32> into f32
154  %0 = vector.contract #contraction_to_scalar_trait %arg0, %arg1, %f0
155    : vector<10xf32>, vector<10xf32> into f32
156  // CHECK:      return %[[X]] : f32
157  return %0 : f32
158}
159
160#contraction_accesses0 = [
161  affine_map<(b0, f0, f1, c0, c1) -> (c0, b0, c1, f0)>,
162  affine_map<(b0, f0, f1, c0, c1) -> (b0, c1, c0, f1)>,
163  affine_map<(b0, f0, f1, c0, c1) -> (b0, f0, f1)>
164]
165#contraction_trait0 = {
166  indexing_maps = #contraction_accesses0,
167  iterator_types = ["parallel", "parallel", "parallel", "reduction", "reduction"]
168}
169#contraction_accesses1 = [              // 7,  8, 16, 15
170  affine_map<(f0, f1, f2, f3, c0, c1) -> (c0, f0, c1, f2)>,
171                                        // 8, 16,  7,  5
172  affine_map<(f0, f1, f2, f3, c0, c1) -> (f1, c1, c0, f3)>,
173                                        // 8,  8, 15,  5
174  affine_map<(f0, f1, f2, f3, c0, c1) -> (f0, f1, f2, f3)>
175]
176#contraction_trait1 = {
177  indexing_maps = #contraction_accesses1,
178  iterator_types = ["parallel", "parallel", "parallel", "parallel", "reduction",
179                    "reduction"]
180}
181// CHECK-LABEL: @contraction
182func @contraction(%arg0 : vector<7x8x16x15xf32>, %arg1 : vector<8x16x7x5xf32>,
183                  %arg2 : vector<8x15x5xf32>, %arg3 : vector<8x8x15x5xf32>,
184                  %arg4 : vector<7x8x16x15xf16>, %arg5 : vector<8x16x7x5xf16>) {
185  // Test contraction with batch and contracting dims.
186  // CHECK: vector.contract {indexing_maps = [#{{.*}}, #{{.*}}, #{{.*}}], iterator_types = ["parallel", "parallel", "parallel", "reduction", "reduction"]} {{.*}}, {{.*}}, {{.*}} : vector<7x8x16x15xf32>, vector<8x16x7x5xf32> into vector<8x15x5xf32>
187  %0 = vector.contract #contraction_trait0 %arg0, %arg1, %arg2
188      : vector<7x8x16x15xf32>, vector<8x16x7x5xf32> into vector<8x15x5xf32>
189  // Test contraction with only contracting dims. In this case the lhs/rhs
190  // dimension of size 8 will be considered a parallel dim for lhs/rhs and will
191  // appear twice in the output.
192  // CHECK: vector.contract {indexing_maps = [#{{.*}}, #{{.*}}, #{{.*}}], iterator_types = ["parallel", "parallel", "parallel", "parallel", "reduction", "reduction"]} {{.*}}, {{.*}}, {{.*}} : vector<7x8x16x15xf32>, vector<8x16x7x5xf32> into vector<8x8x15x5xf32>
193  %1 = vector.contract #contraction_trait1 %arg0, %arg1, %arg3
194      : vector<7x8x16x15xf32>, vector<8x16x7x5xf32> into vector<8x8x15x5xf32>
195  // Test contraction with optional vector mask arguments.
196  %lhs_mask = vector.constant_mask [7, 8, 16, 15] : vector<7x8x16x15xi1>
197  %rhs_mask = vector.constant_mask [8, 16, 7, 5] : vector<8x16x7x5xi1>
198  // CHECK: vector.contract {indexing_maps = [#{{.*}}, #{{.*}}, #{{.*}}], iterator_types = ["parallel", "parallel", "parallel", "parallel", "reduction", "reduction"]} {{.*}}, {{.*}}, {{.*}}, {{.*}}, {{.*}} : vector<7x8x16x15xf32>, vector<8x16x7x5xf32> into vector<8x8x15x5xf32>
199  %2 = vector.contract #contraction_trait1 %arg0, %arg1, %arg3, %lhs_mask,
200                                           %rhs_mask
201      : vector<7x8x16x15xf32>, vector<8x16x7x5xf32> into vector<8x8x15x5xf32>
202  // Test contraction with mixed type.
203  // CHECK: vector.contract {indexing_maps = [#{{.*}}, #{{.*}}, #{{.*}}], iterator_types = ["parallel", "parallel", "parallel", "parallel", "reduction", "reduction"]} {{.*}}, {{.*}}, {{.*}} : vector<7x8x16x15xf16>, vector<8x16x7x5xf16> into vector<8x8x15x5xf32>
204  %3 = vector.contract #contraction_trait1 %arg4, %arg5, %arg3
205      : vector<7x8x16x15xf16>, vector<8x16x7x5xf16> into vector<8x8x15x5xf32>
206  return
207}
208
209// CHECK-LABEL: @create_vector_mask
210func @create_vector_mask() {
211  // CHECK:      %[[C2:.*]] = constant 2 : index
212  %c2 = constant 2 : index
213  // CHECK-NEXT: %[[C3:.*]] = constant 3 : index
214  %c3 = constant 3 : index
215  // CHECK-NEXT: vector.create_mask %[[C3]], %[[C2]] : vector<4x3xi1>
216  %0 = vector.create_mask %c3, %c2 : vector<4x3xi1>
217
218  return
219}
220
221// CHECK-LABEL: @constant_vector_mask
222func @constant_vector_mask() {
223  // CHECK: vector.constant_mask [3, 2] : vector<4x3xi1>
224  %0 = vector.constant_mask [3, 2] : vector<4x3xi1>
225  return
226}
227
228// CHECK-LABEL: @extract_slices
229func @extract_slices(%arg0 : vector<4x2xf32>)
230  -> (tuple<vector<2x2xf32>, vector<2x2xf32>>) {
231  // CHECK: vector.extract_slices %{{.*}}, [2, 2], [1, 1] : vector<4x2xf32> into tuple<vector<2x2xf32>, vector<2x2xf32>>
232  %0 = vector.extract_slices %arg0, [2, 2], [1, 1]
233    : vector<4x2xf32> into tuple<vector<2x2xf32>, vector<2x2xf32>>
234  %1 = vector.tuple_get %0, 0 : tuple<vector<2x2xf32>, vector<2x2xf32>>
235  %2 = vector.tuple_get %0, 1 : tuple<vector<2x2xf32>, vector<2x2xf32>>
236  %3 = vector.tuple %1, %2 : vector<2x2xf32>, vector<2x2xf32>
237  return %3 : tuple<vector<2x2xf32>, vector<2x2xf32>>
238}
239
240// CHECK-LABEL: @insert_slices
241func @insert_slices(%arg0 : tuple<vector<2x2xf32>, vector<2x2xf32>>)
242  -> (vector<4x2xf32>) {
243  // CHECK: vector.insert_slices %{{.*}}, [2, 2], [1, 1] : tuple<vector<2x2xf32>, vector<2x2xf32>> into vector<4x2xf32>
244  %0 = vector.insert_slices %arg0, [2, 2], [1, 1]
245    : tuple<vector<2x2xf32>, vector<2x2xf32>> into vector<4x2xf32>
246  return %0 : vector<4x2xf32>
247}
248
249// CHECK-LABEL: @vector_print
250func @vector_print(%arg0: vector<8x4xf32>) {
251  // CHECK: vector.print %{{.*}} : vector<8x4xf32>
252  vector.print %arg0 : vector<8x4xf32>
253  return
254}
255
256// CHECK-LABEL: @reshape
257func @reshape(%arg0 : vector<3x2x4xf32>) -> (vector<2x3x4xf32>) {
258  // CHECK:      %[[C2:.*]] = constant 2 : index
259  %c2 = constant 2 : index
260  // CHECK:      %[[C3:.*]] = constant 3 : index
261  %c3 = constant 3 : index
262  // CHECK:      %[[C6:.*]] = constant 6 : index
263  %c6 = constant 6 : index
264  // CHECK:      %[[C9:.*]] = constant 9 : index
265  %c9 = constant 9 : index
266  // CHECK: vector.reshape %{{.*}}, [%[[C3]], %[[C6]]], [%[[C2]], %[[C9]]], [4] : vector<3x2x4xf32> to vector<2x3x4xf32>
267  %1 = vector.reshape %arg0, [%c3, %c6], [%c2, %c9], [4]
268    : vector<3x2x4xf32> to vector<2x3x4xf32>
269
270  return %1 : vector<2x3x4xf32>
271}
272
273// CHECK-LABEL: @shape_cast
274func @shape_cast(%arg0 : vector<5x1x3x2xf32>,
275                 %arg1 : tuple<vector<5x4x2xf32>, vector<3x4x2xf32>>,
276                 %arg2 : vector<8x1xf32>,
277                 %arg3 : vector<16x1x1xf32>)
278  -> (vector<15x2xf32>, tuple<vector<20x2xf32>, vector<12x2xf32>>, vector<8xf32>, vector<16xf32>, vector<16x1xf32>) {
279
280  // CHECK: vector.shape_cast %{{.*}} : vector<5x1x3x2xf32> to vector<15x2xf32>
281  %0 = vector.shape_cast %arg0 : vector<5x1x3x2xf32> to vector<15x2xf32>
282
283  // CHECK-NEXT: vector.shape_cast %{{.*}} : tuple<vector<5x4x2xf32>, vector<3x4x2xf32>> to tuple<vector<20x2xf32>, vector<12x2xf32>>
284  %1 = vector.shape_cast %arg1 : tuple<vector<5x4x2xf32>, vector<3x4x2xf32>> to
285                                 tuple<vector<20x2xf32>, vector<12x2xf32>>
286
287  // CHECK-NEXT: vector.shape_cast %{{.*}} : vector<8x1xf32> to vector<8xf32>
288  %2 = vector.shape_cast %arg2 : vector<8x1xf32> to vector<8xf32>
289
290  // CHECK-NEXT: vector.shape_cast %{{.*}} : vector<16x1x1xf32> to vector<16xf32>
291  %3 = vector.shape_cast %arg3 : vector<16x1x1xf32> to vector<16xf32>
292
293  // CHECK-NEXT: vector.shape_cast %{{.*}} : vector<16x1x1xf32> to vector<16x1xf32>
294  %4 = vector.shape_cast %arg3 : vector<16x1x1xf32> to vector<16x1xf32>
295
296  return %0, %1, %2, %3, %4 : vector<15x2xf32>, tuple<vector<20x2xf32>, vector<12x2xf32>>, vector<8xf32>, vector<16xf32>, vector<16x1xf32>
297}
298
299// CHECK-LABEL: @bitcast
300func @bitcast(%arg0 : vector<5x1x3x2xf32>,
301                 %arg1 : vector<8x1xi32>,
302                 %arg2 : vector<16x1x8xi8>)
303  -> (vector<5x1x3x4xf16>, vector<5x1x3x8xi8>, vector<8x4xi8>, vector<8x1xf32>, vector<16x1x2xi32>, vector<16x1x4xi16>) {
304
305  // CHECK: vector.bitcast %{{.*}} : vector<5x1x3x2xf32> to vector<5x1x3x4xf16>
306  %0 = vector.bitcast %arg0 : vector<5x1x3x2xf32> to vector<5x1x3x4xf16>
307
308  // CHECK-NEXT: vector.bitcast %{{.*}} : vector<5x1x3x2xf32> to vector<5x1x3x8xi8>
309  %1 = vector.bitcast %arg0 : vector<5x1x3x2xf32> to vector<5x1x3x8xi8>
310
311  // CHECK-NEXT: vector.bitcast %{{.*}} : vector<8x1xi32> to vector<8x4xi8>
312  %2 = vector.bitcast %arg1 : vector<8x1xi32> to vector<8x4xi8>
313
314  // CHECK-NEXT: vector.bitcast %{{.*}} : vector<8x1xi32> to vector<8x1xf32>
315  %3 = vector.bitcast %arg1 : vector<8x1xi32> to vector<8x1xf32>
316
317  // CHECK-NEXT: vector.bitcast %{{.*}} : vector<16x1x8xi8> to vector<16x1x2xi32>
318  %4 = vector.bitcast %arg2 : vector<16x1x8xi8> to vector<16x1x2xi32>
319
320  // CHECK-NEXT: vector.bitcast %{{.*}} : vector<16x1x8xi8> to vector<16x1x4xi16>
321  %5 = vector.bitcast %arg2 : vector<16x1x8xi8> to vector<16x1x4xi16>
322
323  return %0, %1, %2, %3, %4, %5 : vector<5x1x3x4xf16>, vector<5x1x3x8xi8>, vector<8x4xi8>, vector<8x1xf32>, vector<16x1x2xi32>, vector<16x1x4xi16>
324}
325
326// CHECK-LABEL: @vector_fma
327func @vector_fma(%a: vector<8xf32>, %b: vector<8x4xf32>) {
328  // CHECK: vector.fma %{{.*}} : vector<8xf32>
329  vector.fma %a, %a, %a : vector<8xf32>
330  // CHECK: vector.fma %{{.*}} : vector<8x4xf32>
331  vector.fma %b, %b, %b : vector<8x4xf32>
332  return
333}
334
335// CHECK-LABEL: @reduce_fp
336func @reduce_fp(%arg0: vector<16xf32>, %arg1: f32) -> f32 {
337  // CHECK:    vector.reduction "add", %{{.*}} : vector<16xf32> into f32
338  vector.reduction "add", %arg0 : vector<16xf32> into f32
339  // CHECK:    vector.reduction "add", %{{.*}}, %{{.*}} : vector<16xf32> into f32
340  vector.reduction "add", %arg0, %arg1 : vector<16xf32> into f32
341  // CHECK:    vector.reduction "mul", %{{.*}} : vector<16xf32> into f32
342  vector.reduction "mul", %arg0 : vector<16xf32> into f32
343  // CHECK:    vector.reduction "mul", %{{.*}}, %{{.*}} : vector<16xf32> into f32
344  vector.reduction "mul", %arg0, %arg1 : vector<16xf32> into f32
345  // CHECK:    vector.reduction "min", %{{.*}} : vector<16xf32> into f32
346  vector.reduction "min", %arg0 : vector<16xf32> into f32
347  // CHECK:    %[[X:.*]] = vector.reduction "max", %{{.*}} : vector<16xf32> into f32
348  %0 = vector.reduction "max", %arg0 : vector<16xf32> into f32
349  // CHECK:    return %[[X]] : f32
350  return %0 : f32
351}
352
353// CHECK-LABEL: @reduce_int
354func @reduce_int(%arg0: vector<16xi32>) -> i32 {
355  // CHECK:    vector.reduction "add", %{{.*}} : vector<16xi32> into i32
356  vector.reduction "add", %arg0 : vector<16xi32> into i32
357  // CHECK:    vector.reduction "mul", %{{.*}} : vector<16xi32> into i32
358  vector.reduction "mul", %arg0 : vector<16xi32> into i32
359  // CHECK:    vector.reduction "min", %{{.*}} : vector<16xi32> into i32
360  vector.reduction "min", %arg0 : vector<16xi32> into i32
361  // CHECK:    vector.reduction "max", %{{.*}} : vector<16xi32> into i32
362  vector.reduction "max", %arg0 : vector<16xi32> into i32
363  // CHECK:    vector.reduction "and", %{{.*}} : vector<16xi32> into i32
364  vector.reduction "and", %arg0 : vector<16xi32> into i32
365  // CHECK:    vector.reduction "or", %{{.*}} : vector<16xi32> into i32
366  vector.reduction "or", %arg0 : vector<16xi32> into i32
367  // CHECK:    %[[X:.*]] = vector.reduction "xor", %{{.*}} : vector<16xi32> into i32
368  %0 = vector.reduction "xor", %arg0 : vector<16xi32> into i32
369  // CHECK:    return %[[X]] : i32
370  return %0 : i32
371}
372
373// CHECK-LABEL: @transpose_fp
374func @transpose_fp(%arg0: vector<3x7xf32>) -> vector<7x3xf32> {
375  // CHECK: %[[X:.*]] = vector.transpose %{{.*}}, [1, 0] : vector<3x7xf32> to vector<7x3xf32>
376  %0 = vector.transpose %arg0, [1, 0] : vector<3x7xf32> to vector<7x3xf32>
377  // CHECK: return %[[X]] : vector<7x3xf32>
378  return %0 : vector<7x3xf32>
379}
380
381// CHECK-LABEL: @transpose_int
382func @transpose_int(%arg0: vector<11x7x3x2xi32>) -> vector<2x11x7x3xi32> {
383  // CHECK: %[[X:.*]] = vector.transpose %{{.*}}, [3, 0, 1, 2] : vector<11x7x3x2xi32> to vector<2x11x7x3xi32>
384  %0 = vector.transpose %arg0, [3, 0, 1, 2] : vector<11x7x3x2xi32> to vector<2x11x7x3xi32>
385  // CHECK: return %[[X]] : vector<2x11x7x3xi32>
386  return %0 : vector<2x11x7x3xi32>
387}
388
389// CHECK-LABEL: @flat_transpose_fp
390func @flat_transpose_fp(%arg0: vector<16xf32>) -> vector<16xf32> {
391  // CHECK: %[[X:.*]] = vector.flat_transpose %{{.*}} {columns = 4 : i32, rows = 4 : i32} : vector<16xf32> -> vector<16xf32>
392  %0 = vector.flat_transpose %arg0 { rows = 4: i32, columns = 4: i32 } : vector<16xf32> -> vector<16xf32>
393  // CHECK: return %[[X]] : vector<16xf32>
394  return %0 : vector<16xf32>
395}
396
397// CHECK-LABEL: @flat_transpose_int
398func @flat_transpose_int(%arg0: vector<16xi32>) -> vector<16xi32> {
399  // CHECK: %[[X:.*]] = vector.flat_transpose %{{.*}} {columns = 8 : i32, rows = 2 : i32} : vector<16xi32> -> vector<16xi32>
400  %0 = vector.flat_transpose %arg0 { rows = 2: i32, columns = 8: i32 } : vector<16xi32> -> vector<16xi32>
401  // CHECK: return %[[X]] : vector<16xi32>
402  return %0 : vector<16xi32>
403}
404
405// CHECK-LABEL: @masked_load_and_store
406func @masked_load_and_store(%base: memref<?xf32>, %mask: vector<16xi1>, %passthru: vector<16xf32>) {
407  // CHECK: %[[X:.*]] = vector.maskedload %{{.*}}, %{{.*}}, %{{.*}} : memref<?xf32>, vector<16xi1>, vector<16xf32> into vector<16xf32>
408  %0 = vector.maskedload %base, %mask, %passthru : memref<?xf32>, vector<16xi1>, vector<16xf32> into vector<16xf32>
409  // CHECK: vector.maskedstore %{{.*}}, %{{.*}}, %[[X]] : vector<16xi1>, vector<16xf32> into memref<?xf32>
410  vector.maskedstore %base, %mask, %0 : vector<16xi1>, vector<16xf32> into memref<?xf32>
411  return
412}
413
414// CHECK-LABEL: @gather_and_scatter
415func @gather_and_scatter(%base: memref<?xf32>, %indices: vector<16xi32>, %mask: vector<16xi1>) {
416  // CHECK: %[[X:.*]] = vector.gather %{{.*}}, %{{.*}}, %{{.*}} : (memref<?xf32>, vector<16xi32>, vector<16xi1>) -> vector<16xf32>
417  %0 = vector.gather %base, %indices, %mask : (memref<?xf32>, vector<16xi32>, vector<16xi1>) -> vector<16xf32>
418  // CHECK: %[[Y:.*]] = vector.gather %{{.*}}, %{{.*}}, %{{.*}}, %[[X]] : (memref<?xf32>, vector<16xi32>, vector<16xi1>, vector<16xf32>) -> vector<16xf32>
419  %1 = vector.gather %base, %indices, %mask, %0 : (memref<?xf32>, vector<16xi32>, vector<16xi1>, vector<16xf32>) -> vector<16xf32>
420  // CHECK: vector.scatter %{{.*}}, %{{.*}}, %{{.*}}, %[[Y]] : vector<16xi32>, vector<16xi1>, vector<16xf32> into memref<?xf32>
421  vector.scatter %base, %indices, %mask, %1 : vector<16xi32>, vector<16xi1>, vector<16xf32> into memref<?xf32>
422  return
423}
424
425// CHECK-LABEL: @expand_and_compress
426func @expand_and_compress(%base: memref<?xf32>, %mask: vector<16xi1>, %passthru: vector<16xf32>) {
427  // CHECK: %[[X:.*]] = vector.expandload %{{.*}}, %{{.*}}, %{{.*}} : memref<?xf32>, vector<16xi1>, vector<16xf32> into vector<16xf32>
428  %0 = vector.expandload %base, %mask, %passthru : memref<?xf32>, vector<16xi1>, vector<16xf32> into vector<16xf32>
429  // CHECK: vector.compressstore %{{.*}}, %{{.*}}, %[[X]] : memref<?xf32>, vector<16xi1>, vector<16xf32>
430  vector.compressstore %base, %mask, %0 : memref<?xf32>, vector<16xi1>, vector<16xf32>
431  return
432}
433
434// CHECK-LABEL: @extract_insert_map
435func @extract_insert_map(%v: vector<32xf32>, %v2: vector<16x32xf32>,
436  %id0 : index, %id1 : index) -> (vector<32xf32>, vector<16x32xf32>) {
437  // CHECK: %[[V:.*]] = vector.extract_map %{{.*}}[%{{.*}}] : vector<32xf32> to vector<2xf32>
438  %vd = vector.extract_map %v[%id0] : vector<32xf32> to vector<2xf32>
439  // CHECK: %[[V1:.*]] = vector.extract_map %{{.*}}[%{{.*}}, %{{.*}}] : vector<16x32xf32> to vector<4x2xf32>
440  %vd2 = vector.extract_map %v2[%id0, %id1] : vector<16x32xf32> to vector<4x2xf32>
441  // CHECK: %[[R:.*]] = vector.insert_map %[[V]], %{{.*}}[%{{.*}}] : vector<2xf32> into vector<32xf32>
442  %r = vector.insert_map %vd, %v[%id0] : vector<2xf32> into vector<32xf32>
443  // CHECK: %[[R1:.*]] = vector.insert_map %[[V1]], %{{.*}}[%{{.*}}, %{{.*}}] : vector<4x2xf32> into vector<16x32xf32>
444  %r2 = vector.insert_map %vd2, %v2[%id0, %id1] : vector<4x2xf32> into vector<16x32xf32>
445  // CHECK: return %[[R]], %[[R1]] : vector<32xf32>, vector<16x32xf32>
446  return %r, %r2 : vector<32xf32>, vector<16x32xf32>
447}
448
449