blob: 77f4b68fc31d0fb7bbf688dda9eb19d6906ed0d8 [file] [log] [blame]
Wouter van Oortmerssen8a9cb242018-08-27 15:45:51 +00001; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers -disable-block-placement -verify-machineinstrs -fast-isel=false -machine-sink-split-probability-threshold=0 -cgp-freq-ratio-to-skip-merge=1000 | FileCheck %s
Dan Gohman950a13c2015-09-16 16:51:30 +00002
3; Test the CFG stackifier pass.
4
Dan Gohman2e644382016-05-10 17:39:48 +00005; Explicitly disable fast-isel, since it gets implicitly enabled in the
6; optnone test.
7
Dan Gohman0c6f5ac2016-01-07 03:19:23 +00008target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
Sam Clegga5908002018-05-10 17:49:11 +00009target triple = "wasm32-unknown-unknown"
Dan Gohman950a13c2015-09-16 16:51:30 +000010
11declare void @something()
12
13; Test that loops are made contiguous, even in the presence of split backedges.
14
Dan Gohmane51c0582015-10-06 00:27:55 +000015; CHECK-LABEL: test0:
16; CHECK: loop
Dan Gohman442bfce2016-02-16 16:22:41 +000017; CHECK-NEXT: block
Dan Gohman12de0b92016-05-17 20:19:47 +000018; CHECK: 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
Reid Klecknerbb865232016-08-15 18:51:42 +000023; CHECK-NEXT: i32.const
24; CHECK-NEXT: i32.add
Dan Gohman442bfce2016-02-16 16:22:41 +000025; CHECK-NEXT: call
26; CHECK-NEXT: br
27; CHECK-NEXT: .LBB0_4:
28; CHECK-NEXT: end_loop
Dan Gohman950a13c2015-09-16 16:51:30 +000029define void @test0(i32 %n) {
30entry:
31 br label %header
32
33header:
34 %i = phi i32 [ 0, %entry ], [ %i.next, %back ]
35 %i.next = add i32 %i, 1
36
37 %c = icmp slt i32 %i.next, %n
38 br i1 %c, label %back, label %exit
39
40exit:
41 ret void
42
43back:
44 call void @something()
45 br label %header
46}
47
48; Same as test0, but the branch condition is reversed.
49
Dan Gohmane51c0582015-10-06 00:27:55 +000050; CHECK-LABEL: test1:
51; CHECK: loop
Dan Gohman442bfce2016-02-16 16:22:41 +000052; CHECK-NEXT: block
Dan Gohman12de0b92016-05-17 20:19:47 +000053; CHECK: i32.lt_s
Dan Gohman8fe7e862015-12-14 22:51:54 +000054; CHECK-NEXT: br_if
Dan Gohman442bfce2016-02-16 16:22:41 +000055; CHECK-NEXT: return
56; CHECK-NEXT: .LBB1_3:
57; CHECK-NEXT: end_block
Reid Klecknerbb865232016-08-15 18:51:42 +000058; CHECK-NEXT: i32.const
59; CHECK-NEXT: i32.add
Dan Gohman442bfce2016-02-16 16:22:41 +000060; CHECK-NEXT: call
61; CHECK-NEXT: br
62; CHECK-NEXT: .LBB1_4:
63; CHECK-NEXT: end_loop
Dan Gohman950a13c2015-09-16 16:51:30 +000064define void @test1(i32 %n) {
65entry:
66 br label %header
67
68header:
69 %i = phi i32 [ 0, %entry ], [ %i.next, %back ]
70 %i.next = add i32 %i, 1
71
72 %c = icmp sge i32 %i.next, %n
73 br i1 %c, label %exit, label %back
74
75exit:
76 ret void
77
78back:
79 call void @something()
80 br label %header
81}
82
83; Test that a simple loop is handled as expected.
84
Dan Gohmane51c0582015-10-06 00:27:55 +000085; CHECK-LABEL: test2:
Dan Gohman8f59cf72016-01-06 18:29:35 +000086; CHECK-NOT: local
Dan Gohman2726b882016-10-06 22:29:32 +000087; CHECK: block {{$}}
Dan Gohman06b49582016-02-08 21:50:13 +000088; CHECK: br_if 0, {{[^,]+}}{{$}}
Dan Gohman0cfb5f82016-05-10 04:24:02 +000089; CHECK: .LBB2_{{[0-9]+}}:
Dan Gohman12de0b92016-05-17 20:19:47 +000090; CHECK: loop
91; CHECK: br_if 0, $pop{{[0-9]+}}{{$}}
Dan Gohman0cfb5f82016-05-10 04:24:02 +000092; CHECK: .LBB2_{{[0-9]+}}:
Dan Gohman12de0b92016-05-17 20:19:47 +000093; CHECK: end_loop
94; CHECK: end_block
Dan Gohmane51c0582015-10-06 00:27:55 +000095; CHECK: return{{$}}
Dan Gohman950a13c2015-09-16 16:51:30 +000096define void @test2(double* nocapture %p, i32 %n) {
97entry:
98 %cmp.4 = icmp sgt i32 %n, 0
99 br i1 %cmp.4, label %for.body.preheader, label %for.end
100
101for.body.preheader:
102 br label %for.body
103
104for.body:
105 %i.05 = phi i32 [ %inc, %for.body ], [ 0, %for.body.preheader ]
106 %arrayidx = getelementptr inbounds double, double* %p, i32 %i.05
107 %0 = load double, double* %arrayidx, align 8
108 %mul = fmul double %0, 3.200000e+00
109 store double %mul, double* %arrayidx, align 8
110 %inc = add nuw nsw i32 %i.05, 1
111 %exitcond = icmp eq i32 %inc, %n
112 br i1 %exitcond, label %for.end.loopexit, label %for.body
113
114for.end.loopexit:
115 br label %for.end
116
117for.end:
118 ret void
119}
120
Dan Gohmane51c0582015-10-06 00:27:55 +0000121; CHECK-LABEL: doublediamond:
Dan Gohman2726b882016-10-06 22:29:32 +0000122; CHECK: block {{$}}
123; CHECK-NEXT: block {{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000124; CHECK: br_if 0, ${{[^,]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000125; CHECK: br 1{{$}}
126; CHECK: .LBB3_2:
127; CHECK-NEXT: end_block{{$}}
Dan Gohman2726b882016-10-06 22:29:32 +0000128; CHECK: block {{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000129; CHECK: br_if 0, ${{[^,]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000130; CHECK: br 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000131; CHECK: .LBB3_4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000132; CHECK-NEXT: end_block{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000133; CHECK: .LBB3_5:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000134; CHECK-NEXT: end_block{{$}}
Dan Gohmanb6fd39a2016-01-19 16:59:23 +0000135; CHECK: i32.const $push{{[0-9]+}}=, 0{{$}}
136; CHECK-NEXT: return $pop{{[0-9]+}}{{$}}
Dan Gohman950a13c2015-09-16 16:51:30 +0000137define i32 @doublediamond(i32 %a, i32 %b, i32* %p) {
138entry:
139 %c = icmp eq i32 %a, 0
140 %d = icmp eq i32 %b, 0
141 store volatile i32 0, i32* %p
142 br i1 %c, label %true, label %false
143true:
144 store volatile i32 1, i32* %p
145 br label %exit
146false:
147 store volatile i32 2, i32* %p
148 br i1 %d, label %ft, label %ff
149ft:
150 store volatile i32 3, i32* %p
151 br label %exit
152ff:
153 store volatile i32 4, i32* %p
154 br label %exit
155exit:
156 store volatile i32 5, i32* %p
157 ret i32 0
158}
159
Dan Gohmane51c0582015-10-06 00:27:55 +0000160; CHECK-LABEL: triangle:
Dan Gohman2726b882016-10-06 22:29:32 +0000161; CHECK: block {{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000162; CHECK: br_if 0, $1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000163; CHECK: .LBB4_2:
Dan Gohmanc9623db2016-08-18 17:51:27 +0000164; CHECK: return
Dan Gohman950a13c2015-09-16 16:51:30 +0000165define i32 @triangle(i32* %p, i32 %a) {
166entry:
167 %c = icmp eq i32 %a, 0
168 store volatile i32 0, i32* %p
169 br i1 %c, label %true, label %exit
170true:
171 store volatile i32 1, i32* %p
172 br label %exit
173exit:
174 store volatile i32 2, i32* %p
175 ret i32 0
176}
177
Dan Gohmane51c0582015-10-06 00:27:55 +0000178; CHECK-LABEL: diamond:
Dan Gohman2726b882016-10-06 22:29:32 +0000179; CHECK: block {{$}}
180; CHECK: block {{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000181; CHECK: br_if 0, $1{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000182; CHECK: br 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000183; CHECK: .LBB5_2:
184; CHECK: .LBB5_3:
Dan Gohmanb6fd39a2016-01-19 16:59:23 +0000185; CHECK: i32.const $push{{[0-9]+}}=, 0{{$}}
186; CHECK-NEXT: return $pop{{[0-9]+}}{{$}}
Dan Gohman950a13c2015-09-16 16:51:30 +0000187define i32 @diamond(i32* %p, i32 %a) {
188entry:
189 %c = icmp eq i32 %a, 0
190 store volatile i32 0, i32* %p
191 br i1 %c, label %true, label %false
192true:
193 store volatile i32 1, i32* %p
194 br label %exit
195false:
196 store volatile i32 2, i32* %p
197 br label %exit
198exit:
199 store volatile i32 3, i32* %p
200 ret i32 0
201}
202
Dan Gohmane51c0582015-10-06 00:27:55 +0000203; CHECK-LABEL: single_block:
Dan Gohman950a13c2015-09-16 16:51:30 +0000204; CHECK-NOT: br
Dan Gohman81719f82015-11-25 16:55:01 +0000205; CHECK: return $pop{{[0-9]+}}{{$}}
Dan Gohman950a13c2015-09-16 16:51:30 +0000206define i32 @single_block(i32* %p) {
207entry:
208 store volatile i32 0, i32* %p
209 ret i32 0
210}
211
Dan Gohmane51c0582015-10-06 00:27:55 +0000212; CHECK-LABEL: minimal_loop:
Dan Gohman950a13c2015-09-16 16:51:30 +0000213; CHECK-NOT: br
Dan Gohmana4730cf2016-01-07 18:49:53 +0000214; CHECK: .LBB7_1:
Dan Gohman2726b882016-10-06 22:29:32 +0000215; CHECK: loop i32
Dan Gohman7f1bdb22016-10-06 22:08:28 +0000216; CHECK: i32.store 0($0), $pop{{[0-9]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000217; CHECK: br 0{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000218; CHECK: .LBB7_2:
Dan Gohman2726b882016-10-06 22:29:32 +0000219define i32 @minimal_loop(i32* %p) {
Dan Gohman950a13c2015-09-16 16:51:30 +0000220entry:
221 store volatile i32 0, i32* %p
222 br label %loop
223loop:
224 store volatile i32 1, i32* %p
225 br label %loop
226}
227
Dan Gohmane51c0582015-10-06 00:27:55 +0000228; CHECK-LABEL: simple_loop:
Dan Gohman950a13c2015-09-16 16:51:30 +0000229; CHECK-NOT: br
Dan Gohmana4730cf2016-01-07 18:49:53 +0000230; CHECK: .LBB8_1:
Dan Gohman2726b882016-10-06 22:29:32 +0000231; CHECK: loop {{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000232; CHECK: br_if 0, $pop{{[0-9]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000233; CHECK-NEXT: end_loop{{$}}
Dan Gohmanb6fd39a2016-01-19 16:59:23 +0000234; CHECK: i32.const $push{{[0-9]+}}=, 0{{$}}
235; CHECK-NEXT: return $pop{{[0-9]+}}{{$}}
Dan Gohman950a13c2015-09-16 16:51:30 +0000236define i32 @simple_loop(i32* %p, i32 %a) {
237entry:
238 %c = icmp eq i32 %a, 0
239 store volatile i32 0, i32* %p
240 br label %loop
241loop:
242 store volatile i32 1, i32* %p
243 br i1 %c, label %loop, label %exit
244exit:
245 store volatile i32 2, i32* %p
246 ret i32 0
247}
248
Dan Gohmane51c0582015-10-06 00:27:55 +0000249; CHECK-LABEL: doubletriangle:
Dan Gohman2726b882016-10-06 22:29:32 +0000250; CHECK: block {{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000251; CHECK: br_if 0, $0{{$}}
Dan Gohman2726b882016-10-06 22:29:32 +0000252; CHECK: block {{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000253; CHECK: br_if 0, $1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000254; CHECK: .LBB9_3:
255; CHECK: .LBB9_4:
Dan Gohmanc9623db2016-08-18 17:51:27 +0000256; CHECK: return
Dan Gohman950a13c2015-09-16 16:51:30 +0000257define i32 @doubletriangle(i32 %a, i32 %b, i32* %p) {
258entry:
259 %c = icmp eq i32 %a, 0
260 %d = icmp eq i32 %b, 0
261 store volatile i32 0, i32* %p
262 br i1 %c, label %true, label %exit
263true:
264 store volatile i32 2, i32* %p
265 br i1 %d, label %tt, label %tf
266tt:
267 store volatile i32 3, i32* %p
268 br label %tf
269tf:
270 store volatile i32 4, i32* %p
271 br label %exit
272exit:
273 store volatile i32 5, i32* %p
274 ret i32 0
275}
276
Dan Gohmane51c0582015-10-06 00:27:55 +0000277; CHECK-LABEL: ifelse_earlyexits:
Dan Gohman2726b882016-10-06 22:29:32 +0000278; CHECK: block {{$}}
279; CHECK: block {{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000280; CHECK: br_if 0, $0{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000281; CHECK: br 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000282; CHECK: .LBB10_2:
Dan Gohman06b49582016-02-08 21:50:13 +0000283; CHECK: br_if 0, $1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000284; CHECK: .LBB10_4:
Dan Gohmanb6fd39a2016-01-19 16:59:23 +0000285; CHECK: i32.const $push{{[0-9]+}}=, 0{{$}}
286; CHECK-NEXT: return $pop{{[0-9]+}}{{$}}
Dan Gohman950a13c2015-09-16 16:51:30 +0000287define i32 @ifelse_earlyexits(i32 %a, i32 %b, i32* %p) {
288entry:
289 %c = icmp eq i32 %a, 0
290 %d = icmp eq i32 %b, 0
291 store volatile i32 0, i32* %p
292 br i1 %c, label %true, label %false
293true:
294 store volatile i32 1, i32* %p
295 br label %exit
296false:
297 store volatile i32 2, i32* %p
298 br i1 %d, label %ft, label %exit
299ft:
300 store volatile i32 3, i32* %p
301 br label %exit
302exit:
303 store volatile i32 4, i32* %p
304 ret i32 0
305}
Dan Gohmane3e4a5f2015-10-02 21:11:36 +0000306
Dan Gohman32807932015-11-23 16:19:56 +0000307; CHECK-LABEL: doublediamond_in_a_loop:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000308; CHECK: .LBB11_1:
Dan Gohman2726b882016-10-06 22:29:32 +0000309; CHECK: loop i32{{$}}
310; CHECK: block {{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000311; CHECK: br_if 0, $0{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000312; CHECK: br 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000313; CHECK: .LBB11_3:
Dan Gohman0cfb5f82016-05-10 04:24:02 +0000314; CHECK: end_block{{$}}
Dan Gohman2726b882016-10-06 22:29:32 +0000315; CHECK: block {{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000316; CHECK: br_if 0, $1{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000317; CHECK: br 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000318; CHECK: .LBB11_5:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000319; CHECK: br 0{{$}}
Dan Gohman0cfb5f82016-05-10 04:24:02 +0000320; CHECK: .LBB11_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000321; CHECK-NEXT: end_loop{{$}}
Dan Gohman2726b882016-10-06 22:29:32 +0000322define i32 @doublediamond_in_a_loop(i32 %a, i32 %b, i32* %p) {
Dan Gohman32807932015-11-23 16:19:56 +0000323entry:
324 br label %header
325header:
326 %c = icmp eq i32 %a, 0
327 %d = icmp eq i32 %b, 0
328 store volatile i32 0, i32* %p
329 br i1 %c, label %true, label %false
330true:
331 store volatile i32 1, i32* %p
332 br label %exit
333false:
334 store volatile i32 2, i32* %p
335 br i1 %d, label %ft, label %ff
336ft:
337 store volatile i32 3, i32* %p
338 br label %exit
339ff:
340 store volatile i32 4, i32* %p
341 br label %exit
342exit:
343 store volatile i32 5, i32* %p
344 br label %header
345}
346
Dan Gohmane3e4a5f2015-10-02 21:11:36 +0000347; Test that nested loops are handled.
348
Dan Gohman8fe7e862015-12-14 22:51:54 +0000349; CHECK-LABEL: test3:
350; CHECK: loop
351; CHECK-NEXT: br_if
Dan Gohmana4730cf2016-01-07 18:49:53 +0000352; CHECK-NEXT: .LBB{{[0-9]+}}_{{[0-9]+}}:
Dan Gohman8fe7e862015-12-14 22:51:54 +0000353; CHECK-NEXT: loop
Dan Gohmane3e4a5f2015-10-02 21:11:36 +0000354declare void @bar()
Dan Gohmane3e4a5f2015-10-02 21:11:36 +0000355define void @test3(i32 %w) {
356entry:
357 br i1 undef, label %outer.ph, label %exit
358
359outer.ph:
360 br label %outer
361
362outer:
363 %tobool = icmp eq i32 undef, 0
364 br i1 %tobool, label %inner, label %unreachable
365
366unreachable:
367 unreachable
368
369inner:
370 %c = icmp eq i32 undef, %w
371 br i1 %c, label %if.end, label %inner
372
373exit:
374 ret void
375
376if.end:
377 call void @bar()
378 br label %outer
379}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000380
381; Test switch lowering and block placement.
382
383; CHECK-LABEL: test4:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +0000384; CHECK-NEXT: .functype test4 (i32) -> (){{$}}
Dan Gohman2726b882016-10-06 22:29:32 +0000385; CHECK: block {{$}}
386; CHECK-NEXT: block {{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000387; CHECK: br_if 0, $pop{{[0-9]+}}{{$}}
Dan Gohmand85ab7f2016-02-18 06:32:53 +0000388; CHECK: br_if 1, $pop{{[0-9]+}}{{$}}
389; CHECK: br 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000390; CHECK-NEXT: .LBB13_3:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000391; CHECK-NEXT: end_block{{$}}
Dan Gohman2726b882016-10-06 22:29:32 +0000392; CHECK-NEXT: block {{$}}
Dan Gohmand85ab7f2016-02-18 06:32:53 +0000393; CHECK: br_if 0, $pop{{[0-9]+}}{{$}}
394; CHECK: br_if 1, $pop{{[0-9]+}}{{$}}
395; CHECK-NEXT: .LBB13_5:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000396; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000397; CHECK-NEXT: return{{$}}
Dan Gohmand85ab7f2016-02-18 06:32:53 +0000398; CHECK-NEXT: .LBB13_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000399; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000400; CHECK-NEXT: return{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000401define void @test4(i32 %t) {
402entry:
403 switch i32 %t, label %default [
404 i32 0, label %bb2
405 i32 2, label %bb2
406 i32 4, label %bb1
407 i32 622, label %bb0
408 ]
409
410bb0:
411 ret void
412
413bb1:
414 ret void
415
416bb2:
417 ret void
418
419default:
420 ret void
421}
422
423; Test a case where the BLOCK needs to be placed before the LOOP in the
424; same basic block.
425
426; CHECK-LABEL: test5:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000427; CHECK: .LBB14_1:
Dan Gohman2726b882016-10-06 22:29:32 +0000428; CHECK-NEXT: block {{$}}
429; CHECK-NEXT: loop {{$}}
Dan Gohman3a643e82016-10-06 22:10:23 +0000430; CHECK: br_if 1, {{[^,]+}}{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000431; CHECK: br_if 0, {{[^,]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000432; CHECK-NEXT: end_loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000433; CHECK: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000434; CHECK-NEXT: .LBB14_4:
Dan Gohman8fe7e862015-12-14 22:51:54 +0000435; CHECK: return{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000436define void @test5(i1 %p, i1 %q) {
437entry:
438 br label %header
439
440header:
441 store volatile i32 0, i32* null
442 br i1 %p, label %more, label %alt
443
444more:
445 store volatile i32 1, i32* null
446 br i1 %q, label %header, label %return
447
448alt:
449 store volatile i32 2, i32* null
450 ret void
451
452return:
453 store volatile i32 3, i32* null
454 ret void
455}
456
457; Test an interesting case of a loop with multiple exits, which
458; aren't to layout successors of the loop, and one of which is to a successors
459; which has another predecessor.
460
461; CHECK-LABEL: test6:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000462; CHECK: .LBB15_1:
Dan Gohman2726b882016-10-06 22:29:32 +0000463; CHECK-NEXT: block {{$}}
464; CHECK-NEXT: block {{$}}
465; CHECK-NEXT: loop {{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000466; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000467; CHECK: br_if 2, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000468; CHECK-NOT: block
Dan Gohman3a643e82016-10-06 22:10:23 +0000469; CHECK: br_if 1, {{[^,]+}}{{$}}
470; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000471; CHECK: br_if 0, {{[^,]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000472; CHECK-NEXT: end_loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000473; CHECK-NOT: block
474; CHECK: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000475; CHECK-NEXT: .LBB15_5:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000476; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000477; CHECK-NOT: block
Dan Gohmana4730cf2016-01-07 18:49:53 +0000478; CHECK: .LBB15_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000479; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000480; CHECK-NOT: block
481; CHECK: return{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000482define void @test6(i1 %p, i1 %q) {
483entry:
484 br label %header
485
486header:
487 store volatile i32 0, i32* null
488 br i1 %p, label %more, label %second
489
490more:
491 store volatile i32 1, i32* null
492 br i1 %q, label %evenmore, label %first
493
494evenmore:
495 store volatile i32 1, i32* null
496 br i1 %q, label %header, label %return
497
498return:
499 store volatile i32 2, i32* null
500 ret void
501
502first:
503 store volatile i32 3, i32* null
504 br label %second
505
506second:
507 store volatile i32 4, i32* null
508 ret void
509}
510
511; Test a case where there are multiple backedges and multiple loop exits
512; that end in unreachable.
513
514; CHECK-LABEL: test7:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000515; CHECK: .LBB16_1:
Dan Gohman2726b882016-10-06 22:29:32 +0000516; CHECK-NEXT: loop {{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000517; CHECK-NOT: block
Dan Gohman2726b882016-10-06 22:29:32 +0000518; CHECK: block {{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000519; CHECK: br_if 0, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000520; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000521; CHECK: br_if 1, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000522; CHECK-NOT: block
523; CHECK: unreachable
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000524; CHECK-NEXT: .LBB16_4:
525; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000526; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000527; CHECK: br_if 0, {{[^,]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000528; CHECK-NEXT: end_loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000529; CHECK-NOT: block
530; CHECK: unreachable
Dan Gohman8fe7e862015-12-14 22:51:54 +0000531define void @test7(i1 %tobool2, i1 %tobool9) {
532entry:
533 store volatile i32 0, i32* null
534 br label %loop
535
536loop:
537 store volatile i32 1, i32* null
538 br i1 %tobool2, label %l1, label %l0
539
540l0:
541 store volatile i32 2, i32* null
542 br i1 %tobool9, label %loop, label %u0
543
544l1:
545 store volatile i32 3, i32* null
546 br i1 %tobool9, label %loop, label %u1
547
548u0:
549 store volatile i32 4, i32* null
550 unreachable
551
552u1:
553 store volatile i32 5, i32* null
554 unreachable
555}
556
557; Test an interesting case using nested loops and switches.
558
559; CHECK-LABEL: test8:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000560; CHECK: .LBB17_1:
Dan Gohman2726b882016-10-06 22:29:32 +0000561; CHECK-NEXT: loop i32{{$}}
Dan Gohmane5d3c152016-01-20 05:55:09 +0000562; CHECK-NEXT: i32.const $push{{[^,]+}}, 0{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000563; CHECK-NEXT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman0cfb5f82016-05-10 04:24:02 +0000564; CHECK-NEXT: br 0{{$}}
565; CHECK-NEXT: .LBB17_2:
566; CHECK-NEXT: end_loop{{$}}
Dan Gohman2726b882016-10-06 22:29:32 +0000567define i32 @test8() {
Dan Gohman8fe7e862015-12-14 22:51:54 +0000568bb:
569 br label %bb1
570
571bb1:
572 br i1 undef, label %bb2, label %bb3
573
574bb2:
575 switch i8 undef, label %bb1 [
576 i8 44, label %bb2
577 ]
578
579bb3:
580 switch i8 undef, label %bb1 [
581 i8 44, label %bb2
582 ]
583}
584
585; Test an interesting case using nested loops that share a bottom block.
586
587; CHECK-LABEL: test9:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000588; CHECK: .LBB18_1:
Dan Gohman2726b882016-10-06 22:29:32 +0000589; CHECK-NEXT: block {{$}}
590; CHECK-NEXT: loop {{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000591; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000592; CHECK: br_if 1, {{[^,]+}}{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000593; CHECK-NEXT: .LBB18_2:
Dan Gohman2726b882016-10-06 22:29:32 +0000594; CHECK-NEXT: loop {{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000595; CHECK-NOT: block
Dan Gohman2726b882016-10-06 22:29:32 +0000596; CHECK: block {{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000597; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000598; CHECK: br_if 0, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000599; CHECK-NOT: block
Dan Gohman3a643e82016-10-06 22:10:23 +0000600; CHECK: br_if 2, {{[^,]+}}{{$}}
Dan Gohmand85ab7f2016-02-18 06:32:53 +0000601; CHECK-NEXT: br 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000602; CHECK-NEXT: .LBB18_4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000603; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000604; CHECK-NOT: block
Dan Gohman3a643e82016-10-06 22:10:23 +0000605; CHECK: br_if 1, {{[^,]+}}{{$}}
Dan Gohmand85ab7f2016-02-18 06:32:53 +0000606; CHECK-NEXT: br 0{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000607; CHECK-NEXT: .LBB18_5:
Dan Gohman8fe7e862015-12-14 22:51:54 +0000608; CHECK-NOT: block
Dan Gohman3a643e82016-10-06 22:10:23 +0000609; CHECK: end_block
610; CHECK-NOT: block
Dan Gohman8fe7e862015-12-14 22:51:54 +0000611; CHECK: return{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000612declare i1 @a()
613define void @test9() {
614entry:
615 store volatile i32 0, i32* null
616 br label %header
617
618header:
619 store volatile i32 1, i32* null
620 %call4 = call i1 @a()
621 br i1 %call4, label %header2, label %end
622
623header2:
624 store volatile i32 2, i32* null
625 %call = call i1 @a()
626 br i1 %call, label %if.then, label %if.else
627
628if.then:
629 store volatile i32 3, i32* null
630 %call3 = call i1 @a()
631 br i1 %call3, label %header2, label %header
632
633if.else:
634 store volatile i32 4, i32* null
635 %call2 = call i1 @a()
636 br i1 %call2, label %header2, label %header
637
638end:
639 store volatile i32 5, i32* null
640 ret void
641}
642
643; Test an interesting case involving nested loops sharing a loop bottom,
644; and loop exits to a block with unreachable.
645
646; CHECK-LABEL: test10:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000647; CHECK: .LBB19_1:
Dan Gohman2726b882016-10-06 22:29:32 +0000648; CHECK-NEXT: loop {{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000649; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000650; CHECK: br_if 0, {{[^,]+}}{{$}}
JF Bastienc6ba5ea2016-04-05 17:01:52 +0000651; CHECK: .LBB19_3:
Dan Gohman2726b882016-10-06 22:29:32 +0000652; CHECK-NEXT: block {{$}}
653; CHECK-NEXT: loop {{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000654; CHECK-NOT: block
JF Bastienc6ba5ea2016-04-05 17:01:52 +0000655; CHECK: .LBB19_4:
Dan Gohman2726b882016-10-06 22:29:32 +0000656; CHECK-NEXT: loop {{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000657; CHECK-NOT: block
Dan Gohman89bf88c2017-11-15 21:38:33 +0000658; CHECK: br_if 0, {{[^,]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000659; CHECK-NEXT: end_loop{{$}}
Dan Gohman89bf88c2017-11-15 21:38:33 +0000660; CHECK: br_if 1, {{[^,]+}}{{$}}
661; CHECK-NOT: block
662; CHECK: br_if 0, {{[^,]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000663; CHECK-NEXT: end_loop{{$}}
Dan Gohman89bf88c2017-11-15 21:38:33 +0000664; CHECK-NOT: block
665; CHECK: br_if 1, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000666; CHECK-NEXT: return{{$}}
Dan Gohman89bf88c2017-11-15 21:38:33 +0000667; CHECK-NEXT: .LBB19_9:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000668; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000669; CHECK-NOT: block
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000670; CHECK: br 0{{$}}
Dan Gohman89bf88c2017-11-15 21:38:33 +0000671; CHECK-NEXT: .LBB19_10:
Dan Gohman8fe7e862015-12-14 22:51:54 +0000672define void @test10() {
673bb0:
674 br label %bb1
675
676bb1:
677 %tmp = phi i32 [ 2, %bb0 ], [ 3, %bb3 ]
678 %tmp3 = phi i32 [ undef, %bb0 ], [ %tmp11, %bb3 ]
679 %tmp4 = icmp eq i32 %tmp3, 0
680 br i1 %tmp4, label %bb4, label %bb2
681
682bb2:
683 br label %bb3
684
685bb3:
686 %tmp11 = phi i32 [ 1, %bb5 ], [ 0, %bb2 ]
687 br label %bb1
688
689bb4:
690 %tmp6 = phi i32 [ %tmp9, %bb5 ], [ 4, %bb1 ]
691 %tmp7 = phi i32 [ %tmp6, %bb5 ], [ %tmp, %bb1 ]
692 br label %bb5
693
694bb5:
695 %tmp9 = phi i32 [ %tmp6, %bb5 ], [ %tmp7, %bb4 ]
696 switch i32 %tmp9, label %bb2 [
697 i32 0, label %bb5
698 i32 1, label %bb6
699 i32 3, label %bb4
700 i32 4, label %bb3
701 ]
702
703bb6:
704 ret void
705}
706
707; Test a CFG DAG with interesting merging.
708
709; CHECK-LABEL: test11:
Dan Gohman2726b882016-10-06 22:29:32 +0000710; CHECK: block {{$}}
711; CHECK-NEXT: block {{$}}
712; CHECK-NEXT: block {{$}}
713; CHECK-NEXT: block {{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000714; CHECK: br_if 0, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000715; CHECK-NOT: block
Dan Gohman2726b882016-10-06 22:29:32 +0000716; CHECK: block {{$}}
Dan Gohmanc9623db2016-08-18 17:51:27 +0000717; CHECK-NEXT: i32.const
Dan Gohman06b49582016-02-08 21:50:13 +0000718; CHECK-NEXT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000719; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000720; CHECK: br_if 2, {{[^,]+}}{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000721; CHECK-NEXT: .LBB20_3:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000722; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000723; CHECK-NOT: block
724; CHECK: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000725; CHECK-NEXT: .LBB20_4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000726; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000727; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000728; CHECK: br_if 1, {{[^,]+}}{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +0000729; CHECK-NOT: block
730; CHECK: br_if 2, {{[^,]+}}{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000731; CHECK-NEXT: .LBB20_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000732; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000733; CHECK-NOT: block
734; CHECK: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000735; CHECK-NEXT: .LBB20_7:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000736; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000737; CHECK-NOT: block
738; CHECK: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000739; CHECK-NEXT: .LBB20_8:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000740; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000741; CHECK-NOT: block
742; CHECK: return{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000743define void @test11() {
744bb0:
745 store volatile i32 0, i32* null
746 br i1 undef, label %bb1, label %bb4
747bb1:
748 store volatile i32 1, i32* null
749 br i1 undef, label %bb3, label %bb2
750bb2:
751 store volatile i32 2, i32* null
752 br i1 undef, label %bb3, label %bb7
753bb3:
754 store volatile i32 3, i32* null
755 ret void
756bb4:
757 store volatile i32 4, i32* null
758 br i1 undef, label %bb8, label %bb5
759bb5:
760 store volatile i32 5, i32* null
761 br i1 undef, label %bb6, label %bb7
762bb6:
763 store volatile i32 6, i32* null
764 ret void
765bb7:
766 store volatile i32 7, i32* null
767 ret void
768bb8:
769 store volatile i32 8, i32* null
770 ret void
771}
772
773; CHECK-LABEL: test12:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000774; CHECK: .LBB21_1:
Dan Gohman2726b882016-10-06 22:29:32 +0000775; CHECK-NEXT: block {{$}}
776; CHECK-NEXT: loop {{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000777; CHECK-NOT: block
Dan Gohman2726b882016-10-06 22:29:32 +0000778; CHECK: block {{$}}
779; CHECK-NEXT: block {{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000780; CHECK: br_if 0, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000781; CHECK-NOT: block
Dan Gohman442bfce2016-02-16 16:22:41 +0000782; CHECK: br_if 1, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000783; CHECK-NOT: block
Dan Gohman442bfce2016-02-16 16:22:41 +0000784; CHECK: br_if 1, {{[^,]+}}{{$}}
785; CHECK-NEXT: br 3{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000786; CHECK-NEXT: .LBB21_4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000787; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000788; CHECK-NOT: block
Dan Gohman442bfce2016-02-16 16:22:41 +0000789; CHECK: br_if 0, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000790; CHECK-NOT: block
Dan Gohman442bfce2016-02-16 16:22:41 +0000791; CHECK: br_if 2, {{[^,]+}}{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000792; CHECK-NEXT: .LBB21_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000793; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000794; CHECK-NOT: block
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000795; CHECK: br 0{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +0000796; CHECK-NEXT: .LBB21_7:
797; CHECK-NEXT: end_loop{{$}}
Dan Gohman3a643e82016-10-06 22:10:23 +0000798; CHECK-NEXT: end_block{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +0000799; CHECK-NEXT: return{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000800define void @test12(i8* %arg) {
801bb:
802 br label %bb1
803
804bb1:
805 %tmp = phi i32 [ 0, %bb ], [ %tmp5, %bb4 ]
806 %tmp2 = getelementptr i8, i8* %arg, i32 %tmp
807 %tmp3 = load i8, i8* %tmp2
808 switch i8 %tmp3, label %bb7 [
809 i8 42, label %bb4
810 i8 76, label %bb4
811 i8 108, label %bb4
812 i8 104, label %bb4
813 ]
814
815bb4:
816 %tmp5 = add i32 %tmp, 1
817 br label %bb1
818
819bb7:
820 ret void
821}
Dan Gohmanb3aa1ec2015-12-16 19:06:41 +0000822
823; A block can be "branched to" from another even if it is also reachable via
824; fallthrough from the other. This would normally be optimized away, so use
825; optnone to disable optimizations to test this case.
826
827; CHECK-LABEL: test13:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +0000828; CHECK: block {{$}}
Dan Gohman2726b882016-10-06 22:29:32 +0000829; CHECK-NEXT: block {{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +0000830; CHECK: br_if 0, $pop0{{$}}
Dan Gohman2726b882016-10-06 22:29:32 +0000831; CHECK: block {{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +0000832; CHECK: br_if 0, $pop3{{$}}
833; CHECK: .LBB22_3:
834; CHECK-NEXT: end_block{{$}}
835; CHECK: br_if 1, $pop{{[0-9]+}}{{$}}
836; CHECK-NEXT: br 1{{$}}
837; CHECK-NEXT: .LBB22_4:
838; CHECK-NEXT: end_block{{$}}
Dan Gohmanb3aa1ec2015-12-16 19:06:41 +0000839; CHECK-NEXT: return{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +0000840; CHECK-NEXT: .LBB22_5:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000841; CHECK-NEXT: end_block{{$}}
Dan Gohmanb3aa1ec2015-12-16 19:06:41 +0000842; CHECK-NEXT: unreachable{{$}}
Dan Gohmanb3aa1ec2015-12-16 19:06:41 +0000843define void @test13() noinline optnone {
844bb:
845 br i1 undef, label %bb5, label %bb2
846bb1:
847 unreachable
848bb2:
849 br i1 undef, label %bb3, label %bb4
850bb3:
851 br label %bb4
852bb4:
853 %tmp = phi i1 [ false, %bb2 ], [ false, %bb3 ]
854 br i1 %tmp, label %bb1, label %bb1
855bb5:
856 ret void
857}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000858
859; Test a case with a single-block loop that has another loop
860; as a successor. The end_loop for the first loop should go
861; before the loop for the second.
862
863; CHECK-LABEL: test14:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +0000864; CHECK: .LBB23_1:{{$}}
Dan Gohman2726b882016-10-06 22:29:32 +0000865; CHECK-NEXT: loop {{$}}
Dan Gohmanb6fd39a2016-01-19 16:59:23 +0000866; CHECK-NEXT: i32.const $push0=, 0{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000867; CHECK-NEXT: br_if 0, $pop0{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000868; CHECK-NEXT: end_loop{{$}}
Dan Gohman0cfb5f82016-05-10 04:24:02 +0000869; CHECK-NEXT: .LBB23_3:{{$}}
Dan Gohman2726b882016-10-06 22:29:32 +0000870; CHECK-NEXT: loop {{$}}
Dan Gohmanb6fd39a2016-01-19 16:59:23 +0000871; CHECK-NEXT: i32.const $push1=, 0{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000872; CHECK-NEXT: br_if 0, $pop1{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000873; CHECK-NEXT: end_loop{{$}}
874; CHECK-NEXT: return{{$}}
875define void @test14() {
876bb:
877 br label %bb1
878
879bb1:
880 %tmp = bitcast i1 undef to i1
881 br i1 %tmp, label %bb3, label %bb1
882
883bb3:
884 br label %bb4
885
886bb4:
887 br i1 undef, label %bb7, label %bb48
888
889bb7:
890 br i1 undef, label %bb12, label %bb12
891
892bb12:
893 br i1 undef, label %bb17, label %bb17
894
895bb17:
896 br i1 undef, label %bb22, label %bb22
897
898bb22:
899 br i1 undef, label %bb27, label %bb27
900
901bb27:
902 br i1 undef, label %bb30, label %bb30
903
904bb30:
905 br i1 undef, label %bb35, label %bb35
906
907bb35:
908 br i1 undef, label %bb38, label %bb38
909
910bb38:
911 br i1 undef, label %bb48, label %bb48
912
913bb48:
914 %tmp49 = bitcast i1 undef to i1
915 br i1 %tmp49, label %bb3, label %bb50
916
917bb50:
918 ret void
919}
Dan Gohmana187ab22016-02-12 21:19:25 +0000920
921; Test that a block boundary which ends one block, begins another block, and
922; also begins a loop, has the markers placed in the correct order.
923
924; CHECK-LABEL: test15:
925; CHECK: block
Dan Gohmana187ab22016-02-12 21:19:25 +0000926; CHECK-NEXT: block
Dan Gohman442bfce2016-02-16 16:22:41 +0000927; CHECK: br_if 0, $pop{{.*}}{{$}}
Dan Gohmand85ab7f2016-02-18 06:32:53 +0000928; CHECK: .LBB24_2:
Dan Gohman2726b882016-10-06 22:29:32 +0000929; CHECK-NEXT: block {{$}}
930; CHECK-NEXT: block {{$}}
931; CHECK-NEXT: loop {{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +0000932; CHECK: br_if 1, $pop{{.*}}{{$}}
Dan Gohmand85ab7f2016-02-18 06:32:53 +0000933; CHECK: br_if 0, ${{.*}}{{$}}
934; CHECK-NEXT: br 2{{$}}
935; CHECK-NEXT: .LBB24_4:
Dan Gohman442bfce2016-02-16 16:22:41 +0000936; CHECK-NEXT: end_loop{{$}}
Dan Gohmand85ab7f2016-02-18 06:32:53 +0000937; CHECK: .LBB24_5:
Dan Gohman442bfce2016-02-16 16:22:41 +0000938; CHECK-NEXT: end_block{{$}}
939; CHECK: br_if 1, $pop{{.*}}{{$}}
940; CHECK: return{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +0000941; CHECK: .LBB24_7:
942; CHECK-NEXT: end_block{{$}}
Dan Gohmand85ab7f2016-02-18 06:32:53 +0000943; CHECK: .LBB24_8:
944; CHECK-NEXT: end_block{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +0000945; CHECK-NEXT: return{{$}}
Dan Gohmana187ab22016-02-12 21:19:25 +0000946%0 = type { i8, i32 }
947declare void @test15_callee0()
948declare void @test15_callee1()
949define void @test15() {
950bb:
951 %tmp1 = icmp eq i8 1, 0
952 br i1 %tmp1, label %bb2, label %bb14
953
954bb2:
955 %tmp3 = phi %0** [ %tmp6, %bb5 ], [ null, %bb ]
956 %tmp4 = icmp eq i32 0, 11
957 br i1 %tmp4, label %bb5, label %bb8
958
959bb5:
960 %tmp = bitcast i8* null to %0**
961 %tmp6 = getelementptr %0*, %0** %tmp3, i32 1
962 %tmp7 = icmp eq %0** %tmp6, null
963 br i1 %tmp7, label %bb10, label %bb2
964
965bb8:
966 %tmp9 = icmp eq %0** null, undef
967 br label %bb10
968
969bb10:
970 %tmp11 = phi %0** [ null, %bb8 ], [ %tmp, %bb5 ]
971 %tmp12 = icmp eq %0** null, %tmp11
972 br i1 %tmp12, label %bb15, label %bb13
973
974bb13:
975 call void @test15_callee0()
976 ret void
977
978bb14:
979 call void @test15_callee1()
980 ret void
981
982bb15:
983 ret void
984}