blob: f5b4b77c3d74992eecd442ff68dd0ce877024828 [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
17; CHECK-NEXT: i32.ge_s
18; CHECK-NEXT: br_if
Dan Gohmanf0b165a2015-12-05 03:03:35 +000019; CHECK-NOT: br
Dan Gohmane51c0582015-10-06 00:27:55 +000020; CHECK: call
Dan Gohman1d68e80f2016-01-12 19:14:46 +000021; CHECK: br 0{{$}}
Dan Gohmane51c0582015-10-06 00:27:55 +000022; CHECK: return{{$}}
Dan Gohmanf0b165a2015-12-05 03:03:35 +000023; OPT-LABEL: test0:
24; OPT: loop
Dan Gohmanf0b165a2015-12-05 03:03:35 +000025; OPT-NOT: br
Dan Gohman8fe7e862015-12-14 22:51:54 +000026; OPT: i32.add
27; OPT-NEXT: i32.ge_s
28; OPT-NEXT: br_if
Dan Gohmanf0b165a2015-12-05 03:03:35 +000029; OPT-NOT: br
30; OPT: call
Dan Gohman1d68e80f2016-01-12 19:14:46 +000031; OPT: br 0{{$}}
Dan Gohmanf0b165a2015-12-05 03:03:35 +000032; OPT: return{{$}}
Dan Gohman950a13c2015-09-16 16:51:30 +000033define void @test0(i32 %n) {
34entry:
35 br label %header
36
37header:
38 %i = phi i32 [ 0, %entry ], [ %i.next, %back ]
39 %i.next = add i32 %i, 1
40
41 %c = icmp slt i32 %i.next, %n
42 br i1 %c, label %back, label %exit
43
44exit:
45 ret void
46
47back:
48 call void @something()
49 br label %header
50}
51
52; Same as test0, but the branch condition is reversed.
53
Dan Gohmane51c0582015-10-06 00:27:55 +000054; CHECK-LABEL: test1:
55; CHECK: loop
Dan Gohmanf0b165a2015-12-05 03:03:35 +000056; CHECK-NOT: br
Dan Gohman8fe7e862015-12-14 22:51:54 +000057; CHECK: i32.add
58; CHECK-NEXT: i32.ge_s
59; CHECK-NEXT: br_if
Dan Gohmanf0b165a2015-12-05 03:03:35 +000060; CHECK-NOT: br
Dan Gohmane51c0582015-10-06 00:27:55 +000061; CHECK: call
Dan Gohman1d68e80f2016-01-12 19:14:46 +000062; CHECK: br 0{{$}}
Dan Gohmane51c0582015-10-06 00:27:55 +000063; CHECK: return{{$}}
Dan Gohmanf0b165a2015-12-05 03:03:35 +000064; OPT-LABEL: test1:
65; OPT: loop
Dan Gohmanf0b165a2015-12-05 03:03:35 +000066; OPT-NOT: br
Dan Gohman8fe7e862015-12-14 22:51:54 +000067; OPT: i32.add
68; OPT-NEXT: i32.ge_s
69; OPT-NEXT: br_if
Dan Gohmanf0b165a2015-12-05 03:03:35 +000070; OPT-NOT: br
71; OPT: call
Dan Gohman1d68e80f2016-01-12 19:14:46 +000072; OPT: br 0{{$}}
Dan Gohmanf0b165a2015-12-05 03:03:35 +000073; OPT: return{{$}}
Dan Gohman950a13c2015-09-16 16:51:30 +000074define void @test1(i32 %n) {
75entry:
76 br label %header
77
78header:
79 %i = phi i32 [ 0, %entry ], [ %i.next, %back ]
80 %i.next = add i32 %i, 1
81
82 %c = icmp sge i32 %i.next, %n
83 br i1 %c, label %exit, label %back
84
85exit:
86 ret void
87
88back:
89 call void @something()
90 br label %header
91}
92
93; Test that a simple loop is handled as expected.
94
Dan Gohmane51c0582015-10-06 00:27:55 +000095; CHECK-LABEL: test2:
Dan Gohman8f59cf72016-01-06 18:29:35 +000096; CHECK-NOT: local
Dan Gohman1d68e80f2016-01-12 19:14:46 +000097; CHECK: block{{$}}
Dan Gohmane5d3c152016-01-20 05:55:09 +000098; CHECK: br_if {{[^,]+}}, 0{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +000099; CHECK: .LBB2_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000100; CHECK: br_if ${{[0-9]+}}, 0{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000101; CHECK: .LBB2_2:
Dan Gohmane51c0582015-10-06 00:27:55 +0000102; CHECK: return{{$}}
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000103; OPT-LABEL: test2:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000104; OPT-NOT: local
105; OPT: block{{$}}
Dan Gohmane5d3c152016-01-20 05:55:09 +0000106; OPT: br_if {{[^,]+}}, 0{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000107; OPT: .LBB2_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000108; OPT: br_if ${{[0-9]+}}, 0{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000109; OPT: .LBB2_2:
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000110; OPT: return{{$}}
Dan Gohman950a13c2015-09-16 16:51:30 +0000111define void @test2(double* nocapture %p, i32 %n) {
112entry:
113 %cmp.4 = icmp sgt i32 %n, 0
114 br i1 %cmp.4, label %for.body.preheader, label %for.end
115
116for.body.preheader:
117 br label %for.body
118
119for.body:
120 %i.05 = phi i32 [ %inc, %for.body ], [ 0, %for.body.preheader ]
121 %arrayidx = getelementptr inbounds double, double* %p, i32 %i.05
122 %0 = load double, double* %arrayidx, align 8
123 %mul = fmul double %0, 3.200000e+00
124 store double %mul, double* %arrayidx, align 8
125 %inc = add nuw nsw i32 %i.05, 1
126 %exitcond = icmp eq i32 %inc, %n
127 br i1 %exitcond, label %for.end.loopexit, label %for.body
128
129for.end.loopexit:
130 br label %for.end
131
132for.end:
133 ret void
134}
135
Dan Gohmane51c0582015-10-06 00:27:55 +0000136; CHECK-LABEL: doublediamond:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000137; CHECK: block{{$}}
138; CHECK-NEXT: block{{$}}
Dan Gohmane5d3c152016-01-20 05:55:09 +0000139; CHECK: br_if ${{[^,]+}}, 0{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000140; CHECK: br 1{{$}}
141; CHECK: .LBB3_2:
142; CHECK-NEXT: end_block{{$}}
143; CHECK: block{{$}}
Dan Gohmane5d3c152016-01-20 05:55:09 +0000144; CHECK: br_if ${{[^,]+}}, 0{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000145; CHECK: br 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000146; CHECK: .LBB3_4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000147; CHECK-NEXT: end_block{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000148; CHECK: .LBB3_5:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000149; CHECK-NEXT: end_block{{$}}
Dan Gohmanb6fd39a2016-01-19 16:59:23 +0000150; CHECK: i32.const $push{{[0-9]+}}=, 0{{$}}
151; CHECK-NEXT: return $pop{{[0-9]+}}{{$}}
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000152; OPT-LABEL: doublediamond:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000153; OPT: block{{$}}
154; OPT-NEXT: block{{$}}
Dan Gohmane5d3c152016-01-20 05:55:09 +0000155; OPT: br_if ${{[^,]+}}, 0{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000156; OPT: block{{$}}
Dan Gohmane5d3c152016-01-20 05:55:09 +0000157; OPT: br_if ${{[^,]+}}, 0{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000158; OPT: br 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000159; OPT: .LBB3_4:
160; OPT: .LBB3_5:
Dan Gohmanb6fd39a2016-01-19 16:59:23 +0000161; OPT: i32.const $push{{[0-9]+}}=, 0{{$}}
162; OPT-NEXT: return $pop{{[0-9]+}}{{$}}
Dan Gohman950a13c2015-09-16 16:51:30 +0000163define i32 @doublediamond(i32 %a, i32 %b, i32* %p) {
164entry:
165 %c = icmp eq i32 %a, 0
166 %d = icmp eq i32 %b, 0
167 store volatile i32 0, i32* %p
168 br i1 %c, label %true, label %false
169true:
170 store volatile i32 1, i32* %p
171 br label %exit
172false:
173 store volatile i32 2, i32* %p
174 br i1 %d, label %ft, label %ff
175ft:
176 store volatile i32 3, i32* %p
177 br label %exit
178ff:
179 store volatile i32 4, i32* %p
180 br label %exit
181exit:
182 store volatile i32 5, i32* %p
183 ret i32 0
184}
185
Dan Gohmane51c0582015-10-06 00:27:55 +0000186; CHECK-LABEL: triangle:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000187; CHECK: block{{$}}
188; CHECK: br_if $1, 0{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000189; CHECK: .LBB4_2:
Dan Gohman4ba48162015-11-18 16:12:01 +0000190; CHECK: return ${{[0-9]+}}{{$}}
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000191; OPT-LABEL: triangle:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000192; OPT: block{{$}}
193; OPT: br_if $1, 0{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000194; OPT: .LBB4_2:
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000195; OPT: return ${{[0-9]+}}{{$}}
Dan Gohman950a13c2015-09-16 16:51:30 +0000196define i32 @triangle(i32* %p, i32 %a) {
197entry:
198 %c = icmp eq i32 %a, 0
199 store volatile i32 0, i32* %p
200 br i1 %c, label %true, label %exit
201true:
202 store volatile i32 1, i32* %p
203 br label %exit
204exit:
205 store volatile i32 2, i32* %p
206 ret i32 0
207}
208
Dan Gohmane51c0582015-10-06 00:27:55 +0000209; CHECK-LABEL: diamond:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000210; CHECK: block{{$}}
211; CHECK: block{{$}}
212; CHECK: br_if $1, 0{{$}}
213; CHECK: br 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000214; CHECK: .LBB5_2:
215; CHECK: .LBB5_3:
Dan Gohmanb6fd39a2016-01-19 16:59:23 +0000216; CHECK: i32.const $push{{[0-9]+}}=, 0{{$}}
217; CHECK-NEXT: return $pop{{[0-9]+}}{{$}}
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000218; OPT-LABEL: diamond:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000219; OPT: block{{$}}
220; OPT: block{{$}}
Dan Gohmane5d3c152016-01-20 05:55:09 +0000221; OPT: br_if {{[^,]+}}, 0{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000222; OPT: br 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000223; OPT: .LBB5_2:
224; OPT: .LBB5_3:
Dan Gohmanb6fd39a2016-01-19 16:59:23 +0000225; OPT: i32.const $push{{[0-9]+}}=, 0{{$}}
226; OPT-NEXT: return $pop{{[0-9]+}}{{$}}
Dan Gohman950a13c2015-09-16 16:51:30 +0000227define i32 @diamond(i32* %p, i32 %a) {
228entry:
229 %c = icmp eq i32 %a, 0
230 store volatile i32 0, i32* %p
231 br i1 %c, label %true, label %false
232true:
233 store volatile i32 1, i32* %p
234 br label %exit
235false:
236 store volatile i32 2, i32* %p
237 br label %exit
238exit:
239 store volatile i32 3, i32* %p
240 ret i32 0
241}
242
Dan Gohmane51c0582015-10-06 00:27:55 +0000243; CHECK-LABEL: single_block:
Dan Gohman950a13c2015-09-16 16:51:30 +0000244; CHECK-NOT: br
Dan Gohman81719f82015-11-25 16:55:01 +0000245; CHECK: return $pop{{[0-9]+}}{{$}}
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000246; OPT-LABEL: single_block:
247; OPT-NOT: br
248; OPT: return $pop{{[0-9]+}}{{$}}
Dan Gohman950a13c2015-09-16 16:51:30 +0000249define i32 @single_block(i32* %p) {
250entry:
251 store volatile i32 0, i32* %p
252 ret i32 0
253}
254
Dan Gohmane51c0582015-10-06 00:27:55 +0000255; CHECK-LABEL: minimal_loop:
Dan Gohman950a13c2015-09-16 16:51:30 +0000256; CHECK-NOT: br
Dan Gohmana4730cf2016-01-07 18:49:53 +0000257; CHECK: .LBB7_1:
Derek Schuff9d779522015-12-05 00:26:39 +0000258; CHECK: i32.store $discard=, 0($0), $pop{{[0-9]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000259; CHECK: br 0{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000260; CHECK: .LBB7_2:
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000261; OPT-LABEL: minimal_loop:
262; OPT-NOT: br
Dan Gohmana4730cf2016-01-07 18:49:53 +0000263; OPT: .LBB7_1:
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000264; OPT: i32.store $discard=, 0($0), $pop{{[0-9]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000265; OPT: br 0{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000266; OPT: .LBB7_2:
Dan Gohman950a13c2015-09-16 16:51:30 +0000267define i32 @minimal_loop(i32* %p) {
268entry:
269 store volatile i32 0, i32* %p
270 br label %loop
271loop:
272 store volatile i32 1, i32* %p
273 br label %loop
274}
275
Dan Gohmane51c0582015-10-06 00:27:55 +0000276; CHECK-LABEL: simple_loop:
Dan Gohman950a13c2015-09-16 16:51:30 +0000277; CHECK-NOT: br
Dan Gohmana4730cf2016-01-07 18:49:53 +0000278; CHECK: .LBB8_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000279; CHECK: loop{{$}}
280; CHECK: br_if $pop{{[0-9]+}}, 0{{$}}
281; CHECK-NEXT: end_loop{{$}}
Dan Gohmanb6fd39a2016-01-19 16:59:23 +0000282; CHECK: i32.const $push{{[0-9]+}}=, 0{{$}}
283; CHECK-NEXT: return $pop{{[0-9]+}}{{$}}
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000284; OPT-LABEL: simple_loop:
285; OPT-NOT: br
Dan Gohmana4730cf2016-01-07 18:49:53 +0000286; OPT: .LBB8_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000287; OPT: loop{{$}}
Dan Gohmane5d3c152016-01-20 05:55:09 +0000288; OPT: br_if {{[^,]+}}, 0{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000289; OPT-NEXT: end_loop{{$}}
Dan Gohmanb6fd39a2016-01-19 16:59:23 +0000290; OPT: i32.const $push{{[0-9]+}}=, 0{{$}}
291; OPT-NEXT: return $pop{{[0-9]+}}{{$}}
Dan Gohman950a13c2015-09-16 16:51:30 +0000292define i32 @simple_loop(i32* %p, i32 %a) {
293entry:
294 %c = icmp eq i32 %a, 0
295 store volatile i32 0, i32* %p
296 br label %loop
297loop:
298 store volatile i32 1, i32* %p
299 br i1 %c, label %loop, label %exit
300exit:
301 store volatile i32 2, i32* %p
302 ret i32 0
303}
304
Dan Gohmane51c0582015-10-06 00:27:55 +0000305; CHECK-LABEL: doubletriangle:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000306; CHECK: block{{$}}
307; CHECK: br_if $0, 0{{$}}
308; CHECK: block{{$}}
309; CHECK: br_if $1, 0{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000310; CHECK: .LBB9_3:
311; CHECK: .LBB9_4:
Dan Gohman4ba48162015-11-18 16:12:01 +0000312; CHECK: return ${{[0-9]+}}{{$}}
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000313; OPT-LABEL: doubletriangle:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000314; OPT: block{{$}}
315; OPT: br_if $0, 0{{$}}
316; OPT: block{{$}}
317; OPT: br_if $1, 0{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000318; OPT: .LBB9_3:
319; OPT: .LBB9_4:
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000320; OPT: return ${{[0-9]+}}{{$}}
Dan Gohman950a13c2015-09-16 16:51:30 +0000321define i32 @doubletriangle(i32 %a, i32 %b, i32* %p) {
322entry:
323 %c = icmp eq i32 %a, 0
324 %d = icmp eq i32 %b, 0
325 store volatile i32 0, i32* %p
326 br i1 %c, label %true, label %exit
327true:
328 store volatile i32 2, i32* %p
329 br i1 %d, label %tt, label %tf
330tt:
331 store volatile i32 3, i32* %p
332 br label %tf
333tf:
334 store volatile i32 4, i32* %p
335 br label %exit
336exit:
337 store volatile i32 5, i32* %p
338 ret i32 0
339}
340
Dan Gohmane51c0582015-10-06 00:27:55 +0000341; CHECK-LABEL: ifelse_earlyexits:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000342; CHECK: block{{$}}
343; CHECK: block{{$}}
344; CHECK: br_if $0, 0{{$}}
345; CHECK: br 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000346; CHECK: .LBB10_2:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000347; CHECK: br_if $1, 0{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000348; CHECK: .LBB10_4:
Dan Gohmanb6fd39a2016-01-19 16:59:23 +0000349; CHECK: i32.const $push{{[0-9]+}}=, 0{{$}}
350; CHECK-NEXT: return $pop{{[0-9]+}}{{$}}
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000351; OPT-LABEL: ifelse_earlyexits:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000352; OPT: block{{$}}
353; OPT: block{{$}}
Dan Gohmane5d3c152016-01-20 05:55:09 +0000354; OPT: br_if {{[^,]+}}, 0{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000355; OPT: br_if $1, 1{{$}}
356; OPT: br 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000357; OPT: .LBB10_3:
358; OPT: .LBB10_4:
Dan Gohmanb6fd39a2016-01-19 16:59:23 +0000359; OPT: i32.const $push{{[0-9]+}}=, 0{{$}}
360; OPT-NEXT: return $pop{{[0-9]+}}{{$}}
Dan Gohman950a13c2015-09-16 16:51:30 +0000361define i32 @ifelse_earlyexits(i32 %a, i32 %b, i32* %p) {
362entry:
363 %c = icmp eq i32 %a, 0
364 %d = icmp eq i32 %b, 0
365 store volatile i32 0, i32* %p
366 br i1 %c, label %true, label %false
367true:
368 store volatile i32 1, i32* %p
369 br label %exit
370false:
371 store volatile i32 2, i32* %p
372 br i1 %d, label %ft, label %exit
373ft:
374 store volatile i32 3, i32* %p
375 br label %exit
376exit:
377 store volatile i32 4, i32* %p
378 ret i32 0
379}
Dan Gohmane3e4a5f2015-10-02 21:11:36 +0000380
Dan Gohman32807932015-11-23 16:19:56 +0000381; CHECK-LABEL: doublediamond_in_a_loop:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000382; CHECK: .LBB11_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000383; CHECK: loop{{$}}
384; CHECK: block{{$}}
385; CHECK: block{{$}}
386; CHECK: br_if $0, 0{{$}}
387; CHECK: br 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000388; CHECK: .LBB11_3:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000389; CHECK: block{{$}}
390; CHECK: br_if $1, 0{{$}}
391; CHECK: br 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000392; CHECK: .LBB11_5:
393; CHECK: .LBB11_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000394; CHECK: br 0{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000395; CHECK: .LBB11_7:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000396; CHECK-NEXT: end_loop{{$}}
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000397; OPT-LABEL: doublediamond_in_a_loop:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000398; OPT: .LBB11_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000399; OPT: loop{{$}}
400; OPT: block{{$}}
401; OPT: block{{$}}
Dan Gohmane5d3c152016-01-20 05:55:09 +0000402; OPT: br_if {{[^,]+}}, 0{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000403; OPT: block{{$}}
Dan Gohmane5d3c152016-01-20 05:55:09 +0000404; OPT: br_if {{[^,]+}}, 0{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000405; OPT: br 2{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000406; OPT: .LBB11_4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000407; OPT-NEXT: end_block{{$}}
408; OPT: br 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000409; OPT: .LBB11_5:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000410; OPT-NEXT: end_block{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000411; OPT: .LBB11_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000412; OPT-NEXT: end_block{{$}}
413; OPT: br 0{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000414; OPT: .LBB11_7:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000415; OPT-NEXT: end_loop{{$}}
Dan Gohman32807932015-11-23 16:19:56 +0000416define i32 @doublediamond_in_a_loop(i32 %a, i32 %b, i32* %p) {
417entry:
418 br label %header
419header:
420 %c = icmp eq i32 %a, 0
421 %d = icmp eq i32 %b, 0
422 store volatile i32 0, i32* %p
423 br i1 %c, label %true, label %false
424true:
425 store volatile i32 1, i32* %p
426 br label %exit
427false:
428 store volatile i32 2, i32* %p
429 br i1 %d, label %ft, label %ff
430ft:
431 store volatile i32 3, i32* %p
432 br label %exit
433ff:
434 store volatile i32 4, i32* %p
435 br label %exit
436exit:
437 store volatile i32 5, i32* %p
438 br label %header
439}
440
Dan Gohmane3e4a5f2015-10-02 21:11:36 +0000441; Test that nested loops are handled.
442
Dan Gohman8fe7e862015-12-14 22:51:54 +0000443; CHECK-LABEL: test3:
444; CHECK: loop
445; CHECK-NEXT: br_if
Dan Gohmana4730cf2016-01-07 18:49:53 +0000446; CHECK-NEXT: .LBB{{[0-9]+}}_{{[0-9]+}}:
Dan Gohman8fe7e862015-12-14 22:51:54 +0000447; CHECK-NEXT: loop
448; OPT-LABEL: test3:
449; OPT: loop
450; OPT-NEXT: br_if
Dan Gohmana4730cf2016-01-07 18:49:53 +0000451; OPT-NEXT: .LBB{{[0-9]+}}_{{[0-9]+}}:
Dan Gohman8fe7e862015-12-14 22:51:54 +0000452; OPT-NEXT: loop
Dan Gohmane3e4a5f2015-10-02 21:11:36 +0000453declare void @bar()
Dan Gohmane3e4a5f2015-10-02 21:11:36 +0000454define void @test3(i32 %w) {
455entry:
456 br i1 undef, label %outer.ph, label %exit
457
458outer.ph:
459 br label %outer
460
461outer:
462 %tobool = icmp eq i32 undef, 0
463 br i1 %tobool, label %inner, label %unreachable
464
465unreachable:
466 unreachable
467
468inner:
469 %c = icmp eq i32 undef, %w
470 br i1 %c, label %if.end, label %inner
471
472exit:
473 ret void
474
475if.end:
476 call void @bar()
477 br label %outer
478}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000479
480; Test switch lowering and block placement.
481
482; CHECK-LABEL: test4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000483; CHECK-NEXT: .param i32{{$}}
484; CHECK: block{{$}}
485; CHECK-NEXT: block{{$}}
486; CHECK-NEXT: block{{$}}
Dan Gohmane5d3c152016-01-20 05:55:09 +0000487; CHECK: br_if $pop{{[0-9]+}}, 0{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000488; CHECK-NEXT: block{{$}}
Dan Gohmane5d3c152016-01-20 05:55:09 +0000489; CHECK: br_if $pop{{[0-9]+}}, 0{{$}}
490; CHECK: br_if $pop{{[0-9]+}}, 2{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000491; CHECK-NEXT: .LBB13_3:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000492; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000493; CHECK-NEXT: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000494; CHECK-NEXT: .LBB13_4:
Dan Gohmane5d3c152016-01-20 05:55:09 +0000495; CHECK: br_if $pop{{[0-9]+}}, 1{{$}}
496; CHECK: br_if $pop{{[0-9]+}}, 0{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000497; CHECK-NEXT: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000498; CHECK-NEXT: .LBB13_7:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000499; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000500; CHECK-NEXT: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000501; CHECK-NEXT: .LBB13_8:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000502; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000503; CHECK-NEXT: return{{$}}
504; OPT-LABEL: test4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000505; OPT-NEXT: .param i32{{$}}
506; OPT: block{{$}}
507; OPT-NEXT: block{{$}}
508; OPT-NEXT: block{{$}}
Dan Gohmane5d3c152016-01-20 05:55:09 +0000509; OPT: br_if $pop{{[0-9]+}}, 0{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000510; OPT-NEXT: block{{$}}
Dan Gohmane5d3c152016-01-20 05:55:09 +0000511; OPT: br_if $pop{{[0-9]+}}, 0{{$}}
512; OPT: br_if $pop{{[0-9]+}}, 2{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000513; OPT-NEXT: .LBB13_3:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000514; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000515; OPT-NEXT: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000516; OPT-NEXT: .LBB13_4:
Dan Gohmane5d3c152016-01-20 05:55:09 +0000517; OPT: br_if $pop{{[0-9]+}}, 1{{$}}
518; OPT: br_if $pop{{[0-9]+}}, 0{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000519; OPT-NEXT: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000520; OPT-NEXT: .LBB13_7:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000521; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000522; OPT-NEXT: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000523; OPT-NEXT: .LBB13_8:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000524; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000525; OPT-NEXT: return{{$}}
526define void @test4(i32 %t) {
527entry:
528 switch i32 %t, label %default [
529 i32 0, label %bb2
530 i32 2, label %bb2
531 i32 4, label %bb1
532 i32 622, label %bb0
533 ]
534
535bb0:
536 ret void
537
538bb1:
539 ret void
540
541bb2:
542 ret void
543
544default:
545 ret void
546}
547
548; Test a case where the BLOCK needs to be placed before the LOOP in the
549; same basic block.
550
551; CHECK-LABEL: test5:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000552; CHECK: .LBB14_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000553; CHECK-NEXT: block{{$}}
554; CHECK-NEXT: loop{{$}}
Dan Gohmane5d3c152016-01-20 05:55:09 +0000555; CHECK: br_if {{[^,]+}}, 2{{$}}
556; CHECK: br_if {{[^,]+}}, 0{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000557; CHECK-NEXT: end_loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000558; CHECK: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000559; CHECK-NEXT: .LBB14_4:
Dan Gohman8fe7e862015-12-14 22:51:54 +0000560; CHECK: return{{$}}
561; OPT-LABEL: test5:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000562; OPT: .LBB14_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000563; OPT-NEXT: block{{$}}
564; OPT-NEXT: loop{{$}}
Dan Gohmane5d3c152016-01-20 05:55:09 +0000565; OPT: br_if {{[^,]+}}, 2{{$}}
566; OPT: br_if {{[^,]+}}, 0{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000567; OPT-NEXT: end_loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000568; OPT: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000569; OPT-NEXT: .LBB14_4:
Dan Gohman8fe7e862015-12-14 22:51:54 +0000570; OPT: return{{$}}
571define void @test5(i1 %p, i1 %q) {
572entry:
573 br label %header
574
575header:
576 store volatile i32 0, i32* null
577 br i1 %p, label %more, label %alt
578
579more:
580 store volatile i32 1, i32* null
581 br i1 %q, label %header, label %return
582
583alt:
584 store volatile i32 2, i32* null
585 ret void
586
587return:
588 store volatile i32 3, i32* null
589 ret void
590}
591
592; Test an interesting case of a loop with multiple exits, which
593; aren't to layout successors of the loop, and one of which is to a successors
594; which has another predecessor.
595
596; CHECK-LABEL: test6:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000597; CHECK: .LBB15_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000598; CHECK-NEXT: block{{$}}
599; CHECK-NEXT: block{{$}}
600; CHECK-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000601; CHECK-NOT: block
Dan Gohmane5d3c152016-01-20 05:55:09 +0000602; CHECK: br_if {{[^,]+}}, 3{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000603; CHECK-NOT: block
Dan Gohmane5d3c152016-01-20 05:55:09 +0000604; CHECK: br_if {{[^,]+}}, 2{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000605; CHECK-NOT: block
Dan Gohmane5d3c152016-01-20 05:55:09 +0000606; CHECK: br_if {{[^,]+}}, 0{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000607; CHECK-NEXT: end_loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000608; CHECK-NOT: block
609; CHECK: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000610; CHECK-NEXT: .LBB15_5:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000611; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000612; CHECK-NOT: block
Dan Gohmana4730cf2016-01-07 18:49:53 +0000613; CHECK: .LBB15_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000614; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000615; CHECK-NOT: block
616; CHECK: return{{$}}
617; OPT-LABEL: test6:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000618; OPT: .LBB15_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000619; OPT-NEXT: block{{$}}
620; OPT-NEXT: block{{$}}
621; OPT-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000622; OPT-NOT: block
Dan Gohmane5d3c152016-01-20 05:55:09 +0000623; OPT: br_if {{[^,]+}}, 3{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000624; OPT-NOT: block
Dan Gohmane5d3c152016-01-20 05:55:09 +0000625; OPT: br_if {{[^,]+}}, 2{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000626; OPT-NOT: block
Dan Gohmane5d3c152016-01-20 05:55:09 +0000627; OPT: br_if {{[^,]+}}, 0{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000628; OPT-NEXT: end_loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000629; OPT-NOT: block
630; OPT: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000631; OPT-NEXT: .LBB15_5:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000632; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000633; OPT-NOT: block
Dan Gohmana4730cf2016-01-07 18:49:53 +0000634; OPT: .LBB15_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000635; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000636; OPT-NOT: block
637; OPT: return{{$}}
638define void @test6(i1 %p, i1 %q) {
639entry:
640 br label %header
641
642header:
643 store volatile i32 0, i32* null
644 br i1 %p, label %more, label %second
645
646more:
647 store volatile i32 1, i32* null
648 br i1 %q, label %evenmore, label %first
649
650evenmore:
651 store volatile i32 1, i32* null
652 br i1 %q, label %header, label %return
653
654return:
655 store volatile i32 2, i32* null
656 ret void
657
658first:
659 store volatile i32 3, i32* null
660 br label %second
661
662second:
663 store volatile i32 4, i32* null
664 ret void
665}
666
667; Test a case where there are multiple backedges and multiple loop exits
668; that end in unreachable.
669
670; CHECK-LABEL: test7:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000671; CHECK: .LBB16_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000672; CHECK-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000673; CHECK-NOT: block
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000674; CHECK: block{{$}}
Dan Gohmane5d3c152016-01-20 05:55:09 +0000675; CHECK: br_if {{[^,]+}}, 0{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000676; CHECK-NOT: block
Dan Gohmane5d3c152016-01-20 05:55:09 +0000677; CHECK: br_if {{[^,]+}}, 1{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000678; CHECK-NOT: block
679; CHECK: unreachable
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000680; CHECK-NEXT: .LBB16_4:
681; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000682; CHECK-NOT: block
Dan Gohmane5d3c152016-01-20 05:55:09 +0000683; CHECK: br_if {{[^,]+}}, 0{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000684; CHECK-NEXT: end_loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000685; CHECK-NOT: block
686; CHECK: unreachable
687; OPT-LABEL: test7:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000688; OPT: .LBB16_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000689; OPT-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000690; OPT-NOT: block
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000691; OPT: block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000692; OPT-NOT: block
Dan Gohmane5d3c152016-01-20 05:55:09 +0000693; OPT: br_if {{[^,]+}}, 0{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000694; OPT-NOT: block
Dan Gohmane5d3c152016-01-20 05:55:09 +0000695; OPT: br_if {{[^,]+}}, 1{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000696; OPT-NOT: block
697; OPT: unreachable
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000698; OPT-NEXT: .LBB16_4:
699; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000700; OPT-NOT: block
Dan Gohmane5d3c152016-01-20 05:55:09 +0000701; OPT: br_if {{[^,]+}}, 0{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000702; OPT-NEXT: end_loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000703; OPT-NOT: block
704; OPT: unreachable
705define void @test7(i1 %tobool2, i1 %tobool9) {
706entry:
707 store volatile i32 0, i32* null
708 br label %loop
709
710loop:
711 store volatile i32 1, i32* null
712 br i1 %tobool2, label %l1, label %l0
713
714l0:
715 store volatile i32 2, i32* null
716 br i1 %tobool9, label %loop, label %u0
717
718l1:
719 store volatile i32 3, i32* null
720 br i1 %tobool9, label %loop, label %u1
721
722u0:
723 store volatile i32 4, i32* null
724 unreachable
725
726u1:
727 store volatile i32 5, i32* null
728 unreachable
729}
730
731; Test an interesting case using nested loops and switches.
732
733; CHECK-LABEL: test8:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000734; CHECK: .LBB17_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000735; CHECK-NEXT: loop{{$}}
736; CHECK-NEXT: block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000737; CHECK-NOT: block
Dan Gohmane5d3c152016-01-20 05:55:09 +0000738; CHECK: br_if {{[^,]+}}, 0{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000739; CHECK-NOT: block
Dan Gohmane5d3c152016-01-20 05:55:09 +0000740; CHECK: br_if {{[^,]+}}, 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000741; CHECK-NEXT: .LBB17_3:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000742; CHECK-NEXT: end_block{{$}}
743; CHECK-NEXT: loop{{$}}
Dan Gohmane5d3c152016-01-20 05:55:09 +0000744; CHECK-NEXT: i32.const $push{{[^,]+}}, 0{{$}}
745; CHECK-NEXT: br_if {{[^,]+}}, 0{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000746; CHECK-NEXT: br 2{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000747; CHECK-NEXT: .LBB17_4:
Dan Gohman8fe7e862015-12-14 22:51:54 +0000748; OPT-LABEL: test8:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000749; OPT: .LBB17_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000750; OPT-NEXT: loop{{$}}
751; OPT-NEXT: block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000752; OPT-NOT: block
Dan Gohmane5d3c152016-01-20 05:55:09 +0000753; OPT: br_if {{[^,]+}}, 0{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000754; OPT-NOT: block
Dan Gohmane5d3c152016-01-20 05:55:09 +0000755; OPT: br_if {{[^,]+}}, 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000756; OPT-NEXT: .LBB17_3:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000757; OPT-NEXT: end_block{{$}}
758; OPT-NEXT: loop{{$}}
Dan Gohmane5d3c152016-01-20 05:55:09 +0000759; OPT-NEXT: i32.const $push{{[^,]+}}, 0{{$}}
760; OPT-NEXT: br_if {{[^,]+}}, 0{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000761; OPT-NEXT: br 2{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000762; OPT-NEXT: .LBB17_4:
Dan Gohman8fe7e862015-12-14 22:51:54 +0000763define i32 @test8() {
764bb:
765 br label %bb1
766
767bb1:
768 br i1 undef, label %bb2, label %bb3
769
770bb2:
771 switch i8 undef, label %bb1 [
772 i8 44, label %bb2
773 ]
774
775bb3:
776 switch i8 undef, label %bb1 [
777 i8 44, label %bb2
778 ]
779}
780
781; Test an interesting case using nested loops that share a bottom block.
782
783; CHECK-LABEL: test9:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000784; CHECK: .LBB18_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000785; CHECK-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000786; CHECK-NOT: block
Dan Gohmane5d3c152016-01-20 05:55:09 +0000787; CHECK: br_if {{[^,]+}}, 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000788; CHECK-NEXT: .LBB18_2:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000789; CHECK-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000790; CHECK-NOT: block
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000791; CHECK: block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000792; CHECK-NOT: block
Dan Gohmane5d3c152016-01-20 05:55:09 +0000793; CHECK: br_if {{[^,]+}}, 0{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000794; CHECK-NOT: block
Dan Gohmane5d3c152016-01-20 05:55:09 +0000795; CHECK: br_if {{[^,]+}}, 1{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000796; CHECK-NEXT: br 3{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000797; CHECK-NEXT: .LBB18_4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000798; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000799; CHECK-NOT: block
Dan Gohmane5d3c152016-01-20 05:55:09 +0000800; CHECK: br_if {{[^,]+}}, 0{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000801; CHECK-NEXT: br 2{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000802; CHECK-NEXT: .LBB18_5:
Dan Gohman8fe7e862015-12-14 22:51:54 +0000803; CHECK-NOT: block
804; CHECK: return{{$}}
805; OPT-LABEL: test9:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000806; OPT: .LBB18_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000807; OPT-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000808; OPT-NOT: block
Dan Gohmane5d3c152016-01-20 05:55:09 +0000809; OPT: br_if {{[^,]+}}, 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000810; OPT-NEXT: .LBB18_2:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000811; OPT-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000812; OPT-NOT: block
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000813; OPT: block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000814; OPT-NOT: block
Dan Gohmane5d3c152016-01-20 05:55:09 +0000815; OPT: br_if {{[^,]+}}, 0{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000816; OPT-NOT: block
Dan Gohmane5d3c152016-01-20 05:55:09 +0000817; OPT: br_if {{[^,]+}}, 1{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000818; OPT-NEXT: br 3{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000819; OPT-NEXT: .LBB18_4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000820; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000821; OPT-NOT: block
Dan Gohmane5d3c152016-01-20 05:55:09 +0000822; OPT: br_if {{[^,]+}}, 0{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000823; OPT-NEXT: br 2{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000824; OPT-NEXT: .LBB18_5:
Dan Gohman8fe7e862015-12-14 22:51:54 +0000825; OPT-NOT: block
826; OPT: return{{$}}
827declare i1 @a()
828define void @test9() {
829entry:
830 store volatile i32 0, i32* null
831 br label %header
832
833header:
834 store volatile i32 1, i32* null
835 %call4 = call i1 @a()
836 br i1 %call4, label %header2, label %end
837
838header2:
839 store volatile i32 2, i32* null
840 %call = call i1 @a()
841 br i1 %call, label %if.then, label %if.else
842
843if.then:
844 store volatile i32 3, i32* null
845 %call3 = call i1 @a()
846 br i1 %call3, label %header2, label %header
847
848if.else:
849 store volatile i32 4, i32* null
850 %call2 = call i1 @a()
851 br i1 %call2, label %header2, label %header
852
853end:
854 store volatile i32 5, i32* null
855 ret void
856}
857
858; Test an interesting case involving nested loops sharing a loop bottom,
859; and loop exits to a block with unreachable.
860
861; CHECK-LABEL: test10:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000862; CHECK: .LBB19_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000863; CHECK-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000864; CHECK-NOT: block
Dan Gohmane5d3c152016-01-20 05:55:09 +0000865; CHECK: br_if {{[^,]+}}, 0{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000866; CHECK-NEXT: .LBB19_2:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000867; CHECK-NEXT: block{{$}}
868; CHECK-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000869; CHECK-NOT: block
Dan Gohmana4730cf2016-01-07 18:49:53 +0000870; CHECK: .LBB19_3:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000871; CHECK-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000872; CHECK-NOT: block
Dan Gohmane5d3c152016-01-20 05:55:09 +0000873; CHECK: br_if {{[^,]+}}, 5{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000874; CHECK-NOT: block
Dan Gohmane5d3c152016-01-20 05:55:09 +0000875; CHECK: tableswitch {{[^,]+}}, 0, 0, 1, 5, 2, 4{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000876; CHECK-NEXT: .LBB19_5:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000877; CHECK-NEXT: end_loop{{$}}
878; CHECK-NEXT: end_loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000879; CHECK-NEXT: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000880; CHECK-NEXT: .LBB19_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000881; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000882; CHECK-NOT: block
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000883; CHECK: br 0{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000884; CHECK-NEXT: .LBB19_7:
Dan Gohman8fe7e862015-12-14 22:51:54 +0000885; OPT-LABEL: test10:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000886; OPT: .LBB19_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000887; OPT-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000888; OPT-NOT: block
Dan Gohmane5d3c152016-01-20 05:55:09 +0000889; OPT: br_if {{[^,]+}}, 0{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000890; OPT-NEXT: .LBB19_2:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000891; OPT-NEXT: block{{$}}
892; OPT-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000893; OPT-NOT: block
Dan Gohmana4730cf2016-01-07 18:49:53 +0000894; OPT: .LBB19_3:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000895; OPT-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000896; OPT-NOT: block
Dan Gohmane5d3c152016-01-20 05:55:09 +0000897; OPT: br_if {{[^,]+}}, 5{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000898; OPT-NOT: block
Dan Gohmane5d3c152016-01-20 05:55:09 +0000899; OPT: tableswitch {{[^,]+}}, 0, 0, 1, 5, 2, 4{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000900; OPT-NEXT: .LBB19_5:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000901; OPT-NEXT: end_loop{{$}}
902; OPT-NEXT: end_loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000903; OPT-NEXT: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000904; OPT-NEXT: .LBB19_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000905; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000906; OPT-NOT: block
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000907; OPT: br 0{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000908; OPT-NEXT: .LBB19_7:
Dan Gohman8fe7e862015-12-14 22:51:54 +0000909define void @test10() {
910bb0:
911 br label %bb1
912
913bb1:
914 %tmp = phi i32 [ 2, %bb0 ], [ 3, %bb3 ]
915 %tmp3 = phi i32 [ undef, %bb0 ], [ %tmp11, %bb3 ]
916 %tmp4 = icmp eq i32 %tmp3, 0
917 br i1 %tmp4, label %bb4, label %bb2
918
919bb2:
920 br label %bb3
921
922bb3:
923 %tmp11 = phi i32 [ 1, %bb5 ], [ 0, %bb2 ]
924 br label %bb1
925
926bb4:
927 %tmp6 = phi i32 [ %tmp9, %bb5 ], [ 4, %bb1 ]
928 %tmp7 = phi i32 [ %tmp6, %bb5 ], [ %tmp, %bb1 ]
929 br label %bb5
930
931bb5:
932 %tmp9 = phi i32 [ %tmp6, %bb5 ], [ %tmp7, %bb4 ]
933 switch i32 %tmp9, label %bb2 [
934 i32 0, label %bb5
935 i32 1, label %bb6
936 i32 3, label %bb4
937 i32 4, label %bb3
938 ]
939
940bb6:
941 ret void
942}
943
944; Test a CFG DAG with interesting merging.
945
946; CHECK-LABEL: test11:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000947; CHECK: block{{$}}
948; CHECK-NEXT: block{{$}}
949; CHECK-NEXT: block{{$}}
950; CHECK-NEXT: block{{$}}
Dan Gohmane5d3c152016-01-20 05:55:09 +0000951; CHECK: br_if {{[^,]+}}, 0{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000952; CHECK-NEXT: block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000953; CHECK-NOT: block
Dan Gohmane5d3c152016-01-20 05:55:09 +0000954; CHECK: br_if {{[^,]+}}, 0{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000955; CHECK-NOT: block
Dan Gohmane5d3c152016-01-20 05:55:09 +0000956; CHECK: br_if {{[^,]+}}, 2{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000957; CHECK-NEXT: .LBB20_3:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000958; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000959; CHECK-NOT: block
960; CHECK: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000961; CHECK-NEXT: .LBB20_4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000962; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000963; CHECK-NOT: block
Dan Gohmane5d3c152016-01-20 05:55:09 +0000964; CHECK: br_if {{[^,]+}}, 2{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000965; CHECK-NOT: block
Dan Gohmane5d3c152016-01-20 05:55:09 +0000966; CHECK: br_if {{[^,]+}}, 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000967; CHECK-NEXT: .LBB20_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000968; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000969; CHECK-NOT: block
970; CHECK: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000971; CHECK-NEXT: .LBB20_7:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000972; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000973; CHECK-NOT: block
974; CHECK: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000975; CHECK-NEXT: .LBB20_8:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000976; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000977; CHECK-NOT: block
978; CHECK: return{{$}}
979; OPT-LABEL: test11:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000980; OPT: block{{$}}
981; OPT-NEXT: block{{$}}
Dan Gohmanb6fd39a2016-01-19 16:59:23 +0000982; OPT: br_if $0, 0{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000983; OPT-NEXT: block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000984; OPT-NOT: block
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000985; OPT: br_if $0, 0{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000986; OPT-NOT: block
Dan Gohmane5d3c152016-01-20 05:55:09 +0000987; OPT: br_if {{[^,]+}}, 2{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000988; OPT-NEXT: .LBB20_3:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000989; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000990; OPT-NOT: block
991; OPT: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000992; OPT-NEXT: .LBB20_4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000993; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000994; OPT-NOT: block
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000995; OPT: block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000996; OPT-NOT: block
Dan Gohmanb6fd39a2016-01-19 16:59:23 +0000997; OPT: br_if $pop{{[0-9]+}}, 0{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000998; OPT-NOT: block
999; OPT: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +00001000; OPT-NEXT: .LBB20_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001001; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001002; OPT-NOT: block
Dan Gohmanb6fd39a2016-01-19 16:59:23 +00001003; OPT: br_if $pop{{[0-9]+}}, 0{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001004; OPT-NOT: block
1005; OPT: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +00001006; OPT-NEXT: .LBB20_8:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001007; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001008; OPT-NOT: block
1009; OPT: return{{$}}
1010define void @test11() {
1011bb0:
1012 store volatile i32 0, i32* null
1013 br i1 undef, label %bb1, label %bb4
1014bb1:
1015 store volatile i32 1, i32* null
1016 br i1 undef, label %bb3, label %bb2
1017bb2:
1018 store volatile i32 2, i32* null
1019 br i1 undef, label %bb3, label %bb7
1020bb3:
1021 store volatile i32 3, i32* null
1022 ret void
1023bb4:
1024 store volatile i32 4, i32* null
1025 br i1 undef, label %bb8, label %bb5
1026bb5:
1027 store volatile i32 5, i32* null
1028 br i1 undef, label %bb6, label %bb7
1029bb6:
1030 store volatile i32 6, i32* null
1031 ret void
1032bb7:
1033 store volatile i32 7, i32* null
1034 ret void
1035bb8:
1036 store volatile i32 8, i32* null
1037 ret void
1038}
1039
1040; CHECK-LABEL: test12:
Dan Gohmana4730cf2016-01-07 18:49:53 +00001041; CHECK: .LBB21_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001042; CHECK-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001043; CHECK-NOT: block
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001044; CHECK: block{{$}}
1045; CHECK-NEXT: block{{$}}
1046; CHECK-NEXT: block{{$}}
Dan Gohmane5d3c152016-01-20 05:55:09 +00001047; CHECK: br_if {{[^,]+}}, 0{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001048; CHECK-NOT: block
Dan Gohmane5d3c152016-01-20 05:55:09 +00001049; CHECK: br_if {{[^,]+}}, 2{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001050; CHECK-NOT: block
Dan Gohmane5d3c152016-01-20 05:55:09 +00001051; CHECK: br_if {{[^,]+}}, 2{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001052; CHECK-NEXT: br 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +00001053; CHECK-NEXT: .LBB21_4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001054; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001055; CHECK-NOT: block
Dan Gohmane5d3c152016-01-20 05:55:09 +00001056; CHECK: br_if {{[^,]+}}, 1{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001057; CHECK-NOT: block
Dan Gohmane5d3c152016-01-20 05:55:09 +00001058; CHECK: br_if {{[^,]+}}, 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +00001059; CHECK-NEXT: .LBB21_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001060; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001061; CHECK-NEXT: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +00001062; CHECK-NEXT: .LBB21_7:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001063; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001064; CHECK-NOT: block
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001065; CHECK: br 0{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +00001066; CHECK-NEXT: .LBB21_8:
Dan Gohman8fe7e862015-12-14 22:51:54 +00001067; OPT-LABEL: test12:
Dan Gohmana4730cf2016-01-07 18:49:53 +00001068; OPT: .LBB21_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001069; OPT-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001070; OPT-NOT: block
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001071; OPT: block{{$}}
1072; OPT-NEXT: block{{$}}
1073; OPT-NEXT: block{{$}}
Dan Gohmane5d3c152016-01-20 05:55:09 +00001074; OPT: br_if {{[^,]+}}, 0{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001075; OPT-NOT: block
Dan Gohmane5d3c152016-01-20 05:55:09 +00001076; OPT: br_if {{[^,]+}}, 2{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001077; OPT-NOT: block
Dan Gohmane5d3c152016-01-20 05:55:09 +00001078; OPT: br_if {{[^,]+}}, 2{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001079; OPT-NEXT: br 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +00001080; OPT-NEXT: .LBB21_4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001081; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001082; OPT-NOT: block
Dan Gohmane5d3c152016-01-20 05:55:09 +00001083; OPT: br_if {{[^,]+}}, 1{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001084; OPT-NOT: block
Dan Gohmane5d3c152016-01-20 05:55:09 +00001085; OPT: br_if {{[^,]+}}, 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +00001086; OPT-NEXT: .LBB21_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001087; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001088; OPT-NEXT: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +00001089; OPT-NEXT: .LBB21_7:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001090; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001091; OPT-NOT: block
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001092; OPT: br 0{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +00001093; OPT-NEXT: .LBB21_8:
Dan Gohman8fe7e862015-12-14 22:51:54 +00001094define void @test12(i8* %arg) {
1095bb:
1096 br label %bb1
1097
1098bb1:
1099 %tmp = phi i32 [ 0, %bb ], [ %tmp5, %bb4 ]
1100 %tmp2 = getelementptr i8, i8* %arg, i32 %tmp
1101 %tmp3 = load i8, i8* %tmp2
1102 switch i8 %tmp3, label %bb7 [
1103 i8 42, label %bb4
1104 i8 76, label %bb4
1105 i8 108, label %bb4
1106 i8 104, label %bb4
1107 ]
1108
1109bb4:
1110 %tmp5 = add i32 %tmp, 1
1111 br label %bb1
1112
1113bb7:
1114 ret void
1115}
Dan Gohmanb3aa1ec2015-12-16 19:06:41 +00001116
1117; A block can be "branched to" from another even if it is also reachable via
1118; fallthrough from the other. This would normally be optimized away, so use
1119; optnone to disable optimizations to test this case.
1120
1121; CHECK-LABEL: test13:
Dan Gohmanb6fd39a2016-01-19 16:59:23 +00001122; CHECK-NEXT: .local i32{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001123; CHECK: block{{$}}
1124; CHECK: br_if $pop4, 0{{$}}
Dan Gohmanb3aa1ec2015-12-16 19:06:41 +00001125; CHECK-NEXT: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +00001126; CHECK-NEXT: .LBB22_2:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001127; CHECK-NEXT: end_block{{$}}
1128; CHECK: block{{$}}
1129; CHECK-NEXT: br_if $0, 0{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +00001130; CHECK: .LBB22_4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001131; CHECK-NEXT: end_block{{$}}
1132; CHECK: block{{$}}
1133; CHECK: br_if $pop6, 0{{$}}
1134; CHECK-NEXT: end_block{{$}}
Dan Gohmanb3aa1ec2015-12-16 19:06:41 +00001135; CHECK-NEXT: unreachable{{$}}
1136; OPT-LABEL: test13:
Dan Gohmanb6fd39a2016-01-19 16:59:23 +00001137; OPT-NEXT: .local i32{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001138; OPT: block{{$}}
1139; OPT: br_if $pop4, 0{{$}}
Dan Gohmanb3aa1ec2015-12-16 19:06:41 +00001140; OPT-NEXT: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +00001141; OPT-NEXT: .LBB22_2:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001142; OPT-NEXT: end_block{{$}}
1143; OPT: block{{$}}
1144; OPT-NEXT: br_if $0, 0{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +00001145; OPT: .LBB22_4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001146; OPT-NEXT: end_block{{$}}
1147; OPT: block{{$}}
1148; OPT: br_if $pop6, 0{{$}}
1149; OPT-NEXT: end_block{{$}}
Dan Gohmanb3aa1ec2015-12-16 19:06:41 +00001150; OPT-NEXT: unreachable{{$}}
1151define void @test13() noinline optnone {
1152bb:
1153 br i1 undef, label %bb5, label %bb2
1154bb1:
1155 unreachable
1156bb2:
1157 br i1 undef, label %bb3, label %bb4
1158bb3:
1159 br label %bb4
1160bb4:
1161 %tmp = phi i1 [ false, %bb2 ], [ false, %bb3 ]
1162 br i1 %tmp, label %bb1, label %bb1
1163bb5:
1164 ret void
1165}
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001166
1167; Test a case with a single-block loop that has another loop
1168; as a successor. The end_loop for the first loop should go
1169; before the loop for the second.
1170
1171; CHECK-LABEL: test14:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001172; CHECK-NEXT: .LBB23_1:{{$}}
1173; CHECK-NEXT: loop{{$}}
Dan Gohmanb6fd39a2016-01-19 16:59:23 +00001174; CHECK-NEXT: i32.const $push0=, 0{{$}}
1175; CHECK-NEXT: br_if $pop0, 0{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001176; CHECK-NEXT: .LBB23_2:{{$}}
1177; CHECK-NEXT: end_loop{{$}}
1178; CHECK-NEXT: loop{{$}}
Dan Gohmanb6fd39a2016-01-19 16:59:23 +00001179; CHECK-NEXT: i32.const $push1=, 0{{$}}
1180; CHECK-NEXT: i32.const $push2=, 0{{$}}
1181; CHECK-NEXT: br_if $pop2, 0{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001182; CHECK-NEXT: end_loop{{$}}
1183; CHECK-NEXT: return{{$}}
1184define void @test14() {
1185bb:
1186 br label %bb1
1187
1188bb1:
1189 %tmp = bitcast i1 undef to i1
1190 br i1 %tmp, label %bb3, label %bb1
1191
1192bb3:
1193 br label %bb4
1194
1195bb4:
1196 br i1 undef, label %bb7, label %bb48
1197
1198bb7:
1199 br i1 undef, label %bb12, label %bb12
1200
1201bb12:
1202 br i1 undef, label %bb17, label %bb17
1203
1204bb17:
1205 br i1 undef, label %bb22, label %bb22
1206
1207bb22:
1208 br i1 undef, label %bb27, label %bb27
1209
1210bb27:
1211 br i1 undef, label %bb30, label %bb30
1212
1213bb30:
1214 br i1 undef, label %bb35, label %bb35
1215
1216bb35:
1217 br i1 undef, label %bb38, label %bb38
1218
1219bb38:
1220 br i1 undef, label %bb48, label %bb48
1221
1222bb48:
1223 %tmp49 = bitcast i1 undef to i1
1224 br i1 %tmp49, label %bb3, label %bb50
1225
1226bb50:
1227 ret void
1228}