1 // RUN: mlir-opt %s --test-walk-pattern-rewrite-driver="dump-notifications=true" \
2 // RUN: --allow-unregistered-dialect --split-input-file | FileCheck %s
4 // The following op is updated in-place and will not be added back to the worklist.
5 // CHECK-LABEL: func.func @inplace_update()
6 // CHECK: "test.any_attr_of_i32_str"() <{attr = 1 : i32}> : () -> ()
7 // CHECK: "test.any_attr_of_i32_str"() <{attr = 2 : i32}> : () -> ()
8 func.func @inplace_update() {
9 "test.any_attr_of_i32_str"() {attr = 0 : i32} : () -> ()
10 "test.any_attr_of_i32_str"() {attr = 1 : i32} : () -> ()
14 // Check that the driver does not fold visited ops.
15 // CHECK-LABEL: func.func @add_no_fold()
16 // CHECK: arith.constant
17 // CHECK: arith.constant
18 // CHECK: %[[RES:.+]] = arith.addi
19 // CHECK: return %[[RES]]
20 func.func @add_no_fold() -> i32 {
21 %c0 = arith.constant 0 : i32
22 %c1 = arith.constant 1 : i32
23 %res = arith.addi %c0, %c1 : i32
27 // Check that the driver handles rewriter.moveBefore.
28 // CHECK-LABEL: func.func @move_before(
29 // CHECK: "test.move_before_parent_op"
30 // CHECK: "test.any_attr_of_i32_str"() <{attr = 1 : i32}> : () -> ()
33 func.func @move_before(%cond : i1) {
35 "test.move_before_parent_op"() ({
36 "test.any_attr_of_i32_str"() {attr = 0 : i32} : () -> ()
42 // Check that the driver handles rewriter.moveAfter. In this case, we expect
43 // the moved op to be visited only once since walk uses `make_early_inc_range`.
44 // CHECK-LABEL: func.func @move_after(
47 // CHECK: "test.move_after_parent_op"
48 // CHECK: "test.any_attr_of_i32_str"() <{attr = 1 : i32}> : () -> ()
50 func.func @move_after(%cond : i1) {
52 "test.move_after_parent_op"() ({
53 "test.any_attr_of_i32_str"() {attr = 0 : i32} : () -> ()
59 // Check that the driver handles rewriter.moveAfter. In this case, we expect
60 // the moved op to be visited twice since we advance its position to the next
61 // node after the parent.
62 // CHECK-LABEL: func.func @move_forward_and_revisit(
66 // CHECK: "test.move_after_parent_op"
67 // CHECK: "test.any_attr_of_i32_str"() <{attr = 2 : i32}> : () -> ()
70 func.func @move_forward_and_revisit(%cond : i1) {
72 "test.move_after_parent_op"() ({
73 "test.any_attr_of_i32_str"() {attr = 0 : i32} : () -> ()
74 }) {advance = 1 : i32} : () -> ()
76 %a = arith.addi %cond, %cond : i1
77 %b = arith.addi %a, %cond : i1
81 // Operation inserted just after the currently visited one won't be visited.
82 // CHECK-LABEL: func.func @insert_just_after
83 // CHECK: "test.clone_me"() ({
84 // CHECK: "test.any_attr_of_i32_str"() <{attr = 1 : i32}> : () -> ()
85 // CHECK: }) {was_cloned} : () -> ()
86 // CHECK: "test.clone_me"() ({
87 // CHECK: "test.any_attr_of_i32_str"() <{attr = 1 : i32}> : () -> ()
88 // CHECK: }) : () -> ()
90 func.func @insert_just_after(%cond : i1) {
92 "test.any_attr_of_i32_str"() {attr = 0 : i32} : () -> ()
97 // Check that we can replace the current operation with a new one.
98 // Note that the new op won't be visited.
99 // CHECK-LABEL: func.func @replace_with_new_op
100 // CHECK: %[[NEW:.+]] = "test.new_op"
101 // CHECK: %[[RES:.+]] = arith.addi %[[NEW]], %[[NEW]]
102 // CHECK: return %[[RES]]
103 func.func @replace_with_new_op() -> i32 {
104 %a = "test.replace_with_new_op"() : () -> (i32)
105 %res = arith.addi %a, %a : i32
109 // Check that we can erase nested blocks.
110 // CHECK-LABEL: func.func @erase_nested_block
111 // CHECK: %[[RES:.+]] = "test.erase_first_block"
112 // CHECK-NEXT: foo.bar
113 // CHECK: return %[[RES]]
114 func.func @erase_nested_block() -> i32 {
115 %a = "test.erase_first_block"() ({
116 "foo.foo"() : () -> ()
118 "foo.bar"() : () -> ()