blob: 4c31789973a70fa3b9738327b6b99b3c776dd4ba [file] [log] [blame]
Dan Gohman8fe7e862015-12-14 22:51:54 +00001; RUN: llc < %s -asm-verbose=false -disable-block-placement -verify-machineinstrs | FileCheck %s
2; RUN: llc < %s -asm-verbose=false -verify-machineinstrs | FileCheck -check-prefix=OPT %s
Dan Gohman950a13c2015-09-16 16:51:30 +00003
4; Test the CFG stackifier pass.
5
Dan Gohman0c6f5ac2016-01-07 03:19:23 +00006target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
Dan Gohman950a13c2015-09-16 16:51:30 +00007target triple = "wasm32-unknown-unknown"
8
9declare void @something()
10
11; Test that loops are made contiguous, even in the presence of split backedges.
12
Dan Gohmane51c0582015-10-06 00:27:55 +000013; CHECK-LABEL: test0:
14; CHECK: loop
Dan Gohmanf0b165a2015-12-05 03:03:35 +000015; CHECK-NOT: br
Dan Gohman8fe7e862015-12-14 22:51:54 +000016; CHECK: i32.add
Dan Gohman442bfce2016-02-16 16:22:41 +000017; CHECK-NEXT: block
18; CHECK-NEXT: i32.lt_s
Dan Gohman8fe7e862015-12-14 22:51:54 +000019; CHECK-NEXT: br_if
Dan Gohman442bfce2016-02-16 16:22:41 +000020; CHECK-NEXT: return
21; CHECK-NEXT: .LBB0_3:
22; CHECK-NEXT: end_block
23; CHECK-NEXT: call
24; CHECK-NEXT: br
25; CHECK-NEXT: .LBB0_4:
26; CHECK-NEXT: end_loop
Dan Gohmanf0b165a2015-12-05 03:03:35 +000027; OPT-LABEL: test0:
28; OPT: loop
Dan Gohmanf0b165a2015-12-05 03:03:35 +000029; OPT-NOT: br
Dan Gohman8fe7e862015-12-14 22:51:54 +000030; OPT: i32.add
31; OPT-NEXT: i32.ge_s
32; OPT-NEXT: br_if
Dan Gohmanf0b165a2015-12-05 03:03:35 +000033; OPT-NOT: br
34; OPT: call
Dan Gohman1d68e80f2016-01-12 19:14:46 +000035; OPT: br 0{{$}}
Dan Gohmanf0b165a2015-12-05 03:03:35 +000036; OPT: return{{$}}
Dan Gohman950a13c2015-09-16 16:51:30 +000037define void @test0(i32 %n) {
38entry:
39 br label %header
40
41header:
42 %i = phi i32 [ 0, %entry ], [ %i.next, %back ]
43 %i.next = add i32 %i, 1
44
45 %c = icmp slt i32 %i.next, %n
46 br i1 %c, label %back, label %exit
47
48exit:
49 ret void
50
51back:
52 call void @something()
53 br label %header
54}
55
56; Same as test0, but the branch condition is reversed.
57
Dan Gohmane51c0582015-10-06 00:27:55 +000058; CHECK-LABEL: test1:
59; CHECK: loop
Dan Gohmanf0b165a2015-12-05 03:03:35 +000060; CHECK-NOT: br
Dan Gohman8fe7e862015-12-14 22:51:54 +000061; CHECK: i32.add
Dan Gohman442bfce2016-02-16 16:22:41 +000062; CHECK-NEXT: block
63; CHECK-NEXT: i32.lt_s
Dan Gohman8fe7e862015-12-14 22:51:54 +000064; CHECK-NEXT: br_if
Dan Gohman442bfce2016-02-16 16:22:41 +000065; CHECK-NEXT: return
66; CHECK-NEXT: .LBB1_3:
67; CHECK-NEXT: end_block
68; CHECK-NEXT: call
69; CHECK-NEXT: br
70; CHECK-NEXT: .LBB1_4:
71; CHECK-NEXT: end_loop
Dan Gohmanf0b165a2015-12-05 03:03:35 +000072; OPT-LABEL: test1:
73; OPT: loop
Dan Gohmanf0b165a2015-12-05 03:03:35 +000074; OPT-NOT: br
Dan Gohman8fe7e862015-12-14 22:51:54 +000075; OPT: i32.add
76; OPT-NEXT: i32.ge_s
77; OPT-NEXT: br_if
Dan Gohmanf0b165a2015-12-05 03:03:35 +000078; OPT-NOT: br
79; OPT: call
Dan Gohman1d68e80f2016-01-12 19:14:46 +000080; OPT: br 0{{$}}
Dan Gohmanf0b165a2015-12-05 03:03:35 +000081; OPT: return{{$}}
Dan Gohman950a13c2015-09-16 16:51:30 +000082define void @test1(i32 %n) {
83entry:
84 br label %header
85
86header:
87 %i = phi i32 [ 0, %entry ], [ %i.next, %back ]
88 %i.next = add i32 %i, 1
89
90 %c = icmp sge i32 %i.next, %n
91 br i1 %c, label %exit, label %back
92
93exit:
94 ret void
95
96back:
97 call void @something()
98 br label %header
99}
100
101; Test that a simple loop is handled as expected.
102
Dan Gohmane51c0582015-10-06 00:27:55 +0000103; CHECK-LABEL: test2:
Dan Gohman8f59cf72016-01-06 18:29:35 +0000104; CHECK-NOT: local
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000105; CHECK: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000106; CHECK: br_if 0, {{[^,]+}}{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000107; CHECK: .LBB2_1:
Dan Gohman06b49582016-02-08 21:50:13 +0000108; CHECK: br_if 0, ${{[0-9]+}}{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000109; CHECK: .LBB2_2:
Dan Gohmane51c0582015-10-06 00:27:55 +0000110; CHECK: return{{$}}
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000111; OPT-LABEL: test2:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000112; OPT-NOT: local
113; OPT: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000114; OPT: br_if 0, {{[^,]+}}{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000115; OPT: .LBB2_1:
Dan Gohman06b49582016-02-08 21:50:13 +0000116; OPT: br_if 0, ${{[0-9]+}}{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000117; OPT: .LBB2_2:
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000118; OPT: return{{$}}
Dan Gohman950a13c2015-09-16 16:51:30 +0000119define void @test2(double* nocapture %p, i32 %n) {
120entry:
121 %cmp.4 = icmp sgt i32 %n, 0
122 br i1 %cmp.4, label %for.body.preheader, label %for.end
123
124for.body.preheader:
125 br label %for.body
126
127for.body:
128 %i.05 = phi i32 [ %inc, %for.body ], [ 0, %for.body.preheader ]
129 %arrayidx = getelementptr inbounds double, double* %p, i32 %i.05
130 %0 = load double, double* %arrayidx, align 8
131 %mul = fmul double %0, 3.200000e+00
132 store double %mul, double* %arrayidx, align 8
133 %inc = add nuw nsw i32 %i.05, 1
134 %exitcond = icmp eq i32 %inc, %n
135 br i1 %exitcond, label %for.end.loopexit, label %for.body
136
137for.end.loopexit:
138 br label %for.end
139
140for.end:
141 ret void
142}
143
Dan Gohmane51c0582015-10-06 00:27:55 +0000144; CHECK-LABEL: doublediamond:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000145; CHECK: block{{$}}
146; CHECK-NEXT: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000147; CHECK: br_if 0, ${{[^,]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000148; CHECK: br 1{{$}}
149; CHECK: .LBB3_2:
150; CHECK-NEXT: end_block{{$}}
151; CHECK: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000152; CHECK: br_if 0, ${{[^,]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000153; CHECK: br 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000154; CHECK: .LBB3_4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000155; CHECK-NEXT: end_block{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000156; CHECK: .LBB3_5:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000157; CHECK-NEXT: end_block{{$}}
Dan Gohmanb6fd39a2016-01-19 16:59:23 +0000158; CHECK: i32.const $push{{[0-9]+}}=, 0{{$}}
159; CHECK-NEXT: return $pop{{[0-9]+}}{{$}}
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000160; OPT-LABEL: doublediamond:
Dan Gohman442bfce2016-02-16 16:22:41 +0000161; OPT: block{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000162; OPT-NEXT: block{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +0000163; OPT-NEXT: block{{$}}
164; OPT: br_if 0, ${{[^,]+}}{{$}}
165; OPT: br_if 1, ${{[^,]+}}{{$}}
166; OPT: br 2{{$}}
167; OPT-NEXT: .LBB3_3:
168; OPT-NEXT: end_block
169; OPT: br 1{{$}}
170; OPT-NEXT: .LBB3_4:
171; OPT: .LBB3_5:
172; OPT-NEXT: end_block
173; OPT: return $pop{{[0-9]+}}{{$}}
Dan Gohman950a13c2015-09-16 16:51:30 +0000174define i32 @doublediamond(i32 %a, i32 %b, i32* %p) {
175entry:
176 %c = icmp eq i32 %a, 0
177 %d = icmp eq i32 %b, 0
178 store volatile i32 0, i32* %p
179 br i1 %c, label %true, label %false
180true:
181 store volatile i32 1, i32* %p
182 br label %exit
183false:
184 store volatile i32 2, i32* %p
185 br i1 %d, label %ft, label %ff
186ft:
187 store volatile i32 3, i32* %p
188 br label %exit
189ff:
190 store volatile i32 4, i32* %p
191 br label %exit
192exit:
193 store volatile i32 5, i32* %p
194 ret i32 0
195}
196
Dan Gohmane51c0582015-10-06 00:27:55 +0000197; CHECK-LABEL: triangle:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000198; CHECK: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000199; CHECK: br_if 0, $1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000200; CHECK: .LBB4_2:
Dan Gohman4ba48162015-11-18 16:12:01 +0000201; CHECK: return ${{[0-9]+}}{{$}}
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000202; OPT-LABEL: triangle:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000203; OPT: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000204; OPT: br_if 0, $1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000205; OPT: .LBB4_2:
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000206; OPT: return ${{[0-9]+}}{{$}}
Dan Gohman950a13c2015-09-16 16:51:30 +0000207define i32 @triangle(i32* %p, i32 %a) {
208entry:
209 %c = icmp eq i32 %a, 0
210 store volatile i32 0, i32* %p
211 br i1 %c, label %true, label %exit
212true:
213 store volatile i32 1, i32* %p
214 br label %exit
215exit:
216 store volatile i32 2, i32* %p
217 ret i32 0
218}
219
Dan Gohmane51c0582015-10-06 00:27:55 +0000220; CHECK-LABEL: diamond:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000221; CHECK: block{{$}}
222; CHECK: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000223; CHECK: br_if 0, $1{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000224; CHECK: br 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000225; CHECK: .LBB5_2:
226; CHECK: .LBB5_3:
Dan Gohmanb6fd39a2016-01-19 16:59:23 +0000227; CHECK: i32.const $push{{[0-9]+}}=, 0{{$}}
228; CHECK-NEXT: return $pop{{[0-9]+}}{{$}}
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000229; OPT-LABEL: diamond:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000230; OPT: block{{$}}
231; OPT: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000232; OPT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000233; OPT: br 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000234; OPT: .LBB5_2:
235; OPT: .LBB5_3:
Dan Gohmanb6fd39a2016-01-19 16:59:23 +0000236; OPT: i32.const $push{{[0-9]+}}=, 0{{$}}
237; OPT-NEXT: return $pop{{[0-9]+}}{{$}}
Dan Gohman950a13c2015-09-16 16:51:30 +0000238define i32 @diamond(i32* %p, i32 %a) {
239entry:
240 %c = icmp eq i32 %a, 0
241 store volatile i32 0, i32* %p
242 br i1 %c, label %true, label %false
243true:
244 store volatile i32 1, i32* %p
245 br label %exit
246false:
247 store volatile i32 2, i32* %p
248 br label %exit
249exit:
250 store volatile i32 3, i32* %p
251 ret i32 0
252}
253
Dan Gohmane51c0582015-10-06 00:27:55 +0000254; CHECK-LABEL: single_block:
Dan Gohman950a13c2015-09-16 16:51:30 +0000255; CHECK-NOT: br
Dan Gohman81719f82015-11-25 16:55:01 +0000256; CHECK: return $pop{{[0-9]+}}{{$}}
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000257; OPT-LABEL: single_block:
258; OPT-NOT: br
259; OPT: return $pop{{[0-9]+}}{{$}}
Dan Gohman950a13c2015-09-16 16:51:30 +0000260define i32 @single_block(i32* %p) {
261entry:
262 store volatile i32 0, i32* %p
263 ret i32 0
264}
265
Dan Gohmane51c0582015-10-06 00:27:55 +0000266; CHECK-LABEL: minimal_loop:
Dan Gohman950a13c2015-09-16 16:51:30 +0000267; CHECK-NOT: br
Dan Gohmana4730cf2016-01-07 18:49:53 +0000268; CHECK: .LBB7_1:
Derek Schuff9d779522015-12-05 00:26:39 +0000269; CHECK: i32.store $discard=, 0($0), $pop{{[0-9]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000270; CHECK: br 0{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000271; CHECK: .LBB7_2:
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000272; OPT-LABEL: minimal_loop:
273; OPT-NOT: br
Dan Gohmana4730cf2016-01-07 18:49:53 +0000274; OPT: .LBB7_1:
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000275; OPT: i32.store $discard=, 0($0), $pop{{[0-9]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000276; OPT: br 0{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000277; OPT: .LBB7_2:
Dan Gohman950a13c2015-09-16 16:51:30 +0000278define i32 @minimal_loop(i32* %p) {
279entry:
280 store volatile i32 0, i32* %p
281 br label %loop
282loop:
283 store volatile i32 1, i32* %p
284 br label %loop
285}
286
Dan Gohmane51c0582015-10-06 00:27:55 +0000287; CHECK-LABEL: simple_loop:
Dan Gohman950a13c2015-09-16 16:51:30 +0000288; CHECK-NOT: br
Dan Gohmana4730cf2016-01-07 18:49:53 +0000289; CHECK: .LBB8_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000290; CHECK: loop{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000291; CHECK: br_if 0, $pop{{[0-9]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000292; CHECK-NEXT: end_loop{{$}}
Dan Gohmanb6fd39a2016-01-19 16:59:23 +0000293; CHECK: i32.const $push{{[0-9]+}}=, 0{{$}}
294; CHECK-NEXT: return $pop{{[0-9]+}}{{$}}
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000295; OPT-LABEL: simple_loop:
296; OPT-NOT: br
Dan Gohmana4730cf2016-01-07 18:49:53 +0000297; OPT: .LBB8_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000298; OPT: loop{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000299; OPT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000300; OPT-NEXT: end_loop{{$}}
Dan Gohmanb6fd39a2016-01-19 16:59:23 +0000301; OPT: i32.const $push{{[0-9]+}}=, 0{{$}}
302; OPT-NEXT: return $pop{{[0-9]+}}{{$}}
Dan Gohman950a13c2015-09-16 16:51:30 +0000303define i32 @simple_loop(i32* %p, i32 %a) {
304entry:
305 %c = icmp eq i32 %a, 0
306 store volatile i32 0, i32* %p
307 br label %loop
308loop:
309 store volatile i32 1, i32* %p
310 br i1 %c, label %loop, label %exit
311exit:
312 store volatile i32 2, i32* %p
313 ret i32 0
314}
315
Dan Gohmane51c0582015-10-06 00:27:55 +0000316; CHECK-LABEL: doubletriangle:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000317; CHECK: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000318; CHECK: br_if 0, $0{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000319; CHECK: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000320; CHECK: br_if 0, $1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000321; CHECK: .LBB9_3:
322; CHECK: .LBB9_4:
Dan Gohman4ba48162015-11-18 16:12:01 +0000323; CHECK: return ${{[0-9]+}}{{$}}
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000324; OPT-LABEL: doubletriangle:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000325; OPT: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000326; OPT: br_if 0, $0{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000327; OPT: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000328; OPT: br_if 0, $1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000329; OPT: .LBB9_3:
330; OPT: .LBB9_4:
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000331; OPT: return ${{[0-9]+}}{{$}}
Dan Gohman950a13c2015-09-16 16:51:30 +0000332define i32 @doubletriangle(i32 %a, i32 %b, i32* %p) {
333entry:
334 %c = icmp eq i32 %a, 0
335 %d = icmp eq i32 %b, 0
336 store volatile i32 0, i32* %p
337 br i1 %c, label %true, label %exit
338true:
339 store volatile i32 2, i32* %p
340 br i1 %d, label %tt, label %tf
341tt:
342 store volatile i32 3, i32* %p
343 br label %tf
344tf:
345 store volatile i32 4, i32* %p
346 br label %exit
347exit:
348 store volatile i32 5, i32* %p
349 ret i32 0
350}
351
Dan Gohmane51c0582015-10-06 00:27:55 +0000352; CHECK-LABEL: ifelse_earlyexits:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000353; CHECK: block{{$}}
354; CHECK: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000355; CHECK: br_if 0, $0{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000356; CHECK: br 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000357; CHECK: .LBB10_2:
Dan Gohman06b49582016-02-08 21:50:13 +0000358; CHECK: br_if 0, $1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000359; CHECK: .LBB10_4:
Dan Gohmanb6fd39a2016-01-19 16:59:23 +0000360; CHECK: i32.const $push{{[0-9]+}}=, 0{{$}}
361; CHECK-NEXT: return $pop{{[0-9]+}}{{$}}
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000362; OPT-LABEL: ifelse_earlyexits:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000363; OPT: block{{$}}
364; OPT: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000365; OPT: br_if 0, {{[^,]+}}{{$}}
366; OPT: br_if 1, $1{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000367; OPT: br 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000368; OPT: .LBB10_3:
369; OPT: .LBB10_4:
Dan Gohmanb6fd39a2016-01-19 16:59:23 +0000370; OPT: i32.const $push{{[0-9]+}}=, 0{{$}}
371; OPT-NEXT: return $pop{{[0-9]+}}{{$}}
Dan Gohman950a13c2015-09-16 16:51:30 +0000372define i32 @ifelse_earlyexits(i32 %a, i32 %b, i32* %p) {
373entry:
374 %c = icmp eq i32 %a, 0
375 %d = icmp eq i32 %b, 0
376 store volatile i32 0, i32* %p
377 br i1 %c, label %true, label %false
378true:
379 store volatile i32 1, i32* %p
380 br label %exit
381false:
382 store volatile i32 2, i32* %p
383 br i1 %d, label %ft, label %exit
384ft:
385 store volatile i32 3, i32* %p
386 br label %exit
387exit:
388 store volatile i32 4, i32* %p
389 ret i32 0
390}
Dan Gohmane3e4a5f2015-10-02 21:11:36 +0000391
Dan Gohman32807932015-11-23 16:19:56 +0000392; CHECK-LABEL: doublediamond_in_a_loop:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000393; CHECK: .LBB11_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000394; CHECK: loop{{$}}
395; CHECK: block{{$}}
396; CHECK: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000397; CHECK: br_if 0, $0{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000398; CHECK: br 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000399; CHECK: .LBB11_3:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000400; CHECK: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000401; CHECK: br_if 0, $1{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000402; CHECK: br 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000403; CHECK: .LBB11_5:
404; CHECK: .LBB11_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000405; CHECK: br 0{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000406; CHECK: .LBB11_7:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000407; CHECK-NEXT: end_loop{{$}}
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000408; OPT-LABEL: doublediamond_in_a_loop:
Dan Gohman442bfce2016-02-16 16:22:41 +0000409; OPT: .LBB11_1:
410; OPT: loop{{$}}
411; OPT: block{{$}}
412; OPT-NEXT: block{{$}}
413; OPT-NEXT: block{{$}}
414; OPT: br_if 0, {{[^,]+}}{{$}}
415; OPT: br_if 1, {{[^,]+}}{{$}}
416; OPT: br 2{{$}}
417; OPT-NEXT: .LBB11_4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000418; OPT-NEXT: end_block{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +0000419; OPT: br 1{{$}}
420; OPT: .LBB11_5:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000421; OPT-NEXT: end_block{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +0000422; OPT: .LBB11_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000423; OPT-NEXT: end_block{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +0000424; OPT: br 0{{$}}
425; OPT: .LBB11_7:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000426; OPT-NEXT: end_loop{{$}}
Dan Gohman32807932015-11-23 16:19:56 +0000427define i32 @doublediamond_in_a_loop(i32 %a, i32 %b, i32* %p) {
428entry:
429 br label %header
430header:
431 %c = icmp eq i32 %a, 0
432 %d = icmp eq i32 %b, 0
433 store volatile i32 0, i32* %p
434 br i1 %c, label %true, label %false
435true:
436 store volatile i32 1, i32* %p
437 br label %exit
438false:
439 store volatile i32 2, i32* %p
440 br i1 %d, label %ft, label %ff
441ft:
442 store volatile i32 3, i32* %p
443 br label %exit
444ff:
445 store volatile i32 4, i32* %p
446 br label %exit
447exit:
448 store volatile i32 5, i32* %p
449 br label %header
450}
451
Dan Gohmane3e4a5f2015-10-02 21:11:36 +0000452; Test that nested loops are handled.
453
Dan Gohman8fe7e862015-12-14 22:51:54 +0000454; CHECK-LABEL: test3:
455; CHECK: loop
456; CHECK-NEXT: br_if
Dan Gohmana4730cf2016-01-07 18:49:53 +0000457; CHECK-NEXT: .LBB{{[0-9]+}}_{{[0-9]+}}:
Dan Gohman8fe7e862015-12-14 22:51:54 +0000458; CHECK-NEXT: loop
459; OPT-LABEL: test3:
Dan Gohman442bfce2016-02-16 16:22:41 +0000460; OPT: block
461; OPT: br_if
Dan Gohmand85ab7f2016-02-18 06:32:53 +0000462; OPT: .LBB{{[0-9]+}}_{{[0-9]+}}:
Dan Gohman442bfce2016-02-16 16:22:41 +0000463; OPT-NEXT: loop
464; OPT-NEXT: block
465; OPT-NEXT: block
Dan Gohman8fe7e862015-12-14 22:51:54 +0000466; OPT-NEXT: br_if
Dan Gohmana4730cf2016-01-07 18:49:53 +0000467; OPT-NEXT: .LBB{{[0-9]+}}_{{[0-9]+}}:
Dan Gohman8fe7e862015-12-14 22:51:54 +0000468; OPT-NEXT: loop
Dan Gohman442bfce2016-02-16 16:22:41 +0000469; OPT: br_if
470; OPT-NEXT: br
471; OPT-NEXT: .LBB{{[0-9]+}}_{{[0-9]+}}:
472; OPT-NEXT: end_loop
473; OPT-NEXT: end_block
474; OPT-NEXT: unreachable
475; OPT-NEXT: .LBB{{[0-9]+}}_{{[0-9]+}}:
476; OPT-NEXT: end_block
477; OPT: br
478; OPT-NEXT: .LBB{{[0-9]+}}_{{[0-9]+}}:
479; OPT-NEXT: end_loop
Dan Gohmane3e4a5f2015-10-02 21:11:36 +0000480declare void @bar()
Dan Gohmane3e4a5f2015-10-02 21:11:36 +0000481define void @test3(i32 %w) {
482entry:
483 br i1 undef, label %outer.ph, label %exit
484
485outer.ph:
486 br label %outer
487
488outer:
489 %tobool = icmp eq i32 undef, 0
490 br i1 %tobool, label %inner, label %unreachable
491
492unreachable:
493 unreachable
494
495inner:
496 %c = icmp eq i32 undef, %w
497 br i1 %c, label %if.end, label %inner
498
499exit:
500 ret void
501
502if.end:
503 call void @bar()
504 br label %outer
505}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000506
507; Test switch lowering and block placement.
508
509; CHECK-LABEL: test4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000510; CHECK-NEXT: .param i32{{$}}
511; CHECK: block{{$}}
512; CHECK-NEXT: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000513; CHECK: br_if 0, $pop{{[0-9]+}}{{$}}
Dan Gohmand85ab7f2016-02-18 06:32:53 +0000514; CHECK: br_if 1, $pop{{[0-9]+}}{{$}}
515; CHECK: br 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000516; CHECK-NEXT: .LBB13_3:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000517; CHECK-NEXT: end_block{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +0000518; CHECK-NEXT: block{{$}}
Dan Gohmand85ab7f2016-02-18 06:32:53 +0000519; CHECK: br_if 0, $pop{{[0-9]+}}{{$}}
520; CHECK: br_if 1, $pop{{[0-9]+}}{{$}}
521; CHECK-NEXT: .LBB13_5:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000522; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000523; CHECK-NEXT: return{{$}}
Dan Gohmand85ab7f2016-02-18 06:32:53 +0000524; CHECK-NEXT: .LBB13_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000525; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000526; CHECK-NEXT: return{{$}}
527; OPT-LABEL: test4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000528; OPT-NEXT: .param i32{{$}}
529; OPT: block{{$}}
530; OPT-NEXT: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000531; OPT: br_if 0, $pop{{[0-9]+}}{{$}}
Dan Gohmand85ab7f2016-02-18 06:32:53 +0000532; OPT: br_if 1, $pop{{[0-9]+}}{{$}}
533; OPT: br 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000534; OPT-NEXT: .LBB13_3:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000535; OPT-NEXT: end_block{{$}}
Dan Gohmand85ab7f2016-02-18 06:32:53 +0000536; OPT-NEXT: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000537; OPT: br_if 0, $pop{{[0-9]+}}{{$}}
Dan Gohmand85ab7f2016-02-18 06:32:53 +0000538; OPT: br_if 1, $pop{{[0-9]+}}{{$}}
539; OPT-NEXT: .LBB13_5:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000540; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000541; OPT-NEXT: return{{$}}
Dan Gohmand85ab7f2016-02-18 06:32:53 +0000542; OPT-NEXT: .LBB13_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000543; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000544; OPT-NEXT: return{{$}}
545define void @test4(i32 %t) {
546entry:
547 switch i32 %t, label %default [
548 i32 0, label %bb2
549 i32 2, label %bb2
550 i32 4, label %bb1
551 i32 622, label %bb0
552 ]
553
554bb0:
555 ret void
556
557bb1:
558 ret void
559
560bb2:
561 ret void
562
563default:
564 ret void
565}
566
567; Test a case where the BLOCK needs to be placed before the LOOP in the
568; same basic block.
569
570; CHECK-LABEL: test5:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000571; CHECK: .LBB14_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000572; CHECK-NEXT: block{{$}}
573; CHECK-NEXT: loop{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000574; CHECK: br_if 2, {{[^,]+}}{{$}}
575; CHECK: br_if 0, {{[^,]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000576; CHECK-NEXT: end_loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000577; CHECK: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000578; CHECK-NEXT: .LBB14_4:
Dan Gohman8fe7e862015-12-14 22:51:54 +0000579; CHECK: return{{$}}
580; OPT-LABEL: test5:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000581; OPT: .LBB14_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000582; OPT-NEXT: block{{$}}
583; OPT-NEXT: loop{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000584; OPT: br_if 2, {{[^,]+}}{{$}}
585; OPT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000586; OPT-NEXT: end_loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000587; OPT: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000588; OPT-NEXT: .LBB14_4:
Dan Gohman8fe7e862015-12-14 22:51:54 +0000589; OPT: return{{$}}
590define void @test5(i1 %p, i1 %q) {
591entry:
592 br label %header
593
594header:
595 store volatile i32 0, i32* null
596 br i1 %p, label %more, label %alt
597
598more:
599 store volatile i32 1, i32* null
600 br i1 %q, label %header, label %return
601
602alt:
603 store volatile i32 2, i32* null
604 ret void
605
606return:
607 store volatile i32 3, i32* null
608 ret void
609}
610
611; Test an interesting case of a loop with multiple exits, which
612; aren't to layout successors of the loop, and one of which is to a successors
613; which has another predecessor.
614
615; CHECK-LABEL: test6:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000616; CHECK: .LBB15_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000617; CHECK-NEXT: block{{$}}
618; CHECK-NEXT: block{{$}}
619; CHECK-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000620; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000621; CHECK: br_if 3, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000622; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000623; CHECK: br_if 2, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000624; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000625; CHECK: br_if 0, {{[^,]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000626; CHECK-NEXT: end_loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000627; CHECK-NOT: block
628; CHECK: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000629; CHECK-NEXT: .LBB15_5:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000630; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000631; CHECK-NOT: block
Dan Gohmana4730cf2016-01-07 18:49:53 +0000632; CHECK: .LBB15_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000633; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000634; CHECK-NOT: block
635; CHECK: return{{$}}
636; OPT-LABEL: test6:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000637; OPT: .LBB15_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000638; OPT-NEXT: block{{$}}
639; OPT-NEXT: block{{$}}
640; OPT-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000641; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000642; OPT: br_if 3, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000643; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000644; OPT: br_if 2, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000645; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000646; OPT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000647; OPT-NEXT: end_loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000648; OPT-NOT: block
649; OPT: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000650; OPT-NEXT: .LBB15_5:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000651; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000652; OPT-NOT: block
Dan Gohmana4730cf2016-01-07 18:49:53 +0000653; OPT: .LBB15_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000654; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000655; OPT-NOT: block
656; OPT: return{{$}}
657define void @test6(i1 %p, i1 %q) {
658entry:
659 br label %header
660
661header:
662 store volatile i32 0, i32* null
663 br i1 %p, label %more, label %second
664
665more:
666 store volatile i32 1, i32* null
667 br i1 %q, label %evenmore, label %first
668
669evenmore:
670 store volatile i32 1, i32* null
671 br i1 %q, label %header, label %return
672
673return:
674 store volatile i32 2, i32* null
675 ret void
676
677first:
678 store volatile i32 3, i32* null
679 br label %second
680
681second:
682 store volatile i32 4, i32* null
683 ret void
684}
685
686; Test a case where there are multiple backedges and multiple loop exits
687; that end in unreachable.
688
689; CHECK-LABEL: test7:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000690; CHECK: .LBB16_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000691; CHECK-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000692; CHECK-NOT: block
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000693; CHECK: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000694; CHECK: br_if 0, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000695; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000696; CHECK: br_if 1, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000697; CHECK-NOT: block
698; CHECK: unreachable
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000699; CHECK-NEXT: .LBB16_4:
700; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000701; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000702; CHECK: br_if 0, {{[^,]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000703; CHECK-NEXT: end_loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000704; CHECK-NOT: block
705; CHECK: unreachable
706; OPT-LABEL: test7:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000707; OPT: .LBB16_1:
Dan Gohman442bfce2016-02-16 16:22:41 +0000708; OPT-NEXT: block
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000709; OPT-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000710; OPT-NOT: block
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000711; OPT: block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000712; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000713; OPT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000714; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000715; OPT: br_if 1, {{[^,]+}}{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +0000716; OPT: br 3{{$}}
717; OPT-NEXT: .LBB16_3:
718; OPT-NEXT: end_block
Dan Gohman8fe7e862015-12-14 22:51:54 +0000719; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000720; OPT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +0000721; OPT-NEXT: end_loop
722; OPT-NOT: block
723; OPT: unreachable
724; OPT-NEXT: .LBB16_5:
725; OPT-NEXT: end_block
Dan Gohman8fe7e862015-12-14 22:51:54 +0000726; OPT-NOT: block
727; OPT: unreachable
728define void @test7(i1 %tobool2, i1 %tobool9) {
729entry:
730 store volatile i32 0, i32* null
731 br label %loop
732
733loop:
734 store volatile i32 1, i32* null
735 br i1 %tobool2, label %l1, label %l0
736
737l0:
738 store volatile i32 2, i32* null
739 br i1 %tobool9, label %loop, label %u0
740
741l1:
742 store volatile i32 3, i32* null
743 br i1 %tobool9, label %loop, label %u1
744
745u0:
746 store volatile i32 4, i32* null
747 unreachable
748
749u1:
750 store volatile i32 5, i32* null
751 unreachable
752}
753
754; Test an interesting case using nested loops and switches.
755
756; CHECK-LABEL: test8:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000757; CHECK: .LBB17_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000758; CHECK-NEXT: loop{{$}}
759; CHECK-NEXT: block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000760; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000761; CHECK: br_if 0, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000762; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000763; CHECK: br_if 1, {{[^,]+}}{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000764; CHECK-NEXT: .LBB17_3:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000765; CHECK-NEXT: end_block{{$}}
766; CHECK-NEXT: loop{{$}}
Dan Gohmane5d3c152016-01-20 05:55:09 +0000767; CHECK-NEXT: i32.const $push{{[^,]+}}, 0{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000768; CHECK-NEXT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000769; CHECK-NEXT: br 2{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000770; CHECK-NEXT: .LBB17_4:
Dan Gohman8fe7e862015-12-14 22:51:54 +0000771; OPT-LABEL: test8:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000772; OPT: .LBB17_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000773; OPT-NEXT: loop{{$}}
774; OPT-NEXT: block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000775; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000776; OPT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000777; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000778; OPT: br_if 1, {{[^,]+}}{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000779; OPT-NEXT: .LBB17_3:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000780; OPT-NEXT: end_block{{$}}
781; OPT-NEXT: loop{{$}}
Dan Gohmane5d3c152016-01-20 05:55:09 +0000782; OPT-NEXT: i32.const $push{{[^,]+}}, 0{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000783; OPT-NEXT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000784; OPT-NEXT: br 2{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000785; OPT-NEXT: .LBB17_4:
Dan Gohman8fe7e862015-12-14 22:51:54 +0000786define i32 @test8() {
787bb:
788 br label %bb1
789
790bb1:
791 br i1 undef, label %bb2, label %bb3
792
793bb2:
794 switch i8 undef, label %bb1 [
795 i8 44, label %bb2
796 ]
797
798bb3:
799 switch i8 undef, label %bb1 [
800 i8 44, label %bb2
801 ]
802}
803
804; Test an interesting case using nested loops that share a bottom block.
805
806; CHECK-LABEL: test9:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000807; CHECK: .LBB18_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000808; CHECK-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000809; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000810; CHECK: br_if 1, {{[^,]+}}{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000811; CHECK-NEXT: .LBB18_2:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000812; CHECK-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000813; CHECK-NOT: block
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000814; CHECK: block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000815; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000816; CHECK: br_if 0, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000817; CHECK-NOT: block
Dan Gohmand85ab7f2016-02-18 06:32:53 +0000818; CHECK: br_if 3, {{[^,]+}}{{$}}
819; CHECK-NEXT: br 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000820; CHECK-NEXT: .LBB18_4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000821; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000822; CHECK-NOT: block
Dan Gohmand85ab7f2016-02-18 06:32:53 +0000823; CHECK: br_if 2, {{[^,]+}}{{$}}
824; CHECK-NEXT: br 0{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000825; CHECK-NEXT: .LBB18_5:
Dan Gohman8fe7e862015-12-14 22:51:54 +0000826; CHECK-NOT: block
827; CHECK: return{{$}}
828; OPT-LABEL: test9:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000829; OPT: .LBB18_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000830; OPT-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000831; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000832; OPT: br_if 1, {{[^,]+}}{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000833; OPT-NEXT: .LBB18_2:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000834; OPT-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000835; OPT-NOT: block
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000836; OPT: block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000837; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000838; OPT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000839; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000840; OPT: br_if 1, {{[^,]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000841; OPT-NEXT: br 3{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000842; OPT-NEXT: .LBB18_4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000843; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000844; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000845; OPT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000846; OPT-NEXT: br 2{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000847; OPT-NEXT: .LBB18_5:
Dan Gohman8fe7e862015-12-14 22:51:54 +0000848; OPT-NOT: block
849; OPT: return{{$}}
850declare i1 @a()
851define void @test9() {
852entry:
853 store volatile i32 0, i32* null
854 br label %header
855
856header:
857 store volatile i32 1, i32* null
858 %call4 = call i1 @a()
859 br i1 %call4, label %header2, label %end
860
861header2:
862 store volatile i32 2, i32* null
863 %call = call i1 @a()
864 br i1 %call, label %if.then, label %if.else
865
866if.then:
867 store volatile i32 3, i32* null
868 %call3 = call i1 @a()
869 br i1 %call3, label %header2, label %header
870
871if.else:
872 store volatile i32 4, i32* null
873 %call2 = call i1 @a()
874 br i1 %call2, label %header2, label %header
875
876end:
877 store volatile i32 5, i32* null
878 ret void
879}
880
881; Test an interesting case involving nested loops sharing a loop bottom,
882; and loop exits to a block with unreachable.
883
884; CHECK-LABEL: test10:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000885; CHECK: .LBB19_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000886; CHECK-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000887; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000888; CHECK: br_if 0, {{[^,]+}}{{$}}
JF Bastienc6ba5ea2016-04-05 17:01:52 +0000889; CHECK: .LBB19_3:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000890; CHECK-NEXT: block{{$}}
891; CHECK-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000892; CHECK-NOT: block
JF Bastienc6ba5ea2016-04-05 17:01:52 +0000893; CHECK: .LBB19_4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000894; CHECK-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000895; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000896; CHECK: br_if 5, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000897; CHECK-NOT: block
Dan Gohman14026062016-03-08 03:18:12 +0000898; CHECK: br_table {{[^,]+}}, 0, 1, 5, 2, 4, 0{{$}}
JF Bastienc6ba5ea2016-04-05 17:01:52 +0000899; CHECK-NEXT: .LBB19_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000900; CHECK-NEXT: end_loop{{$}}
901; CHECK-NEXT: end_loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000902; CHECK-NEXT: return{{$}}
JF Bastienc6ba5ea2016-04-05 17:01:52 +0000903; CHECK-NEXT: .LBB19_7:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000904; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000905; CHECK-NOT: block
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000906; CHECK: br 0{{$}}
JF Bastienc6ba5ea2016-04-05 17:01:52 +0000907; CHECK-NEXT: .LBB19_8:
Dan Gohman8fe7e862015-12-14 22:51:54 +0000908; OPT-LABEL: test10:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000909; OPT: .LBB19_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000910; OPT-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000911; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000912; OPT: br_if 0, {{[^,]+}}{{$}}
JF Bastienc6ba5ea2016-04-05 17:01:52 +0000913; OPT: .LBB19_3:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000914; OPT-NEXT: block{{$}}
915; OPT-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000916; OPT-NOT: block
JF Bastienc6ba5ea2016-04-05 17:01:52 +0000917; OPT: .LBB19_4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000918; OPT-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000919; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000920; OPT: br_if 5, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000921; OPT-NOT: block
Dan Gohman14026062016-03-08 03:18:12 +0000922; OPT: br_table {{[^,]+}}, 0, 1, 5, 2, 4, 0{{$}}
JF Bastienc6ba5ea2016-04-05 17:01:52 +0000923; OPT-NEXT: .LBB19_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000924; OPT-NEXT: end_loop{{$}}
925; OPT-NEXT: end_loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000926; OPT-NEXT: return{{$}}
JF Bastienc6ba5ea2016-04-05 17:01:52 +0000927; OPT-NEXT: .LBB19_7:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000928; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000929; OPT-NOT: block
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000930; OPT: br 0{{$}}
JF Bastienc6ba5ea2016-04-05 17:01:52 +0000931; OPT-NEXT: .LBB19_8:
Dan Gohman8fe7e862015-12-14 22:51:54 +0000932define void @test10() {
933bb0:
934 br label %bb1
935
936bb1:
937 %tmp = phi i32 [ 2, %bb0 ], [ 3, %bb3 ]
938 %tmp3 = phi i32 [ undef, %bb0 ], [ %tmp11, %bb3 ]
939 %tmp4 = icmp eq i32 %tmp3, 0
940 br i1 %tmp4, label %bb4, label %bb2
941
942bb2:
943 br label %bb3
944
945bb3:
946 %tmp11 = phi i32 [ 1, %bb5 ], [ 0, %bb2 ]
947 br label %bb1
948
949bb4:
950 %tmp6 = phi i32 [ %tmp9, %bb5 ], [ 4, %bb1 ]
951 %tmp7 = phi i32 [ %tmp6, %bb5 ], [ %tmp, %bb1 ]
952 br label %bb5
953
954bb5:
955 %tmp9 = phi i32 [ %tmp6, %bb5 ], [ %tmp7, %bb4 ]
956 switch i32 %tmp9, label %bb2 [
957 i32 0, label %bb5
958 i32 1, label %bb6
959 i32 3, label %bb4
960 i32 4, label %bb3
961 ]
962
963bb6:
964 ret void
965}
966
967; Test a CFG DAG with interesting merging.
968
969; CHECK-LABEL: test11:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000970; CHECK: block{{$}}
971; CHECK-NEXT: block{{$}}
972; CHECK-NEXT: block{{$}}
973; CHECK-NEXT: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000974; CHECK: br_if 0, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000975; CHECK-NOT: block
Dan Gohmaned0f1132016-01-30 05:01:06 +0000976; CHECK: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000977; CHECK-NEXT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000978; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000979; CHECK: br_if 2, {{[^,]+}}{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000980; CHECK-NEXT: .LBB20_3:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000981; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000982; CHECK-NOT: block
983; CHECK: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000984; CHECK-NEXT: .LBB20_4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000985; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000986; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000987; CHECK: br_if 1, {{[^,]+}}{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +0000988; CHECK-NOT: block
989; CHECK: br_if 2, {{[^,]+}}{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000990; CHECK-NEXT: .LBB20_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000991; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000992; CHECK-NOT: block
993; CHECK: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000994; CHECK-NEXT: .LBB20_7:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000995; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000996; CHECK-NOT: block
997; CHECK: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000998; CHECK-NEXT: .LBB20_8:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000999; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001000; CHECK-NOT: block
1001; CHECK: return{{$}}
1002; OPT-LABEL: test11:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001003; OPT: block{{$}}
1004; OPT-NEXT: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +00001005; OPT: br_if 0, $pop{{[0-9]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001006; OPT-NOT: block
Dan Gohmaned0f1132016-01-30 05:01:06 +00001007; OPT: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +00001008; OPT-NEXT: br_if 0, $0{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001009; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +00001010; OPT: br_if 2, {{[^,]+}}{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +00001011; OPT-NEXT: .LBB20_3:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001012; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001013; OPT-NOT: block
1014; OPT: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +00001015; OPT-NEXT: .LBB20_4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001016; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001017; OPT-NOT: block
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001018; OPT: block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001019; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +00001020; OPT: br_if 0, $pop{{[0-9]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001021; OPT-NOT: block
1022; OPT: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +00001023; OPT-NEXT: .LBB20_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001024; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001025; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +00001026; OPT: br_if 0, $pop{{[0-9]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001027; OPT-NOT: block
1028; OPT: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +00001029; OPT-NEXT: .LBB20_8:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001030; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001031; OPT-NOT: block
1032; OPT: return{{$}}
1033define void @test11() {
1034bb0:
1035 store volatile i32 0, i32* null
1036 br i1 undef, label %bb1, label %bb4
1037bb1:
1038 store volatile i32 1, i32* null
1039 br i1 undef, label %bb3, label %bb2
1040bb2:
1041 store volatile i32 2, i32* null
1042 br i1 undef, label %bb3, label %bb7
1043bb3:
1044 store volatile i32 3, i32* null
1045 ret void
1046bb4:
1047 store volatile i32 4, i32* null
1048 br i1 undef, label %bb8, label %bb5
1049bb5:
1050 store volatile i32 5, i32* null
1051 br i1 undef, label %bb6, label %bb7
1052bb6:
1053 store volatile i32 6, i32* null
1054 ret void
1055bb7:
1056 store volatile i32 7, i32* null
1057 ret void
1058bb8:
1059 store volatile i32 8, i32* null
1060 ret void
1061}
1062
1063; CHECK-LABEL: test12:
Dan Gohmana4730cf2016-01-07 18:49:53 +00001064; CHECK: .LBB21_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001065; CHECK-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001066; CHECK-NOT: block
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001067; CHECK: block{{$}}
1068; CHECK-NEXT: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +00001069; CHECK: br_if 0, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001070; CHECK-NOT: block
Dan Gohman442bfce2016-02-16 16:22:41 +00001071; CHECK: br_if 1, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001072; CHECK-NOT: block
Dan Gohman442bfce2016-02-16 16:22:41 +00001073; CHECK: br_if 1, {{[^,]+}}{{$}}
1074; CHECK-NEXT: br 3{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +00001075; CHECK-NEXT: .LBB21_4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001076; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001077; CHECK-NOT: block
Dan Gohman442bfce2016-02-16 16:22:41 +00001078; CHECK: br_if 0, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001079; CHECK-NOT: block
Dan Gohman442bfce2016-02-16 16:22:41 +00001080; CHECK: br_if 2, {{[^,]+}}{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +00001081; CHECK-NEXT: .LBB21_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001082; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001083; CHECK-NOT: block
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001084; CHECK: br 0{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +00001085; CHECK-NEXT: .LBB21_7:
1086; CHECK-NEXT: end_loop{{$}}
1087; CHECK-NEXT: return{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001088; OPT-LABEL: test12:
Dan Gohmana4730cf2016-01-07 18:49:53 +00001089; OPT: .LBB21_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001090; OPT-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001091; OPT-NOT: block
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001092; OPT: block{{$}}
1093; OPT-NEXT: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +00001094; OPT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001095; OPT-NOT: block
Dan Gohman442bfce2016-02-16 16:22:41 +00001096; OPT: br_if 1, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001097; OPT-NOT: block
Dan Gohman442bfce2016-02-16 16:22:41 +00001098; OPT: br_if 1, {{[^,]+}}{{$}}
1099; OPT-NEXT: br 3{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +00001100; OPT-NEXT: .LBB21_4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001101; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001102; OPT-NOT: block
Dan Gohman442bfce2016-02-16 16:22:41 +00001103; OPT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001104; OPT-NOT: block
Dan Gohman442bfce2016-02-16 16:22:41 +00001105; OPT: br_if 2, {{[^,]+}}{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +00001106; OPT-NEXT: .LBB21_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001107; OPT-NEXT: end_block{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001108; OPT: br 0{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +00001109; OPT-NEXT: .LBB21_7:
1110; OPT-NEXT: end_loop{{$}}
1111; OPT-NEXT: return{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001112define void @test12(i8* %arg) {
1113bb:
1114 br label %bb1
1115
1116bb1:
1117 %tmp = phi i32 [ 0, %bb ], [ %tmp5, %bb4 ]
1118 %tmp2 = getelementptr i8, i8* %arg, i32 %tmp
1119 %tmp3 = load i8, i8* %tmp2
1120 switch i8 %tmp3, label %bb7 [
1121 i8 42, label %bb4
1122 i8 76, label %bb4
1123 i8 108, label %bb4
1124 i8 104, label %bb4
1125 ]
1126
1127bb4:
1128 %tmp5 = add i32 %tmp, 1
1129 br label %bb1
1130
1131bb7:
1132 ret void
1133}
Dan Gohmanb3aa1ec2015-12-16 19:06:41 +00001134
1135; A block can be "branched to" from another even if it is also reachable via
1136; fallthrough from the other. This would normally be optimized away, so use
1137; optnone to disable optimizations to test this case.
1138
1139; CHECK-LABEL: test13:
Dan Gohmanb6fd39a2016-01-19 16:59:23 +00001140; CHECK-NEXT: .local i32{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +00001141; CHECK-NEXT: block{{$}}
1142; CHECK-NEXT: block{{$}}
1143; CHECK: br_if 0, $pop0{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001144; CHECK: block{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +00001145; CHECK: br_if 0, $pop3{{$}}
1146; CHECK: .LBB22_3:
1147; CHECK-NEXT: end_block{{$}}
1148; CHECK: br_if 1, $pop{{[0-9]+}}{{$}}
1149; CHECK-NEXT: br 1{{$}}
1150; CHECK-NEXT: .LBB22_4:
1151; CHECK-NEXT: end_block{{$}}
Dan Gohmanb3aa1ec2015-12-16 19:06:41 +00001152; CHECK-NEXT: return{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +00001153; CHECK-NEXT: .LBB22_5:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001154; CHECK-NEXT: end_block{{$}}
Dan Gohmanb3aa1ec2015-12-16 19:06:41 +00001155; CHECK-NEXT: unreachable{{$}}
1156; OPT-LABEL: test13:
Dan Gohmanb6fd39a2016-01-19 16:59:23 +00001157; OPT-NEXT: .local i32{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +00001158; OPT-NEXT: block{{$}}
1159; OPT-NEXT: block{{$}}
1160; OPT: br_if 0, $pop0{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001161; OPT: block{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +00001162; OPT: br_if 0, $pop3{{$}}
1163; OPT: .LBB22_3:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001164; OPT-NEXT: end_block{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +00001165; OPT: br_if 1, $pop{{[0-9]+}}{{$}}
1166; OPT-NEXT: br 1{{$}}
1167; OPT-NEXT: .LBB22_4:
1168; OPT-NEXT: end_block
1169; OPT-NEXT: return
1170; OPT-NEXT: .LBB22_5:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001171; OPT-NEXT: end_block{{$}}
Dan Gohmanb3aa1ec2015-12-16 19:06:41 +00001172; OPT-NEXT: unreachable{{$}}
1173define void @test13() noinline optnone {
1174bb:
1175 br i1 undef, label %bb5, label %bb2
1176bb1:
1177 unreachable
1178bb2:
1179 br i1 undef, label %bb3, label %bb4
1180bb3:
1181 br label %bb4
1182bb4:
1183 %tmp = phi i1 [ false, %bb2 ], [ false, %bb3 ]
1184 br i1 %tmp, label %bb1, label %bb1
1185bb5:
1186 ret void
1187}
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001188
1189; Test a case with a single-block loop that has another loop
1190; as a successor. The end_loop for the first loop should go
1191; before the loop for the second.
1192
1193; CHECK-LABEL: test14:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001194; CHECK-NEXT: .LBB23_1:{{$}}
1195; CHECK-NEXT: loop{{$}}
Dan Gohmanb6fd39a2016-01-19 16:59:23 +00001196; CHECK-NEXT: i32.const $push0=, 0{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +00001197; CHECK-NEXT: br_if 0, $pop0{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001198; CHECK-NEXT: .LBB23_2:{{$}}
1199; CHECK-NEXT: end_loop{{$}}
1200; CHECK-NEXT: loop{{$}}
Dan Gohman899cb5a2016-01-25 16:48:44 +00001201; CHECK-NEXT: i32.const $discard=, 0{{$}}
Dan Gohmanb6fd39a2016-01-19 16:59:23 +00001202; CHECK-NEXT: i32.const $push1=, 0{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +00001203; CHECK-NEXT: br_if 0, $pop1{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001204; CHECK-NEXT: end_loop{{$}}
1205; CHECK-NEXT: return{{$}}
1206define void @test14() {
1207bb:
1208 br label %bb1
1209
1210bb1:
1211 %tmp = bitcast i1 undef to i1
1212 br i1 %tmp, label %bb3, label %bb1
1213
1214bb3:
1215 br label %bb4
1216
1217bb4:
1218 br i1 undef, label %bb7, label %bb48
1219
1220bb7:
1221 br i1 undef, label %bb12, label %bb12
1222
1223bb12:
1224 br i1 undef, label %bb17, label %bb17
1225
1226bb17:
1227 br i1 undef, label %bb22, label %bb22
1228
1229bb22:
1230 br i1 undef, label %bb27, label %bb27
1231
1232bb27:
1233 br i1 undef, label %bb30, label %bb30
1234
1235bb30:
1236 br i1 undef, label %bb35, label %bb35
1237
1238bb35:
1239 br i1 undef, label %bb38, label %bb38
1240
1241bb38:
1242 br i1 undef, label %bb48, label %bb48
1243
1244bb48:
1245 %tmp49 = bitcast i1 undef to i1
1246 br i1 %tmp49, label %bb3, label %bb50
1247
1248bb50:
1249 ret void
1250}
Dan Gohmana187ab22016-02-12 21:19:25 +00001251
1252; Test that a block boundary which ends one block, begins another block, and
1253; also begins a loop, has the markers placed in the correct order.
1254
1255; CHECK-LABEL: test15:
1256; CHECK: block
Dan Gohmana187ab22016-02-12 21:19:25 +00001257; CHECK-NEXT: block
Dan Gohman442bfce2016-02-16 16:22:41 +00001258; CHECK: br_if 0, $pop{{.*}}{{$}}
Dan Gohmand85ab7f2016-02-18 06:32:53 +00001259; CHECK: .LBB24_2:
Dan Gohman442bfce2016-02-16 16:22:41 +00001260; CHECK-NEXT: block{{$}}
1261; CHECK-NEXT: loop{{$}}
1262; CHECK: br_if 1, $pop{{.*}}{{$}}
Dan Gohmand85ab7f2016-02-18 06:32:53 +00001263; CHECK: br_if 0, ${{.*}}{{$}}
1264; CHECK-NEXT: br 2{{$}}
1265; CHECK-NEXT: .LBB24_4:
Dan Gohman442bfce2016-02-16 16:22:41 +00001266; CHECK-NEXT: end_loop{{$}}
Dan Gohmand85ab7f2016-02-18 06:32:53 +00001267; CHECK: .LBB24_5:
Dan Gohman442bfce2016-02-16 16:22:41 +00001268; CHECK-NEXT: end_block{{$}}
1269; CHECK: br_if 1, $pop{{.*}}{{$}}
1270; CHECK: return{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +00001271; CHECK: .LBB24_7:
1272; CHECK-NEXT: end_block{{$}}
Dan Gohmand85ab7f2016-02-18 06:32:53 +00001273; CHECK: .LBB24_8:
1274; CHECK-NEXT: end_block{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +00001275; CHECK-NEXT: return{{$}}
Dan Gohmana187ab22016-02-12 21:19:25 +00001276; OPT-LABEL: test15:
1277; OPT: block
Dan Gohmand85ab7f2016-02-18 06:32:53 +00001278; OPT: block
Dan Gohmana187ab22016-02-12 21:19:25 +00001279; OPT-NEXT: i32.const $push
1280; OPT-NEXT: i32.const $push
1281; OPT-NEXT: i32.eq $push{{.*}}=, $pop{{.*}}, $pop{{.*}}{{$}}
1282; OPT-NEXT: br_if 0, $pop{{.*}}{{$}}
1283; OPT-NEXT: call test15_callee1@FUNCTION{{$}}
Dan Gohmand85ab7f2016-02-18 06:32:53 +00001284; OPT-NEXT: br 1{{$}}
Dan Gohmana187ab22016-02-12 21:19:25 +00001285; OPT-NEXT: .LBB24_2:
1286; OPT-NEXT: end_block
Dan Gohmand85ab7f2016-02-18 06:32:53 +00001287; OPT-NEXT: i32.const
1288; OPT-NEXT: .LBB24_3:
Dan Gohmana187ab22016-02-12 21:19:25 +00001289; OPT-NEXT: block
1290; OPT-NEXT: loop
1291%0 = type { i8, i32 }
1292declare void @test15_callee0()
1293declare void @test15_callee1()
1294define void @test15() {
1295bb:
1296 %tmp1 = icmp eq i8 1, 0
1297 br i1 %tmp1, label %bb2, label %bb14
1298
1299bb2:
1300 %tmp3 = phi %0** [ %tmp6, %bb5 ], [ null, %bb ]
1301 %tmp4 = icmp eq i32 0, 11
1302 br i1 %tmp4, label %bb5, label %bb8
1303
1304bb5:
1305 %tmp = bitcast i8* null to %0**
1306 %tmp6 = getelementptr %0*, %0** %tmp3, i32 1
1307 %tmp7 = icmp eq %0** %tmp6, null
1308 br i1 %tmp7, label %bb10, label %bb2
1309
1310bb8:
1311 %tmp9 = icmp eq %0** null, undef
1312 br label %bb10
1313
1314bb10:
1315 %tmp11 = phi %0** [ null, %bb8 ], [ %tmp, %bb5 ]
1316 %tmp12 = icmp eq %0** null, %tmp11
1317 br i1 %tmp12, label %bb15, label %bb13
1318
1319bb13:
1320 call void @test15_callee0()
1321 ret void
1322
1323bb14:
1324 call void @test15_callee1()
1325 ret void
1326
1327bb15:
1328 ret void
1329}