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
5
2
6
3
// CHECK-LABEL: @simple_constant
7
4
func.func @simple_constant () -> (i32 , i32 ) {
@@ -13,6 +10,11 @@ func.func @simple_constant() -> (i32, i32) {
13
10
return %0 , %1 : i32 , i32
14
11
}
15
12
13
+ // -----
14
+
15
+ // CHECK: #[[$MAP:.*]] = affine_map<(d0) -> (d0 mod 2)>
16
+ #map0 = affine_map <(d0 ) -> (d0 mod 2 )>
17
+
16
18
// CHECK-LABEL: @basic
17
19
func.func @basic () -> (index , index ) {
18
20
// CHECK: %[[VAR_c0:[0-9a-zA-Z_]+]] = arith.constant 0 : index
@@ -27,6 +29,8 @@ func.func @basic() -> (index, index) {
27
29
return %0 , %1 : index , index
28
30
}
29
31
32
+ // -----
33
+
30
34
// CHECK-LABEL: @many
31
35
func.func @many (f32 , f32 ) -> (f32 ) {
32
36
^bb0 (%a : f32 , %b : f32 ):
@@ -52,6 +56,8 @@ func.func @many(f32, f32) -> (f32) {
52
56
return %l : f32
53
57
}
54
58
59
+ // -----
60
+
55
61
/// Check that operations are not eliminated if they have different operands.
56
62
// CHECK-LABEL: @different_ops
57
63
func.func @different_ops () -> (i32 , i32 ) {
@@ -64,6 +70,8 @@ func.func @different_ops() -> (i32, i32) {
64
70
return %0 , %1 : i32 , i32
65
71
}
66
72
73
+ // -----
74
+
67
75
/// Check that operations are not eliminated if they have different result
68
76
/// types.
69
77
// CHECK-LABEL: @different_results
@@ -77,6 +85,8 @@ func.func @different_results(%arg0: tensor<*xf32>) -> (tensor<?x?xf32>, tensor<4
77
85
return %0 , %1 : tensor <?x?xf32 >, tensor <4 x?xf32 >
78
86
}
79
87
88
+ // -----
89
+
80
90
/// Check that operations are not eliminated if they have different attributes.
81
91
// CHECK-LABEL: @different_attributes
82
92
func.func @different_attributes (index , index ) -> (i1 , i1 , i1 ) {
@@ -93,6 +103,8 @@ func.func @different_attributes(index, index) -> (i1, i1, i1) {
93
103
return %0 , %1 , %2 : i1 , i1 , i1
94
104
}
95
105
106
+ // -----
107
+
96
108
/// Check that operations with side effects are not eliminated.
97
109
// CHECK-LABEL: @side_effect
98
110
func.func @side_effect () -> (memref <2 x1 xf32 >, memref <2 x1 xf32 >) {
@@ -106,6 +118,8 @@ func.func @side_effect() -> (memref<2x1xf32>, memref<2x1xf32>) {
106
118
return %0 , %1 : memref <2 x1 xf32 >, memref <2 x1 xf32 >
107
119
}
108
120
121
+ // -----
122
+
109
123
/// Check that operation definitions are properly propagated down the dominance
110
124
/// tree.
111
125
// CHECK-LABEL: @down_propagate_for
@@ -122,6 +136,8 @@ func.func @down_propagate_for() {
122
136
return
123
137
}
124
138
139
+ // -----
140
+
125
141
// CHECK-LABEL: @down_propagate
126
142
func.func @down_propagate () -> i32 {
127
143
// CHECK-NEXT: %[[VAR_c1_i32:[0-9a-zA-Z_]+]] = arith.constant 1 : i32
@@ -142,6 +158,8 @@ func.func @down_propagate() -> i32 {
142
158
return %arg : i32
143
159
}
144
160
161
+ // -----
162
+
145
163
/// Check that operation definitions are NOT propagated up the dominance tree.
146
164
// CHECK-LABEL: @up_propagate_for
147
165
func.func @up_propagate_for () -> i32 {
@@ -159,6 +177,8 @@ func.func @up_propagate_for() -> i32 {
159
177
return %1 : i32
160
178
}
161
179
180
+ // -----
181
+
162
182
// CHECK-LABEL: func @up_propagate
163
183
func.func @up_propagate () -> i32 {
164
184
// CHECK-NEXT: %[[VAR_c0_i32:[0-9a-zA-Z_]+]] = arith.constant 0 : i32
@@ -188,6 +208,8 @@ func.func @up_propagate() -> i32 {
188
208
return %add : i32
189
209
}
190
210
211
+ // -----
212
+
191
213
/// The same test as above except that we are testing on a cfg embedded within
192
214
/// an operation region.
193
215
// CHECK-LABEL: func @up_propagate_region
@@ -221,6 +243,8 @@ func.func @up_propagate_region() -> i32 {
221
243
return %0 : i32
222
244
}
223
245
246
+ // -----
247
+
224
248
/// This test checks that nested regions that are isolated from above are
225
249
/// properly handled.
226
250
// CHECK-LABEL: @nested_isolated
@@ -248,6 +272,8 @@ func.func @nested_isolated() -> i32 {
248
272
return %0 : i32
249
273
}
250
274
275
+ // -----
276
+
251
277
/// This test is checking that CSE gracefully handles values in graph regions
252
278
/// where the use occurs before the def, and one of the defs could be CSE'd with
253
279
/// the other.
@@ -269,6 +295,8 @@ func.func @use_before_def() {
269
295
return
270
296
}
271
297
298
+ // -----
299
+
272
300
/// This test is checking that CSE is removing duplicated read op that follow
273
301
/// other.
274
302
// CHECK-LABEL: @remove_direct_duplicated_read_op
@@ -281,6 +309,8 @@ func.func @remove_direct_duplicated_read_op() -> i32 {
281
309
return %2 : i32
282
310
}
283
311
312
+ // -----
313
+
284
314
/// This test is checking that CSE is removing duplicated read op that follow
285
315
/// other.
286
316
// CHECK-LABEL: @remove_multiple_duplicated_read_op
@@ -300,6 +330,8 @@ func.func @remove_multiple_duplicated_read_op() -> i64 {
300
330
return %6 : i64
301
331
}
302
332
333
+ // -----
334
+
303
335
/// This test is checking that CSE is not removing duplicated read op that
304
336
/// have write op in between.
305
337
// CHECK-LABEL: @dont_remove_duplicated_read_op_with_sideeffecting
@@ -314,6 +346,8 @@ func.func @dont_remove_duplicated_read_op_with_sideeffecting() -> i32 {
314
346
return %2 : i32
315
347
}
316
348
349
+ // -----
350
+
317
351
// Check that an operation with a single region can CSE.
318
352
func.func @cse_single_block_ops (%a : tensor <?x?xf32 >, %b : tensor <?x?xf32 >)
319
353
-> (tensor <?x?xf32 >, tensor <?x?xf32 >) {
@@ -332,6 +366,8 @@ func.func @cse_single_block_ops(%a : tensor<?x?xf32>, %b : tensor<?x?xf32>)
332
366
// CHECK-NOT: test.cse_of_single_block_op
333
367
// CHECK: return %[[OP]], %[[OP]]
334
368
369
+ // -----
370
+
335
371
// Operations with different number of bbArgs dont CSE.
336
372
func.func @no_cse_varied_bbargs (%a : tensor <?x?xf32 >, %b : tensor <?x?xf32 >)
337
373
-> (tensor <?x?xf32 >, tensor <?x?xf32 >) {
@@ -350,6 +386,8 @@ func.func @no_cse_varied_bbargs(%a : tensor<?x?xf32>, %b : tensor<?x?xf32>)
350
386
// CHECK: %[[OP1:.+]] = test.cse_of_single_block_op
351
387
// CHECK: return %[[OP0]], %[[OP1]]
352
388
389
+ // -----
390
+
353
391
// Operations with different regions dont CSE
354
392
func.func @no_cse_region_difference_simple (%a : tensor <?x?xf32 >, %b : tensor <?x?xf32 >)
355
393
-> (tensor <?x?xf32 >, tensor <?x?xf32 >) {
@@ -368,6 +406,8 @@ func.func @no_cse_region_difference_simple(%a : tensor<?x?xf32>, %b : tensor<?x?
368
406
// CHECK: %[[OP1:.+]] = test.cse_of_single_block_op
369
407
// CHECK: return %[[OP0]], %[[OP1]]
370
408
409
+ // -----
410
+
371
411
// Operation with identical region with multiple statements CSE.
372
412
func.func @cse_single_block_ops_identical_bodies (%a : tensor <?x?xf32 >, %b : tensor <?x?xf32 >, %c : f32 , %d : i1 )
373
413
-> (tensor <?x?xf32 >, tensor <?x?xf32 >) {
@@ -392,6 +432,8 @@ func.func @cse_single_block_ops_identical_bodies(%a : tensor<?x?xf32>, %b : tens
392
432
// CHECK-NOT: test.cse_of_single_block_op
393
433
// CHECK: return %[[OP]], %[[OP]]
394
434
435
+ // -----
436
+
395
437
// Operation with non-identical regions dont CSE.
396
438
func.func @no_cse_single_block_ops_different_bodies (%a : tensor <?x?xf32 >, %b : tensor <?x?xf32 >, %c : f32 , %d : i1 )
397
439
-> (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
416
458
// CHECK: %[[OP1:.+]] = test.cse_of_single_block_op
417
459
// CHECK: return %[[OP0]], %[[OP1]]
418
460
461
+ // -----
462
+
419
463
func.func @failing_issue_59135 (%arg0: tensor <2 x2 xi1 >, %arg1: f32 , %arg2 : tensor <2 xi1 >) -> (tensor <2 xi1 >, tensor <2 xi1 >) {
420
464
%false_2 = arith.constant false
421
465
%true_5 = arith.constant true
@@ -438,6 +482,8 @@ func.func @failing_issue_59135(%arg0: tensor<2x2xi1>, %arg1: f32, %arg2 : tensor
438
482
// CHECK: test.region_yield %[[TRUE]]
439
483
// CHECK: return %[[OP]], %[[OP]]
440
484
485
+ // -----
486
+
441
487
func.func @cse_multiple_regions (%c: i1 , %t: tensor <5 xf32 >) -> (tensor <5 xf32 >, tensor <5 xf32 >) {
442
488
%r1 = scf.if %c -> (tensor <5 xf32 >) {
443
489
%0 = tensor.empty () : tensor <5 xf32 >
@@ -463,6 +509,8 @@ func.func @cse_multiple_regions(%c: i1, %t: tensor<5xf32>) -> (tensor<5xf32>, te
463
509
// CHECK-NOT: scf.if
464
510
// CHECK: return %[[if]], %[[if]]
465
511
512
+ // -----
513
+
466
514
// CHECK-LABEL: @cse_recursive_effects_success
467
515
func.func @cse_recursive_effects_success () -> (i32 , i32 , i32 ) {
468
516
// CHECK-NEXT: %[[READ_VALUE:.*]] = "test.op_with_memread"() : () -> i32
@@ -492,6 +540,8 @@ func.func @cse_recursive_effects_success() -> (i32, i32, i32) {
492
540
return %0 , %2 , %1 : i32 , i32 , i32
493
541
}
494
542
543
+ // -----
544
+
495
545
// CHECK-LABEL: @cse_recursive_effects_failure
496
546
func.func @cse_recursive_effects_failure () -> (i32 , i32 , i32 ) {
497
547
// CHECK-NEXT: %[[READ_VALUE:.*]] = "test.op_with_memread"() : () -> i32
0 commit comments