1
1
// RUN: mlir-opt -test-greedy-patterns='top-down=false' %s | FileCheck %s
2
2
// RUN: mlir-opt -test-greedy-patterns='top-down=true' %s | FileCheck %s
3
+ // RUN: mlir-opt -test-greedy-patterns='cse-constants=false' %s | FileCheck %s --check-prefix=NOCSE
4
+ // RUN: mlir-opt -test-greedy-patterns='fold=false' %s | FileCheck %s --check-prefix=NOFOLD
3
5
4
6
func.func @foo () -> i32 {
5
7
%c42 = arith.constant 42 : i32
@@ -25,7 +27,8 @@ func.func @test_fold_before_previously_folded_op() -> (i32, i32) {
25
27
}
26
28
27
29
func.func @test_dont_reorder_constants () -> (i32 , i32 , i32 ) {
28
- // Test that we don't reorder existing constants during folding if it isn't necessary.
30
+ // Test that we don't reorder existing constants during folding if it isn't
31
+ // necessary.
29
32
// CHECK: %[[CST:.+]] = arith.constant 1
30
33
// CHECK-NEXT: %[[CST:.+]] = arith.constant 2
31
34
// CHECK-NEXT: %[[CST:.+]] = arith.constant 3
@@ -34,3 +37,37 @@ func.func @test_dont_reorder_constants() -> (i32, i32, i32) {
34
37
%2 = arith.constant 3 : i32
35
38
return %0 , %1 , %2 : i32 , i32 , i32
36
39
}
40
+
41
+ func.func @test_dont_fold () -> (i32 , i32 , i32 , i32 , i32 , i32 ) {
42
+ // Test either not folding or deduping constants.
43
+
44
+ // CHECK-LABEL: test_dont_fold
45
+ // CHECK-NOT: arith.constant 0
46
+ // CHECK-DAG: %[[CST:.+]] = arith.constant 0
47
+ // CHECK-DAG: %[[CST:.+]] = arith.constant 1
48
+ // CHECK-DAG: %[[CST:.+]] = arith.constant 2
49
+ // CHECK-DAG: %[[CST:.+]] = arith.constant 3
50
+ // CHECK-NEXT: return
51
+
52
+ // NOCSE-LABEL: test_dont_fold
53
+ // NOCSE-DAG: arith.constant 0 : i32
54
+ // NOCSE-DAG: arith.constant 1 : i32
55
+ // NOCSE-DAG: arith.constant 2 : i32
56
+ // NOCSE-DAG: arith.constant 1 : i32
57
+ // NOCSE-DAG: arith.constant 2 : i32
58
+ // NOCSE-DAG: arith.constant 3 : i32
59
+ // NOCSE-NEXT: return
60
+
61
+ // NOFOLD-LABEL: test_dont_fold
62
+ // NOFOLD: arith.addi
63
+ // NOFOLD: arith.addi
64
+ // NOFOLD: arith.addi
65
+
66
+ %c0 = arith.constant 0 : i32
67
+ %c1 = arith.constant 1 : i32
68
+ %c2 = arith.constant 2 : i32
69
+ %0 = arith.addi %c0 , %c1 : i32
70
+ %1 = arith.addi %0 , %c1 : i32
71
+ %2 = arith.addi %c2 , %c1 : i32
72
+ return %0 , %1 , %2 , %c0 , %c1 , %c2 : i32 , i32 , i32 , i32 , i32 , i32
73
+ }
0 commit comments