1212
1313// CHECK-EN-LABEL: func @test_erase
1414// CHECK-EN-SAME: pattern_driver_all_erased = true, pattern_driver_changed = true}
15- // CHECK-EN: test.arg0
16- // CHECK-EN: test.arg1
17- // CHECK-EN-NOT: test.erase_op
15+ // CHECK-EN: " test.arg0"
16+ // CHECK-EN: " test.arg1"
17+ // CHECK-EN-NOT: " test.erase_op"
1818func.func @test_erase () {
1919 %0 = " test.arg0" () : () -> (i32 )
2020 %1 = " test.arg1" () : () -> (i32 )
@@ -51,13 +51,13 @@ func.func @test_replace_with_new_op() {
5151
5252// CHECK-EN-LABEL: func @test_replace_with_erase_op
5353// CHECK-EN-SAME: {pattern_driver_all_erased = true, pattern_driver_changed = true}
54- // CHECK-EN-NOT: test.replace_with_new_op
55- // CHECK-EN-NOT: test.erase_op
54+ // CHECK-EN-NOT: " test.replace_with_new_op"
55+ // CHECK-EN-NOT: " test.erase_op"
5656
5757// CHECK-EX-LABEL: func @test_replace_with_erase_op
5858// CHECK-EX-SAME: {pattern_driver_all_erased = true, pattern_driver_changed = true}
59- // CHECK-EX-NOT: test.replace_with_new_op
60- // CHECK-EX: test.erase_op
59+ // CHECK-EX-NOT: " test.replace_with_new_op"
60+ // CHECK-EX: " test.erase_op"
6161func.func @test_replace_with_erase_op () {
6262 " test.replace_with_new_op" () {create_erase_op } : () -> ()
6363 return
@@ -83,3 +83,149 @@ func.func @test_trigger_rewrite_through_block() {
8383 // in turn, replaces the successor with bb3.
8484 " test.implicit_change_op" () [^bb1 ] : () -> ()
8585}
86+
87+ // -----
88+
89+ // CHECK-AN: notifyOperationRemoved: test.foo_b
90+ // CHECK-AN: notifyOperationRemoved: test.foo_a
91+ // CHECK-AN: notifyOperationRemoved: test.graph_region
92+ // CHECK-AN: notifyOperationRemoved: test.erase_op
93+ // CHECK-AN-LABEL: func @test_remove_graph_region()
94+ // CHECK-AN-NEXT: return
95+ func.func @test_remove_graph_region () {
96+ " test.erase_op" () ({
97+ test.graph_region {
98+ %0 = " test.foo_a" (%1 ) : (i1 ) -> (i1 )
99+ %1 = " test.foo_b" (%0 ) : (i1 ) -> (i1 )
100+ }
101+ }) : () -> ()
102+ return
103+ }
104+
105+ // -----
106+
107+ // CHECK-AN: notifyOperationRemoved: cf.br
108+ // CHECK-AN: notifyOperationRemoved: test.bar
109+ // CHECK-AN: notifyOperationRemoved: cf.br
110+ // CHECK-AN: notifyOperationRemoved: test.foo
111+ // CHECK-AN: notifyOperationRemoved: cf.br
112+ // CHECK-AN: notifyOperationRemoved: test.dummy_op
113+ // CHECK-AN: notifyOperationRemoved: test.erase_op
114+ // CHECK-AN-LABEL: func @test_remove_cyclic_blocks()
115+ // CHECK-AN-NEXT: return
116+ func.func @test_remove_cyclic_blocks () {
117+ " test.erase_op" () ({
118+ %x = " test.dummy_op" () : () -> (i1 )
119+ cf.br ^bb1 (%x: i1 )
120+ ^bb1 (%arg0: i1 ):
121+ " test.foo" (%x ) : (i1 ) -> ()
122+ cf.br ^bb2 (%arg0: i1 )
123+ ^bb2 (%arg1: i1 ):
124+ " test.bar" (%x ) : (i1 ) -> ()
125+ cf.br ^bb1 (%arg1: i1 )
126+ }) : () -> ()
127+ return
128+ }
129+
130+ // -----
131+
132+ // CHECK-AN: notifyOperationRemoved: test.dummy_op
133+ // CHECK-AN: notifyOperationRemoved: test.bar
134+ // CHECK-AN: notifyOperationRemoved: test.qux
135+ // CHECK-AN: notifyOperationRemoved: test.qux_unreachable
136+ // CHECK-AN: notifyOperationRemoved: test.nested_dummy
137+ // CHECK-AN: notifyOperationRemoved: cf.br
138+ // CHECK-AN: notifyOperationRemoved: test.foo
139+ // CHECK-AN: notifyOperationRemoved: test.erase_op
140+ // CHECK-AN-LABEL: func @test_remove_dead_blocks()
141+ // CHECK-AN-NEXT: return
142+ func.func @test_remove_dead_blocks () {
143+ " test.erase_op" () ({
144+ " test.dummy_op" () : () -> (i1 )
145+ // The following blocks are not reachable. Still, ^bb2 should be deleted
146+ // befire ^bb1.
147+ ^bb1 (%arg0: i1 ):
148+ " test.foo" () : () -> ()
149+ cf.br ^bb2 (%arg0: i1 )
150+ ^bb2 (%arg1: i1 ):
151+ " test.nested_dummy" () ({
152+ " test.qux" () : () -> ()
153+ // The following block is unreachable.
154+ ^bb3 :
155+ " test.qux_unreachable" () : () -> ()
156+ }) : () -> ()
157+ " test.bar" () : () -> ()
158+ }) : () -> ()
159+ return
160+ }
161+
162+ // -----
163+
164+ // test.nested_* must be deleted before test.foo.
165+ // test.bar must be deleted before test.foo.
166+
167+ // CHECK-AN: notifyOperationRemoved: cf.br
168+ // CHECK-AN: notifyOperationRemoved: test.bar
169+ // CHECK-AN: notifyOperationRemoved: cf.br
170+ // CHECK-AN: notifyOperationRemoved: test.nested_b
171+ // CHECK-AN: notifyOperationRemoved: test.nested_a
172+ // CHECK-AN: notifyOperationRemoved: test.nested_d
173+ // CHECK-AN: notifyOperationRemoved: cf.br
174+ // CHECK-AN: notifyOperationRemoved: test.nested_e
175+ // CHECK-AN: notifyOperationRemoved: cf.br
176+ // CHECK-AN: notifyOperationRemoved: test.nested_c
177+ // CHECK-AN: notifyOperationRemoved: test.foo
178+ // CHECK-AN: notifyOperationRemoved: cf.br
179+ // CHECK-AN: notifyOperationRemoved: test.dummy_op
180+ // CHECK-AN: notifyOperationRemoved: test.erase_op
181+ // CHECK-AN-LABEL: func @test_remove_nested_ops()
182+ // CHECK-AN-NEXT: return
183+ func.func @test_remove_nested_ops () {
184+ " test.erase_op" () ({
185+ %x = " test.dummy_op" () : () -> (i1 )
186+ cf.br ^bb1 (%x: i1 )
187+ ^bb1 (%arg0: i1 ):
188+ " test.foo" () ({
189+ " test.nested_a" () : () -> ()
190+ " test.nested_b" () : () -> ()
191+ ^dead1 :
192+ " test.nested_c" () : () -> ()
193+ cf.br ^dead3
194+ ^dead2 :
195+ " test.nested_d" () : () -> ()
196+ ^dead3 :
197+ " test.nested_e" () : () -> ()
198+ cf.br ^dead2
199+ }) : () -> ()
200+ cf.br ^bb2 (%arg0: i1 )
201+ ^bb2 (%arg1: i1 ):
202+ " test.bar" (%x ) : (i1 ) -> ()
203+ cf.br ^bb1 (%arg1: i1 )
204+ }) : () -> ()
205+ return
206+ }
207+
208+ // -----
209+
210+ // CHECK-AN: notifyOperationRemoved: test.qux
211+ // CHECK-AN: notifyOperationRemoved: cf.br
212+ // CHECK-AN: notifyOperationRemoved: test.foo
213+ // CHECK-AN: notifyOperationRemoved: cf.br
214+ // CHECK-AN: notifyOperationRemoved: test.bar
215+ // CHECK-AN: notifyOperationRemoved: cf.cond_br
216+ // CHECK-AN-LABEL: func @test_remove_diamond(
217+ // CHECK-AN-NEXT: return
218+ func.func @test_remove_diamond (%c: i1 ) {
219+ " test.erase_op" () ({
220+ cf.cond_br %c , ^bb1 , ^bb2
221+ ^bb1 :
222+ " test.foo" () : () -> ()
223+ cf.br ^bb3
224+ ^bb2 :
225+ " test.bar" () : () -> ()
226+ cf.br ^bb3
227+ ^bb3 :
228+ " test.qux" () : () -> ()
229+ }) : () -> ()
230+ return
231+ }
0 commit comments