173
|
1 // RUN: mlir-opt %s -test-vector-slices-conversion | FileCheck %s
|
|
2
|
|
3 // CHECK-LABEL: func @extract_slices(%arg0: vector<3x3xf32>)
|
|
4 // CHECK: %[[SS:.*]] = vector.extract_strided_slice %arg0 {offsets = [0, 0], sizes = [2, 2], strides = [1, 1]}
|
|
5 // CHECK: return %[[SS]]
|
|
6
|
|
7 func @extract_slices(%arg0: vector<3x3xf32>) -> vector<2x2xf32> {
|
|
8 %0 = vector.extract_slices %arg0, [2, 2], [1, 1]
|
|
9 : vector<3x3xf32> into tuple<vector<2x2xf32>, vector<2x1xf32>, vector<1x2xf32>, vector<1x1xf32>>
|
|
10 %1 = vector.tuple_get %0, 0 : tuple<vector<2x2xf32>, vector<2x1xf32>, vector<1x2xf32>, vector<1x1xf32>>
|
|
11 return %1 : vector<2x2xf32>
|
|
12 }
|
|
13
|
|
14 // CHECK-LABEL: func @insert_slices(%arg0: vector<2x2xf32>, %arg1: vector<2x1xf32>, %arg2: vector<1x2xf32>, %arg3: vector<1x1xf32>)
|
|
15 // CHECK: %[[C0:.*]] = constant dense<0.000000e+00> : vector<3x3xf32>
|
|
16 // CHECK: %[[I0:.*]] = vector.insert_strided_slice %arg0, %[[C0]] {offsets = [0, 0], strides = [1, 1]}
|
|
17 // CHECK: %[[I1:.*]] = vector.insert_strided_slice %arg1, %[[I0]] {offsets = [0, 2], strides = [1, 1]}
|
|
18 // CHECK: %[[I2:.*]] = vector.insert_strided_slice %arg2, %[[I1]] {offsets = [2, 0], strides = [1, 1]}
|
|
19 // CHECK: %[[I3:.*]] = vector.insert_strided_slice %arg3, %[[I2]] {offsets = [2, 2], strides = [1, 1]}
|
|
20 // CHECK: return %[[I3]]
|
|
21
|
|
22 func @insert_slices(%arg0: vector<2x2xf32>,
|
|
23 %arg1: vector<2x1xf32>,
|
|
24 %arg2: vector<1x2xf32>,
|
|
25 %arg3: vector<1x1xf32>) -> vector<3x3xf32> {
|
|
26 %0 = vector.tuple %arg0, %arg1, %arg2, %arg3
|
|
27 : vector<2x2xf32>, vector<2x1xf32>, vector<1x2xf32>, vector<1x1xf32>
|
|
28 %1 = vector.insert_slices %0, [2, 2], [1, 1]
|
|
29 : tuple<vector<2x2xf32>, vector<2x1xf32>, vector<1x2xf32>, vector<1x1xf32>> into vector<3x3xf32>
|
|
30 return %1 : vector<3x3xf32>
|
|
31 }
|
|
32
|
|
33 // CHECK-LABEL: func @extract_insert_slices(%arg0: vector<3x3xf32>)
|
|
34 // CHECK: %[[C:.*]] = constant dense<0.000000e+00> : vector<3x3xf32>
|
|
35 // CHECK: %[[X0:.*]] = vector.extract_strided_slice %arg0 {offsets = [0, 0], sizes = [2, 2], strides = [1, 1]}
|
|
36 // CHECK: %[[X1:.*]] = vector.extract_strided_slice %arg0 {offsets = [0, 2], sizes = [2, 1], strides = [1, 1]}
|
|
37 // CHECK: %[[X2:.*]] = vector.extract_strided_slice %arg0 {offsets = [2, 0], sizes = [1, 2], strides = [1, 1]}
|
|
38 // CHECK: %[[X3:.*]] = vector.extract_strided_slice %arg0 {offsets = [2, 2], sizes = [1, 1], strides = [1, 1]}
|
|
39 // CHECK: %[[X4:.*]] = vector.insert_strided_slice %[[X0]], %[[C0]] {offsets = [0, 0], strides = [1, 1]}
|
|
40 // CHECK: %[[X5:.*]] = vector.insert_strided_slice %[[X1]], %[[X4]] {offsets = [0, 2], strides = [1, 1]}
|
|
41 // CHECK: %[[X6:.*]] = vector.insert_strided_slice %[[X2]], %[[X5]] {offsets = [2, 0], strides = [1, 1]}
|
|
42 // CHECK: %[[X7:.*]] = vector.insert_strided_slice %[[X3]], %[[X6]] {offsets = [2, 2], strides = [1, 1]}
|
|
43 // CHECK:return %[[X7]]
|
|
44
|
|
45 func @extract_insert_slices(%arg0: vector<3x3xf32>) -> vector<3x3xf32> {
|
|
46 %0 = vector.extract_slices %arg0, [2, 2], [1, 1]
|
|
47 : vector<3x3xf32> into tuple<vector<2x2xf32>, vector<2x1xf32>, vector<1x2xf32>, vector<1x1xf32>>
|
|
48 %1 = vector.insert_slices %0, [2, 2], [1, 1]
|
|
49 : tuple<vector<2x2xf32>, vector<2x1xf32>, vector<1x2xf32>, vector<1x1xf32>> into vector<3x3xf32>
|
|
50 return %1 : vector<3x3xf32>
|
|
51 }
|
|
52
|
|
53 // CHECK-LABEL: func @extract_slices_tuple_leaks(%arg0: vector<4xf32>)
|
|
54 // CHECK: %[[X0:.*]] = vector.extract_strided_slice %arg0 {offsets = [0], sizes = [2], strides = [1]}
|
|
55 // CHECK: %[[X1:.*]] = vector.extract_strided_slice %arg0 {offsets = [2], sizes = [2], strides = [1]}
|
|
56 // CHECK: %[[X2:.*]] = vector.tuple %[[X0]], %[[X1]]
|
|
57 // CHECK: return %[[X2]]
|
|
58
|
|
59 func @extract_slices_tuple_leaks(%arg0: vector<4xf32>) -> tuple<vector<2xf32>, vector<2xf32>> {
|
|
60 %0 = vector.extract_slices %arg0, [2], [1] : vector<4xf32> into tuple<vector<2xf32>, vector<2xf32>>
|
|
61 return %0 : tuple<vector<2xf32>, vector<2xf32>>
|
|
62 }
|
|
63
|