Skip to content

Commit c315c01

Browse files
[mlir][Transforms][NFC] CSE: Split tests and fix typo (#115680)
Add `-split-input-file` to CSE tests and fix a typo in `Passes.h`. (The typo is harmless as long as the pass has no options.)
1 parent a7b249e commit c315c01

File tree

2 files changed

+55
-5
lines changed

2 files changed

+55
-5
lines changed

mlir/include/mlir/Transforms/Passes.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class GreedyRewriteConfig;
3333

3434
#define GEN_PASS_DECL_CANONICALIZER
3535
#define GEN_PASS_DECL_CONTROLFLOWSINK
36-
#define GEN_PASS_DECL_CSEPASS
36+
#define GEN_PASS_DECL_CSE
3737
#define GEN_PASS_DECL_INLINER
3838
#define GEN_PASS_DECL_LOOPINVARIANTCODEMOTION
3939
#define GEN_PASS_DECL_MEM2REG

mlir/test/Transforms/cse.mlir

Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
// RUN: mlir-opt -allow-unregistered-dialect %s -pass-pipeline='builtin.module(func.func(cse))' | FileCheck %s
2-
3-
// CHECK-DAG: #[[$MAP:.*]] = affine_map<(d0) -> (d0 mod 2)>
4-
#map0 = affine_map<(d0) -> (d0 mod 2)>
1+
// RUN: mlir-opt -allow-unregistered-dialect %s -pass-pipeline='builtin.module(func.func(cse))' -split-input-file | FileCheck %s
52

63
// CHECK-LABEL: @simple_constant
74
func.func @simple_constant() -> (i32, i32) {
@@ -13,6 +10,11 @@ func.func @simple_constant() -> (i32, i32) {
1310
return %0, %1 : i32, i32
1411
}
1512

13+
// -----
14+
15+
// CHECK: #[[$MAP:.*]] = affine_map<(d0) -> (d0 mod 2)>
16+
#map0 = affine_map<(d0) -> (d0 mod 2)>
17+
1618
// CHECK-LABEL: @basic
1719
func.func @basic() -> (index, index) {
1820
// CHECK: %[[VAR_c0:[0-9a-zA-Z_]+]] = arith.constant 0 : index
@@ -27,6 +29,8 @@ func.func @basic() -> (index, index) {
2729
return %0, %1 : index, index
2830
}
2931

32+
// -----
33+
3034
// CHECK-LABEL: @many
3135
func.func @many(f32, f32) -> (f32) {
3236
^bb0(%a : f32, %b : f32):
@@ -52,6 +56,8 @@ func.func @many(f32, f32) -> (f32) {
5256
return %l : f32
5357
}
5458

59+
// -----
60+
5561
/// Check that operations are not eliminated if they have different operands.
5662
// CHECK-LABEL: @different_ops
5763
func.func @different_ops() -> (i32, i32) {
@@ -64,6 +70,8 @@ func.func @different_ops() -> (i32, i32) {
6470
return %0, %1 : i32, i32
6571
}
6672

73+
// -----
74+
6775
/// Check that operations are not eliminated if they have different result
6876
/// types.
6977
// CHECK-LABEL: @different_results
@@ -77,6 +85,8 @@ func.func @different_results(%arg0: tensor<*xf32>) -> (tensor<?x?xf32>, tensor<4
7785
return %0, %1 : tensor<?x?xf32>, tensor<4x?xf32>
7886
}
7987

88+
// -----
89+
8090
/// Check that operations are not eliminated if they have different attributes.
8191
// CHECK-LABEL: @different_attributes
8292
func.func @different_attributes(index, index) -> (i1, i1, i1) {
@@ -93,6 +103,8 @@ func.func @different_attributes(index, index) -> (i1, i1, i1) {
93103
return %0, %1, %2 : i1, i1, i1
94104
}
95105

106+
// -----
107+
96108
/// Check that operations with side effects are not eliminated.
97109
// CHECK-LABEL: @side_effect
98110
func.func @side_effect() -> (memref<2x1xf32>, memref<2x1xf32>) {
@@ -106,6 +118,8 @@ func.func @side_effect() -> (memref<2x1xf32>, memref<2x1xf32>) {
106118
return %0, %1 : memref<2x1xf32>, memref<2x1xf32>
107119
}
108120

121+
// -----
122+
109123
/// Check that operation definitions are properly propagated down the dominance
110124
/// tree.
111125
// CHECK-LABEL: @down_propagate_for
@@ -122,6 +136,8 @@ func.func @down_propagate_for() {
122136
return
123137
}
124138

139+
// -----
140+
125141
// CHECK-LABEL: @down_propagate
126142
func.func @down_propagate() -> i32 {
127143
// CHECK-NEXT: %[[VAR_c1_i32:[0-9a-zA-Z_]+]] = arith.constant 1 : i32
@@ -142,6 +158,8 @@ func.func @down_propagate() -> i32 {
142158
return %arg : i32
143159
}
144160

161+
// -----
162+
145163
/// Check that operation definitions are NOT propagated up the dominance tree.
146164
// CHECK-LABEL: @up_propagate_for
147165
func.func @up_propagate_for() -> i32 {
@@ -159,6 +177,8 @@ func.func @up_propagate_for() -> i32 {
159177
return %1 : i32
160178
}
161179

180+
// -----
181+
162182
// CHECK-LABEL: func @up_propagate
163183
func.func @up_propagate() -> i32 {
164184
// CHECK-NEXT: %[[VAR_c0_i32:[0-9a-zA-Z_]+]] = arith.constant 0 : i32
@@ -188,6 +208,8 @@ func.func @up_propagate() -> i32 {
188208
return %add : i32
189209
}
190210

211+
// -----
212+
191213
/// The same test as above except that we are testing on a cfg embedded within
192214
/// an operation region.
193215
// CHECK-LABEL: func @up_propagate_region
@@ -221,6 +243,8 @@ func.func @up_propagate_region() -> i32 {
221243
return %0 : i32
222244
}
223245

246+
// -----
247+
224248
/// This test checks that nested regions that are isolated from above are
225249
/// properly handled.
226250
// CHECK-LABEL: @nested_isolated
@@ -248,6 +272,8 @@ func.func @nested_isolated() -> i32 {
248272
return %0 : i32
249273
}
250274

275+
// -----
276+
251277
/// This test is checking that CSE gracefully handles values in graph regions
252278
/// where the use occurs before the def, and one of the defs could be CSE'd with
253279
/// the other.
@@ -269,6 +295,8 @@ func.func @use_before_def() {
269295
return
270296
}
271297

298+
// -----
299+
272300
/// This test is checking that CSE is removing duplicated read op that follow
273301
/// other.
274302
// CHECK-LABEL: @remove_direct_duplicated_read_op
@@ -281,6 +309,8 @@ func.func @remove_direct_duplicated_read_op() -> i32 {
281309
return %2 : i32
282310
}
283311

312+
// -----
313+
284314
/// This test is checking that CSE is removing duplicated read op that follow
285315
/// other.
286316
// CHECK-LABEL: @remove_multiple_duplicated_read_op
@@ -300,6 +330,8 @@ func.func @remove_multiple_duplicated_read_op() -> i64 {
300330
return %6 : i64
301331
}
302332

333+
// -----
334+
303335
/// This test is checking that CSE is not removing duplicated read op that
304336
/// have write op in between.
305337
// CHECK-LABEL: @dont_remove_duplicated_read_op_with_sideeffecting
@@ -314,6 +346,8 @@ func.func @dont_remove_duplicated_read_op_with_sideeffecting() -> i32 {
314346
return %2 : i32
315347
}
316348

349+
// -----
350+
317351
// Check that an operation with a single region can CSE.
318352
func.func @cse_single_block_ops(%a : tensor<?x?xf32>, %b : tensor<?x?xf32>)
319353
-> (tensor<?x?xf32>, tensor<?x?xf32>) {
@@ -332,6 +366,8 @@ func.func @cse_single_block_ops(%a : tensor<?x?xf32>, %b : tensor<?x?xf32>)
332366
// CHECK-NOT: test.cse_of_single_block_op
333367
// CHECK: return %[[OP]], %[[OP]]
334368

369+
// -----
370+
335371
// Operations with different number of bbArgs dont CSE.
336372
func.func @no_cse_varied_bbargs(%a : tensor<?x?xf32>, %b : tensor<?x?xf32>)
337373
-> (tensor<?x?xf32>, tensor<?x?xf32>) {
@@ -350,6 +386,8 @@ func.func @no_cse_varied_bbargs(%a : tensor<?x?xf32>, %b : tensor<?x?xf32>)
350386
// CHECK: %[[OP1:.+]] = test.cse_of_single_block_op
351387
// CHECK: return %[[OP0]], %[[OP1]]
352388

389+
// -----
390+
353391
// Operations with different regions dont CSE
354392
func.func @no_cse_region_difference_simple(%a : tensor<?x?xf32>, %b : tensor<?x?xf32>)
355393
-> (tensor<?x?xf32>, tensor<?x?xf32>) {
@@ -368,6 +406,8 @@ func.func @no_cse_region_difference_simple(%a : tensor<?x?xf32>, %b : tensor<?x?
368406
// CHECK: %[[OP1:.+]] = test.cse_of_single_block_op
369407
// CHECK: return %[[OP0]], %[[OP1]]
370408

409+
// -----
410+
371411
// Operation with identical region with multiple statements CSE.
372412
func.func @cse_single_block_ops_identical_bodies(%a : tensor<?x?xf32>, %b : tensor<?x?xf32>, %c : f32, %d : i1)
373413
-> (tensor<?x?xf32>, tensor<?x?xf32>) {
@@ -392,6 +432,8 @@ func.func @cse_single_block_ops_identical_bodies(%a : tensor<?x?xf32>, %b : tens
392432
// CHECK-NOT: test.cse_of_single_block_op
393433
// CHECK: return %[[OP]], %[[OP]]
394434

435+
// -----
436+
395437
// Operation with non-identical regions dont CSE.
396438
func.func @no_cse_single_block_ops_different_bodies(%a : tensor<?x?xf32>, %b : tensor<?x?xf32>, %c : f32, %d : i1)
397439
-> (tensor<?x?xf32>, tensor<?x?xf32>) {
@@ -416,6 +458,8 @@ func.func @no_cse_single_block_ops_different_bodies(%a : tensor<?x?xf32>, %b : t
416458
// CHECK: %[[OP1:.+]] = test.cse_of_single_block_op
417459
// CHECK: return %[[OP0]], %[[OP1]]
418460

461+
// -----
462+
419463
func.func @failing_issue_59135(%arg0: tensor<2x2xi1>, %arg1: f32, %arg2 : tensor<2xi1>) -> (tensor<2xi1>, tensor<2xi1>) {
420464
%false_2 = arith.constant false
421465
%true_5 = arith.constant true
@@ -438,6 +482,8 @@ func.func @failing_issue_59135(%arg0: tensor<2x2xi1>, %arg1: f32, %arg2 : tensor
438482
// CHECK: test.region_yield %[[TRUE]]
439483
// CHECK: return %[[OP]], %[[OP]]
440484

485+
// -----
486+
441487
func.func @cse_multiple_regions(%c: i1, %t: tensor<5xf32>) -> (tensor<5xf32>, tensor<5xf32>) {
442488
%r1 = scf.if %c -> (tensor<5xf32>) {
443489
%0 = tensor.empty() : tensor<5xf32>
@@ -463,6 +509,8 @@ func.func @cse_multiple_regions(%c: i1, %t: tensor<5xf32>) -> (tensor<5xf32>, te
463509
// CHECK-NOT: scf.if
464510
// CHECK: return %[[if]], %[[if]]
465511

512+
// -----
513+
466514
// CHECK-LABEL: @cse_recursive_effects_success
467515
func.func @cse_recursive_effects_success() -> (i32, i32, i32) {
468516
// CHECK-NEXT: %[[READ_VALUE:.*]] = "test.op_with_memread"() : () -> i32
@@ -492,6 +540,8 @@ func.func @cse_recursive_effects_success() -> (i32, i32, i32) {
492540
return %0, %2, %1 : i32, i32, i32
493541
}
494542

543+
// -----
544+
495545
// CHECK-LABEL: @cse_recursive_effects_failure
496546
func.func @cse_recursive_effects_failure() -> (i32, i32, i32) {
497547
// CHECK-NEXT: %[[READ_VALUE:.*]] = "test.op_with_memread"() : () -> i32

0 commit comments

Comments
 (0)