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
74func.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
1719func.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
3135func.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
5763func.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 <4 x?xf32 >
7886}
7987
88+ // -----
89+
8090/// Check that operations are not eliminated if they have different attributes.
8191// CHECK-LABEL: @different_attributes
8292func.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
98110func.func @side_effect () -> (memref <2 x1 xf32 >, memref <2 x1 xf32 >) {
@@ -106,6 +118,8 @@ func.func @side_effect() -> (memref<2x1xf32>, memref<2x1xf32>) {
106118 return %0 , %1 : memref <2 x1 xf32 >, memref <2 x1 xf32 >
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
126142func.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
147165func.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
163183func.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.
318352func.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.
336372func.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
354392func.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.
372412func.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.
396438func.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+
419463func.func @failing_issue_59135 (%arg0: tensor <2 x2 xi1 >, %arg1: f32 , %arg2 : tensor <2 xi1 >) -> (tensor <2 xi1 >, tensor <2 xi1 >) {
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+
441487func.func @cse_multiple_regions (%c: i1 , %t: tensor <5 xf32 >) -> (tensor <5 xf32 >, tensor <5 xf32 >) {
442488 %r1 = scf.if %c -> (tensor <5 xf32 >) {
443489 %0 = tensor.empty () : tensor <5 xf32 >
@@ -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
467515func.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
496546func.func @cse_recursive_effects_failure () -> (i32 , i32 , i32 ) {
497547 // CHECK-NEXT: %[[READ_VALUE:.*]] = "test.op_with_memread"() : () -> i32
0 commit comments