Skip to content

Commit bf4fc00

Browse files
authored
[mlir][vector] Refactor linearize.mlir (#86648)
This patch refactors the `linearize.mlir` test - currently it contains some duplication and can be tricky to follow. Summary of changes: * reduce duplication by introducing a shared check prefix (`ALL`) and by introducing `-check-prefixes`, * make sure that every "check" line is directly above the corresponding line of input MLIR, * group check lines corresponding to a particular prefix together (so that it's easier to see the expected output for a particular prefix), * remove `CHECK` from prefix names (with multiple prefixes that's just noise that can be avoided) and use a bit more descriptive prefixes instead (`CHECK0` -> `BW-0`, where `BW` stands for bitwidth), * unify indentation, * `nonvec_result` -> `test_tensor_no_linearize` (for consistency with `test_index_no_linearize`). NOTE: This change only updates the format of the "CHECK" lines and doesn't affect what's being tested. This change is intended as preparation for adding support for scalable vectors to `LinearizeConstant` and `LinearizeVectorizable` - i.e. patterns that `linearlize.mlir` is meant to test.
1 parent 39c03a2 commit bf4fc00

File tree

1 file changed

+61
-67
lines changed

1 file changed

+61
-67
lines changed

mlir/test/Dialect/Vector/linearize.mlir

Lines changed: 61 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,87 @@
1-
// RUN: mlir-opt %s -split-input-file -test-vector-linearize | FileCheck %s
2-
// RUN: mlir-opt %s -split-input-file -test-vector-linearize=target-vector-bitwidth=128 | FileCheck %s --check-prefix=CHECK128
3-
// RUN: mlir-opt %s -split-input-file -test-vector-linearize=target-vector-bitwidth=0 | FileCheck %s --check-prefix=CHECK0
4-
5-
// CHECK-LABEL: test_linearize
6-
// CHECK128-LABEL: test_linearize
7-
// CHECK0-LABEL: test_linearize
8-
// CHECK-SAME: (%[[ORIG_ARG:.*]]: vector<2x2xf32>)
9-
// CHECK128-SAME: (%[[ORIG_ARG:.*]]: vector<2x2xf32>)
10-
// CHECK: %[[ARG:.*]] = vector.shape_cast %[[ORIG_ARG]] : vector<2x2xf32> to vector<4xf32>
11-
// CHECK128: %[[ARG:.*]] = vector.shape_cast %[[ORIG_ARG]] : vector<2x2xf32> to vector<4xf32>
1+
// RUN: mlir-opt %s -split-input-file -test-vector-linearize | FileCheck %s --check-prefixes=ALL,DEFAULT
2+
// RUN: mlir-opt %s -split-input-file -test-vector-linearize=target-vector-bitwidth=128 | FileCheck %s --check-prefixes=ALL,BW-128
3+
// RUN: mlir-opt %s -split-input-file -test-vector-linearize=target-vector-bitwidth=0 | FileCheck %s --check-prefixes=ALL,BW-0
4+
5+
// ALL-LABEL: test_linearize
6+
// ALL-SAME: (%[[ORIG_ARG:.*]]: vector<2x2xf32>)
127
func.func @test_linearize(%arg0: vector<2x2xf32>) -> vector<2x2xf32> {
13-
// CHECK: %[[C1:.*]] = arith.constant dense<[1.000000e+00, 2.000000e+00, 3.000000e+00, 4.000000e+00]> : vector<4xf32>
14-
// CHECK128: %[[C1:.*]] = arith.constant dense<[1.000000e+00, 2.000000e+00, 3.000000e+00, 4.000000e+00]> : vector<4xf32>
15-
// CHECK0: %[[C1:.*]] = arith.constant dense<{{.*}}> : vector<2x2xf32>
8+
// DEFAULT: %[[ARG:.*]] = vector.shape_cast %[[ORIG_ARG]] : vector<2x2xf32> to vector<4xf32>
9+
// DEFAULT: %[[CST:.*]] = arith.constant dense<[1.000000e+00, 2.000000e+00, 3.000000e+00, 4.000000e+00]> : vector<4xf32>
10+
// DEFAULT: %[[RES:.*]] = vector.shape_cast %[[CST]] : vector<4xf32> to vector<2x2xf32>
11+
12+
// BW-128: %[[ARG:.*]] = vector.shape_cast %[[ORIG_ARG]] : vector<2x2xf32> to vector<4xf32>
13+
// BW-128: %[[CST:.*]] = arith.constant dense<[1.000000e+00, 2.000000e+00, 3.000000e+00, 4.000000e+00]> : vector<4xf32>
14+
// BW-128: %[[RES:.*]] = vector.shape_cast %[[CST]] : vector<4xf32> to vector<2x2xf32>
1615

16+
// BW-0: %[[RES:.*]] = arith.constant dense<{{.*}}> : vector<2x2xf32>
1717
%0 = arith.constant dense<[[1.0, 2.0], [3.0, 4.0]]> : vector<2x2xf32>
18-
// CHECK: %[[RES:.*]] = vector.shape_cast %[[C1]] : vector<4xf32> to vector<2x2xf32>
19-
// CHECK128: %[[RES:.*]] = vector.shape_cast %[[C1]] : vector<4xf32> to vector<2x2xf32>
20-
// Arith and math ops are handled in generic way, check some of them
21-
// CHECK: %{{.*}} = math.sin %[[ARG]] : vector<4xf32>
22-
// CHECK128: %{{.*}} = math.sin %[[ARG]] : vector<4xf32>
23-
// CHECK0: %{{.*}} = math.sin %{{.*}} : vector<2x2xf32>
18+
19+
// DEFAULT: %{{.*}} = math.sin %[[ARG]] : vector<4xf32>
20+
// BW-128: %{{.*}} = math.sin %[[ARG]] : vector<4xf32>
21+
// BW-0: %{{.*}} = math.sin %{{.*}} : vector<2x2xf32>
2422
%1 = math.sin %arg0 : vector<2x2xf32>
25-
// CHECK: %{{.*}} = arith.addf %[[ARG]], %[[C1]] : vector<4xf32>
26-
// CHECK128: %{{.*}} = arith.addf %[[ARG]], %[[C1]] : vector<4xf32>
27-
// CHECK0: %{{.*}} = arith.addf %{{.*}} : vector<2x2xf32>
2823

24+
// DEFAULT: %{{.*}} = arith.addf %[[ARG]], %[[CST]] : vector<4xf32>
25+
// BW-128: %{{.*}} = arith.addf %[[ARG]], %[[CST]] : vector<4xf32>
26+
// BW-0: %{{.*}} = arith.addf %{{.*}} : vector<2x2xf32>
2927
%2 = arith.addf %arg0, %0 : vector<2x2xf32>
3028

31-
// CHECK: return %[[RES]] : vector<2x2xf32>
32-
// CHECK128: return %[[RES]] : vector<2x2xf32>
29+
// ALL: return %[[RES]] : vector<2x2xf32>
3330
return %0 : vector<2x2xf32>
3431
}
3532

36-
// CHECK-LABEL: test_partial_linearize
37-
// CHECK128-LABEL: test_partial_linearize
38-
// CHECK0-LABEL: test_partial_linearize
39-
// CHECK-SAME: (%[[ORIG_ARG:.*]]: vector<2x2xf32>, %[[ORIG_ARG2:.*]]: vector<4x4xf32>)
40-
// CHECK128-SAME: (%[[ORIG_ARG:.*]]: vector<2x2xf32>, %[[ORIG_ARG2:.*]]: vector<4x4xf32>)
41-
// CHECK0-SAME: (%[[ORIG_ARG:.*]]: vector<2x2xf32>, %[[ORIG_ARG2:.*]]: vector<4x4xf32>)
42-
// CHECK: %[[ARG:.*]] = vector.shape_cast %[[ORIG_ARG]] : vector<2x2xf32> to vector<4xf32>
43-
// CHECK128: %[[ARG:.*]] = vector.shape_cast %[[ORIG_ARG]] : vector<2x2xf32> to vector<4xf32>
44-
// CHECK: %[[ARG2:.*]] = vector.shape_cast %[[ORIG_ARG2]] : vector<4x4xf32> to vector<16xf32>
33+
// -----
34+
35+
// ALL-LABEL: test_partial_linearize
36+
// ALL-SAME: (%[[ORIG_ARG:.*]]: vector<2x2xf32>, %[[ORIG_ARG2:.*]]: vector<4x4xf32>)
4537
func.func @test_partial_linearize(%arg0: vector<2x2xf32>, %arg1: vector<4x4xf32>) -> vector<2x2xf32> {
46-
// CHECK: %[[C1:.*]] = arith.constant dense<[1.000000e+00, 2.000000e+00, 3.000000e+00, 4.000000e+00]> : vector<4xf32>
47-
// CHECK128: %[[C1:.*]] = arith.constant dense<[1.000000e+00, 2.000000e+00, 3.000000e+00, 4.000000e+00]> : vector<4xf32>
48-
// CHECK0: %[[C1:.*]] = arith.constant dense<{{.*}}> : vector<2x2xf32>
38+
// DEFAULT: %[[ARG:.*]] = vector.shape_cast %[[ORIG_ARG]] : vector<2x2xf32> to vector<4xf32>
39+
// DEFAULT: %[[ARG2:.*]] = vector.shape_cast %[[ORIG_ARG2]] : vector<4x4xf32> to vector<16xf32>
40+
// DEFAULT: %[[CST:.*]] = arith.constant dense<{{.*}}> : vector<4xf32>
41+
// DEFAULT: %[[RES:.*]] = vector.shape_cast %[[CST]] : vector<4xf32> to vector<2x2xf32>
4942

43+
// BW-128: %[[ARG:.*]] = vector.shape_cast %[[ORIG_ARG]] : vector<2x2xf32> to vector<4xf32>
44+
// BW-128: %[[CST:.*]] = arith.constant dense<{{.*}}> : vector<4xf32>
45+
// BW-128: %[[RES:.*]] = vector.shape_cast %[[CST]] : vector<4xf32> to vector<2x2xf32>
46+
47+
// BW-0: %[[RES:.*]] = arith.constant dense<{{.*}}> : vector<2x2xf32>
5048
%0 = arith.constant dense<[[1.0, 2.0], [3.0, 4.0]]> : vector<2x2xf32>
51-
// CHECK: %[[RES:.*]] = vector.shape_cast %[[C1]] : vector<4xf32> to vector<2x2xf32>
52-
// CHECK128: %[[RES:.*]] = vector.shape_cast %[[C1]] : vector<4xf32> to vector<2x2xf32>
5349

54-
// CHECK: %[[C2:.*]] = arith.constant dense<[1.000000e+00, 2.000000e+00, 3.000000e+00, 4.000000e+00, 1.000000e+00, 2.000000e+00, 3.000000e+00, 4.000000e+00, 1.000000e+00, 2.000000e+00, 3.000000e+00, 4.000000e+00, 1.000000e+00, 2.000000e+00, 5.000000e+00, 6.000000e+00]> : vector<16xf32>
55-
// CHECK128: %[[C2:.*]] = arith.constant dense<{{.*}}> : vector<4x4xf32>
56-
// CHECK0: %[[C2:.*]] = arith.constant dense<{{.*}}> : vector<4x4xf32>
50+
// DEFAULT: %[[C2:.*]] = arith.constant dense<{{.*}}> : vector<16xf32>
51+
// BW-128: %[[C2:.*]] = arith.constant dense<{{.*}}> : vector<4x4xf32>
52+
// BW-0: %[[C2:.*]] = arith.constant dense<{{.*}}> : vector<4x4xf32>
5753
%5 = arith.constant dense<[[1.0, 2.0, 3.0, 4.0], [1.0, 2.0,3.0, 4.0], [1.0, 2.0, 3.0, 4.0], [1.0, 2.0, 5.0, 6.0]]> : vector<4x4xf32>
58-
// Arith and math ops are handled in generic way, check some of them
59-
// CHECK: %[[SIN:.*]] = math.sin %[[ARG]] : vector<4xf32>
60-
// CHECK128: %[[SIN:.*]] = math.sin %[[ARG]] : vector<4xf32>
61-
// CHECK0: %[[SIN:.*]] = math.sin %[[ORIG_ARG]] : vector<2x2xf32>
54+
55+
// Arith and math ops are handled in generic way, check some of them
56+
// DEFAULT: %[[SIN:.*]] = math.sin %[[ARG]] : vector<4xf32>
57+
// BW-128: %[[SIN:.*]] = math.sin %[[ARG]] : vector<4xf32>
58+
// BW-0: %[[SIN:.*]] = math.sin %[[ORIG_ARG]] : vector<2x2xf32>
6259
%1 = math.sin %arg0 : vector<2x2xf32>
6360

64-
// CHECK: %[[SIN1:.*]] = math.sin %[[ARG2]] : vector<16xf32>
65-
// CHECK128: %[[SIN1:.*]] = math.sin %[[ORIG_ARG2]] : vector<4x4xf32>
66-
// CHECK0: %[[SIN1:.*]] = math.sin %[[ORIG_ARG2]] : vector<4x4xf32>
61+
// DEFAULT: %[[SIN1:.*]] = math.sin %[[ARG2]] : vector<16xf32>
62+
// BW-128: %[[SIN1:.*]] = math.sin %[[ORIG_ARG2]] : vector<4x4xf32>
63+
// BW-0: %[[SIN1:.*]] = math.sin %[[ORIG_ARG2]] : vector<4x4xf32>
6764
%6 = math.sin %arg1 : vector<4x4xf32>
68-
// CHECK: %{{.*}} = arith.addf %[[ARG]], %[[C1]] : vector<4xf32>
69-
// CHECK128: %{{.*}} = arith.addf %[[ARG]], %[[C1]] : vector<4xf32>
70-
// CHECK0: %{{.*}} = arith.addf %{{.*}} : vector<2x2xf32>
7165

66+
// DEFAULT: %{{.*}} = arith.addf %[[ARG]], %[[CST]] : vector<4xf32>
67+
// BW-128: %{{.*}} = arith.addf %[[ARG]], %[[CST]] : vector<4xf32>
68+
// BW-0: %{{.*}} = arith.addf %{{.*}} : vector<2x2xf32>
7269
%2 = arith.addf %arg0, %0 : vector<2x2xf32>
7370

74-
// CHECK: %[[ADD2:.*]] = arith.addf %[[ARG2]], %[[C2]] : vector<16xf32>
75-
// CHECK128: %[[ADD2:.*]] = arith.addf %[[ORIG_ARG2]], %[[C2]] : vector<4x4xf32>
76-
// CHECK0: %[[ADD2:.*]] = arith.addf %[[ORIG_ARG2]], %[[C2]] : vector<4x4xf32>
71+
// DEFAULT: %[[ADD2:.*]] = arith.addf %[[ARG2]], %[[C2]] : vector<16xf32>
72+
// BW-128: %[[ADD2:.*]] = arith.addf %[[ORIG_ARG2]], %[[C2]] : vector<4x4xf32>
73+
// BW-0: %[[ADD2:.*]] = arith.addf %[[ORIG_ARG2]], %[[C2]] : vector<4x4xf32>
7774
%7 = arith.addf %arg1, %5 : vector<4x4xf32>
78-
// CHECK: return %[[RES]] : vector<2x2xf32>
79-
// CHECK128: return %[[RES]] : vector<2x2xf32>
75+
76+
// ALL: return %[[RES]] : vector<2x2xf32>
8077
return %0 : vector<2x2xf32>
8178
}
8279

83-
// CHECK-LABEL: test_index_no_linearize
84-
// CHECK128-LABEL: test_index_no_linearize
85-
// CHECK0-LABEL: test_index_no_linearize
80+
// -----
81+
82+
// ALL-LABEL: test_index_no_linearize
8683
func.func @test_index_no_linearize(%arg0: vector<2x2xindex>, %arg1: vector<2x2xindex>) -> vector<2x2xindex> {
87-
// CHECK: %[[ADD:.*]] = arith.addi {{.*}} : vector<2x2xindex>
88-
// CHECK128: %[[ADD:.*]] = arith.addi {{.*}} : vector<2x2xindex>
89-
// CHECK0: %[[ADD:.*]] = arith.addi {{.*}} : vector<2x2xindex>
84+
// ALL: %[[ADD:.*]] = arith.addi {{.*}} : vector<2x2xindex>
9085
%0 = arith.addi %arg0, %arg1 : vector<2x2xindex>
9186
return %0 : vector<2x2xindex>
9287
}
@@ -95,10 +90,9 @@ func.func @test_index_no_linearize(%arg0: vector<2x2xindex>, %arg1: vector<2x2xi
9590

9691
// vectorizable operation (arith.mulf) with tensor result types.
9792

98-
func.func @nonvec_result(%arg0: tensor<2x2xf32>, %arg1: tensor<2x2xf32>) -> (tensor<2x2xf32>, tensor<2x2xf32>) {
99-
// CHECK: %[[MULF:.*]] = arith.mulf %arg0, %arg1 : tensor<2x2xf32>
100-
// CHECK128: %[[MULF:.*]] = arith.mulf %arg0, %arg1 : tensor<2x2xf32>
101-
// CHECK0: %[[MULF:.*]] = arith.mulf %arg0, %arg1 : tensor<2x2xf32>
93+
// ALL-LABEL: test_tensor_no_linearize
94+
func.func @test_tensor_no_linearize(%arg0: tensor<2x2xf32>, %arg1: tensor<2x2xf32>) -> (tensor<2x2xf32>, tensor<2x2xf32>) {
95+
// ALL: %[[MULF:.*]] = arith.mulf %arg0, %arg1 : tensor<2x2xf32>
10296
%0 = arith.mulf %arg0, %arg1 : tensor<2x2xf32>
10397

10498
return %0, %arg0 : tensor<2x2xf32>, tensor<2x2xf32>

0 commit comments

Comments
 (0)