Skip to content

Commit 6e68537

Browse files
committed
update testing
1 parent 0909b5b commit 6e68537

File tree

3 files changed

+85
-138
lines changed

3 files changed

+85
-138
lines changed

mlir/test/Dialect/Vector/canonicalize.mlir

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,30 +1033,6 @@ func.func @canonicalize_broadcast_shapecast_to_broadcast_scalar(%arg0: f32) -> v
10331033

10341034
// -----
10351035

1036-
// In this test, broadcast (2)->(1,2,1) is not legal, but shape_cast (2)->(1,2,1) is.
1037-
// CHECK-LABEL: func @canonicalize_broadcast_shapecast_to_shapcast
1038-
// CHECK-NOT: vector.broadcast
1039-
// CHECK: vector.shape_cast {{.+}} : vector<2xf32> to vector<1x2x1xf32>
1040-
func.func @canonicalize_broadcast_shapecast_to_shapcast(%arg0 : vector<2xf32>) -> vector<1x2x1xf32> {
1041-
%0 = vector.broadcast %arg0 : vector<2xf32> to vector<1x2xf32>
1042-
%1 = vector.shape_cast %0 : vector<1x2xf32> to vector<1x2x1xf32>
1043-
return %1 : vector<1x2x1xf32>
1044-
}
1045-
1046-
// -----
1047-
1048-
// In this test, broadcast (1)->(1,1) and shape_cast (1)->(1,1) are both legal. shape_cast is chosen.
1049-
// CHECK-LABEL: func @canonicalize_broadcast_shapecast_both_possible
1050-
// CHECK-NOT: vector.broadcast
1051-
// CHECK: vector.shape_cast {{.+}} : vector<1xf32> to vector<1x1xf32>
1052-
func.func @canonicalize_broadcast_shapecast_both_possible(%arg0: vector<1xf32>) -> vector<1x1xf32> {
1053-
%0 = vector.broadcast %arg0 : vector<1xf32> to vector<1x1x1xf32>
1054-
%1 = vector.shape_cast %0 : vector<1x1x1xf32> to vector<1x1xf32>
1055-
return %1 : vector<1x1xf32>
1056-
}
1057-
1058-
// -----
1059-
10601036
// CHECK-LABEL: fold_vector_transfer_masks
10611037
func.func @fold_vector_transfer_masks(%A: memref<?x?xf32>) -> (vector<4x8xf32>, vector<4x[4]xf32>) {
10621038
// CHECK: %[[C0:.+]] = arith.constant 0 : index

mlir/test/Dialect/Vector/canonicalize/vector-shape-cast.mlir

Lines changed: 85 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,5 @@
11
// RUN: mlir-opt %s -split-input-file -canonicalize | FileCheck %s
22

3-
// +----------------------------------------
4-
// Tests of TransposeToShapeCast
5-
// +----------------------------------------
6-
7-
// CHECK-LABEL: @transpose_to_shape_cast
8-
// CHECK-SAME: %[[ARG0:.*]]: vector<2x1x2xf32>
9-
// CHECK-NEXT: %[[SCAST:.*]] = vector.shape_cast %[[ARG0]]
10-
// CHECK-NEXT: return %[[SCAST]] : vector<2x2x1xf32>
11-
func.func @transpose_to_shape_cast(%arg0 : vector<2x1x2xf32>) -> vector<2x2x1xf32> {
12-
%0 = vector.transpose %arg0, [0, 2, 1] : vector<2x1x2xf32> to vector<2x2x1xf32>
13-
return %0 : vector<2x2x1xf32>
14-
}
15-
16-
17-
// -----
18-
19-
// CHECK-LABEL: @negative_transpose_to_shape_cast
20-
// CHECK-SAME: %[[ARG0:.*]]: vector<2x1x2xf32>
21-
// CHECK-NEXT: %[[TRANSPOSE:.*]] = vector.transpose %[[ARG0]], [2, 0, 1]
22-
// CHECK-NEXT: return %[[TRANSPOSE]] : vector<2x2x1xf32>
23-
func.func @negative_transpose_to_shape_cast(%arg0 : vector<2x1x2xf32>) -> vector<2x2x1xf32> {
24-
%0 = vector.transpose %arg0, [2, 0, 1] : vector<2x1x2xf32> to vector<2x2x1xf32>
25-
return %0 : vector<2x2x1xf32>
26-
}
27-
28-
// -----
293

304
// +----------------------------------------
315
// Tests of BroadcastToShapeCast
@@ -42,16 +16,20 @@ func.func @broadcast_to_shape_cast(%arg0 : vector<4xi8>) -> vector<1x1x4xi8> {
4216

4317
// -----
4418

45-
// CHECK-LABEL: @negative_broadcast_to_shape_cast
19+
// broadcast can only be transformed to a shape_cast if the number of elements is
20+
// unchanged by the broadcast
21+
// CHECK-LABEL: @negative_broadcast_increased_elements_to_shape_cast
4622
// CHECK-NOT: shape_cast
4723
// CHECK: return
48-
func.func @negative_broadcast_to_shape_cast(%arg0 : vector<1x4xi8>) -> vector<2x3x4xi8> {
24+
func.func @negative_broadcast_increased_elements_to_shape_cast(%arg0 : vector<1x4xi8>) -> vector<2x3x4xi8> {
4925
%0 = vector.broadcast %arg0 : vector<1x4xi8> to vector<2x3x4xi8>
5026
return %0 : vector<2x3x4xi8>
5127
}
5228

5329
// -----
5430

31+
// shape_cast does not support scalar inputs/outputs, so a broadcast of a scalar
32+
// cannot be transformed to a shape_cast.
5533
// CHECK-LABEL: @negative_broadcast_scalar_to_shape_cast
5634
// CHECK-NOT: shape_cast
5735
// CHECK: return
@@ -62,56 +40,101 @@ func.func @negative_broadcast_scalar_to_shape_cast(%arg0 : i8) -> vector<1xi8> {
6240

6341
// -----
6442

65-
// The conversion transpose(shape_cast) -> shape_cast is currently disabled for scalable
66-
// vectors.
67-
// CHECK-LABEL: @transpose_of_shape_cast_scalable
68-
// CHECK: vector.shape_cast
69-
// CHECK: vector.transpose
70-
func.func @transpose_of_shape_cast_scalable(%arg : vector<[4]xi8>) -> vector<[4]x1xi8> {
71-
%0 = vector.shape_cast %arg : vector<[4]xi8> to vector<1x[4]xi8>
72-
%1 = vector.transpose %0, [1, 0] : vector<1x[4]xi8> to vector<[4]x1xi8>
73-
return %1 : vector<[4]x1xi8>
43+
// +----------------------------------------
44+
// Tests of TransposeToShapeCast
45+
// +----------------------------------------
46+
47+
// In this test, the permutation maps the non-unit dimensions (0 and 2) as follows:
48+
// 0 -> 0
49+
// 2 -> 1
50+
// Because 0 < 1, this permutation is order preserving and effectively a shape_cast.
51+
// CHECK-LABEL: @transpose_to_shape_cast
52+
// CHECK-SAME: %[[ARG0:.*]]: vector<2x1x2xf32>
53+
// CHECK-NEXT: %[[SCAST:.*]] = vector.shape_cast %[[ARG0]]
54+
// CHECK-NEXT: return %[[SCAST]] : vector<2x2x1xf32>
55+
func.func @transpose_to_shape_cast(%arg0 : vector<2x1x2xf32>) -> vector<2x2x1xf32> {
56+
%0 = vector.transpose %arg0, [0, 2, 1] : vector<2x1x2xf32> to vector<2x2x1xf32>
57+
return %0 : vector<2x2x1xf32>
7458
}
7559

7660
// -----
7761

78-
// A transpose that is 'order preserving' can be treated like a shape_cast.
79-
// CHECK-LABEL: @transpose_of_shape_cast
80-
// CHECK-SAME: %[[ARG:.*]]: vector<2x3x1x1xi8>) -> vector<6x1x1xi8> {
62+
// In this test, the permutation maps the non-unit dimensions (1 and 2) as follows:
63+
// 1 -> 0
64+
// 2 -> 4
65+
// Because 0 < 4, this permutation is order preserving and effectively a shape_cast.
66+
// CHECK-LABEL: @shape_cast_of_transpose
67+
// CHECK-SAME: %[[ARG:.*]]: vector<1x4x4x1x1xi8>)
8168
// CHECK: %[[SHAPE_CAST:.*]] = vector.shape_cast %[[ARG]] :
82-
// CHECK-SAME: vector<2x3x1x1xi8> to vector<6x1x1xi8>
83-
// CHECK: return %[[SHAPE_CAST]] : vector<6x1x1xi8>
84-
func.func @transpose_of_shape_cast(%arg : vector<2x3x1x1xi8>) -> vector<6x1x1xi8> {
85-
%0 = vector.shape_cast %arg : vector<2x3x1x1xi8> to vector<6x1x1xi8>
86-
%1 = vector.transpose %0, [0, 2, 1]
87-
: vector<6x1x1xi8> to vector<6x1x1xi8>
88-
return %1 : vector<6x1x1xi8>
69+
// CHECK-SAME: vector<1x4x4x1x1xi8> to vector<4x1x1x1x4xi8>
70+
// CHECK: return %[[SHAPE_CAST]]
71+
func.func @shape_cast_of_transpose(%arg : vector<1x4x4x1x1xi8>) -> vector<4x1x1x1x4xi8> {
72+
%0 = vector.transpose %arg, [1, 0, 3, 4, 2] : vector<1x4x4x1x1xi8> to vector<4x1x1x1x4xi8>
73+
return %0 : vector<4x1x1x1x4xi8>
8974
}
9075

9176
// -----
9277

9378
// Scalable dimensions should be treated as non-unit dimensions.
94-
// CHECK-LABEL: @transpose_of_shape_cast_scalable
79+
// CHECK-LABEL: @transpose_scalable_unit
80+
// CHECK-NOT: shape_cast
81+
func.func @transpose_scalable_unit(%arg : vector<[1]x4xi8>) -> vector<4x[1]xi8> {
82+
%0 = vector.transpose %arg, [1, 0] : vector<[1]x4xi8> to vector<4x[1]xi8>
83+
return %0 : vector<4x[1]xi8>
84+
}
85+
86+
// -----
87+
88+
// In this test, the mapping of non-unit dimensions (1 and 2) is as follows:
89+
// 1 -> 2
90+
// 2 -> 1
91+
// As this is not increasing (2 > 1), this transpose is not order
92+
// preserving and cannot be treated as a shape_cast.
93+
// CHECK-LABEL: @negative_transpose_to_shape_cast
94+
// CHECK-NOT: shape_cast
95+
func.func @negative_transpose_to_shape_cast(%arg : vector<1x4x4x1xi8>) -> vector<1x4x4x1xi8> {
96+
%0 = vector.transpose %arg, [0, 2, 1, 3]
97+
: vector<1x4x4x1xi8> to vector<1x4x4x1xi8>
98+
return %0 : vector<1x4x4x1xi8>
99+
}
100+
101+
// -----
102+
103+
// Currently the conversion shape_cast(transpose) -> shape_cast is disabled for
104+
// scalable vectors because of bad interaction with ConvertIllegalShapeCastOpsToTransposes
105+
// CHECK-LABEL: @negative_shape_cast_of_transpose_scalable
106+
// CHECK: vector.transpose
107+
// CHECK: vector.shape_cast
108+
func.func @negative_shape_cast_of_transpose_scalable(%arg : vector<[4]x1xi8>) -> vector<[4]xi8> {
109+
%0 = vector.transpose %arg, [1, 0] : vector<[4]x1xi8> to vector<1x[4]xi8>
110+
%1 = vector.shape_cast %0 : vector<1x[4]xi8> to vector<[4]xi8>
111+
return %1 : vector<[4]xi8>
112+
}
113+
114+
// -----
115+
116+
// The conversion transpose(shape_cast) -> shape_cast is currently disabled for scalable
117+
// vectors.
118+
// CHECK-LABEL: @negative_transpose_of_shape_cast_scalable
95119
// CHECK: vector.shape_cast
96120
// CHECK: vector.transpose
97-
func.func @transpose_of_shape_cast_scalable_unit(%arg : vector<[1]x4x1xi8>) -> vector<4x[1]xi8> {
98-
%0 = vector.shape_cast %arg : vector<[1]x4x1xi8> to vector<[1]x4xi8>
99-
%1 = vector.transpose %0, [1, 0] : vector<[1]x4xi8> to vector<4x[1]xi8>
100-
return %1 : vector<4x[1]xi8>
121+
func.func @negative_transpose_of_shape_cast_scalable(%arg : vector<[4]xi8>) -> vector<[4]x1xi8> {
122+
%0 = vector.shape_cast %arg : vector<[4]xi8> to vector<1x[4]xi8>
123+
%1 = vector.transpose %0, [1, 0] : vector<1x[4]xi8> to vector<[4]x1xi8>
124+
return %1 : vector<[4]x1xi8>
101125
}
102126

103127
// -----
104128

105-
// Test of shape_cast (not) folding.
106-
// CHECK-LABEL: @negative_transpose_of_shape_cast
107-
// CHECK-SAME: %[[ARG:.*]]: vector<6xi8>) -> vector<2x3xi8> {
108-
// CHECK: %[[SHAPE_CAST:.*]] = vector.shape_cast %[[ARG]] :
109-
// CHECK: %[[TRANSPOSE:.*]] = vector.transpose %[[SHAPE_CAST]]
110-
// CHECK: return %[[TRANSPOSE]] : vector<2x3xi8>
111-
func.func @negative_transpose_of_shape_cast(%arg : vector<6xi8>) -> vector<2x3xi8> {
112-
%0 = vector.shape_cast %arg : vector<6xi8> to vector<3x2xi8>
113-
%1 = vector.transpose %0, [1, 0] : vector<3x2xi8> to vector<2x3xi8>
114-
return %1 : vector<2x3xi8>
129+
// A test where a transpose cannot be transformed to a shape_cast because it is not order
130+
// preserving
131+
// CHECK-LABEL: @negative_transpose_to_shape_cast
132+
// CHECK-SAME: %[[ARG0:.*]]: vector<2x1x2xf32>
133+
// CHECK-NEXT: %[[TRANSPOSE:.*]] = vector.transpose %[[ARG0]], [2, 0, 1]
134+
// CHECK-NEXT: return %[[TRANSPOSE]] : vector<2x2x1xf32>
135+
func.func @negative_transpose_to_shape_cast(%arg0 : vector<2x1x2xf32>) -> vector<2x2x1xf32> {
136+
%0 = vector.transpose %arg0, [2, 0, 1] : vector<2x1x2xf32> to vector<2x2x1xf32>
137+
return %0 : vector<2x2x1xf32>
115138
}
116139

117140
// -----

mlir/test/Dialect/Vector/canonicalize/vector-transpose.mlir

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -143,58 +143,6 @@ func.func @negative_broadcast_transpose_021(%arg0 : vector<3x1x3xi8>) -> vector<
143143

144144
// -----
145145

146-
/// +--------------------------------------------------------------------------
147-
/// Tests of ShapeCastOp::fold: shape_cast(transpose) -> shape_cast
148-
/// +--------------------------------------------------------------------------
149-
150-
// In this test, the permutation maps the non-unit dimensions (1 and 2) as follows:
151-
// 1 -> 0
152-
// 2 -> 4
153-
// Because 0 < 4, this permutation is order preserving and effectively a shape_cast.
154-
// CHECK-LABEL: @shape_cast_of_transpose
155-
// CHECK-SAME: %[[ARG:.*]]: vector<1x4x4x1x1xi8>) -> vector<4x4xi8> {
156-
// CHECK: %[[SHAPE_CAST:.*]] = vector.shape_cast %[[ARG]] :
157-
// CHECK-SAME: vector<1x4x4x1x1xi8> to vector<4x4xi8>
158-
// CHECK: return %[[SHAPE_CAST]] : vector<4x4xi8>
159-
func.func @shape_cast_of_transpose(%arg : vector<1x4x4x1x1xi8>) -> vector<4x4xi8> {
160-
%0 = vector.transpose %arg, [1, 0, 3, 4, 2]
161-
: vector<1x4x4x1x1xi8> to vector<4x1x1x1x4xi8>
162-
%1 = vector.shape_cast %0 : vector<4x1x1x1x4xi8> to vector<4x4xi8>
163-
return %1 : vector<4x4xi8>
164-
}
165-
166-
// -----
167-
168-
// In this test, the mapping of non-unit dimensions (1 and 2) is as follows:
169-
// 1 -> 2
170-
// 2 -> 1
171-
// As this is not increasing (2 > 1), this transpose is not order
172-
// preserving and cannot be treated as a shape_cast.
173-
// CHECK-LABEL: @negative_shape_cast_of_transpose
174-
// CHECK-SAME: %[[ARG:.*]]: vector<1x4x4x1xi8>) -> vector<4x4xi8> {
175-
// CHECK: %[[TRANSPOSE:.*]] = vector.transpose %[[ARG]]
176-
// CHECK: %[[SHAPE_CAST:.*]] = vector.shape_cast %[[TRANSPOSE]]
177-
// CHECK: return %[[SHAPE_CAST]] : vector<4x4xi8>
178-
func.func @negative_shape_cast_of_transpose(%arg : vector<1x4x4x1xi8>) -> vector<4x4xi8> {
179-
%0 = vector.transpose %arg, [0, 2, 1, 3]
180-
: vector<1x4x4x1xi8> to vector<1x4x4x1xi8>
181-
%1 = vector.shape_cast %0 : vector<1x4x4x1xi8> to vector<4x4xi8>
182-
return %1 : vector<4x4xi8>
183-
}
184-
185-
// -----
186-
187-
// Currently the conversion shape_cast(transpose) -> shape_cast is disabled for
188-
// scalable vectors because of bad interaction with ConvertIllegalShapeCastOpsToTransposes
189-
// CHECK-LABEL: @negative_shape_cast_of_transpose_scalable
190-
// CHECK: vector.transpose
191-
// CHECK: vector.shape_cast
192-
func.func @negative_shape_cast_of_transpose_scalable(%arg : vector<[4]x1xi8>) -> vector<[4]xi8> {
193-
%0 = vector.transpose %arg, [1, 0] : vector<[4]x1xi8> to vector<1x[4]xi8>
194-
%1 = vector.shape_cast %0 : vector<1x[4]xi8> to vector<[4]xi8>
195-
return %1 : vector<[4]xi8>
196-
}
197-
198146
// +-----------------------------------
199147
// Tests of TransposeOp::fold
200148
// +-----------------------------------

0 commit comments

Comments
 (0)