blob: cbb45611cec574f4e2aa4263bede3b8cf138e9aa [file] [log] [blame]
Dan Gohman2e644382016-05-10 17:39:48 +00001; RUN: llc < %s -asm-verbose=false -disable-block-placement -verify-machineinstrs -fast-isel=false | FileCheck %s
2; RUN: llc < %s -asm-verbose=false -verify-machineinstrs -fast-isel=false | FileCheck -check-prefix=OPT %s
Dan Gohman950a13c2015-09-16 16:51:30 +00003
4; Test the CFG stackifier pass.
5
Dan Gohman2e644382016-05-10 17:39:48 +00006; Explicitly disable fast-isel, since it gets implicitly enabled in the
7; optnone test.
8
Dan Gohman0c6f5ac2016-01-07 03:19:23 +00009target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
Dan Gohman950a13c2015-09-16 16:51:30 +000010target triple = "wasm32-unknown-unknown"
11
12declare void @something()
13
14; Test that loops are made contiguous, even in the presence of split backedges.
15
Dan Gohmane51c0582015-10-06 00:27:55 +000016; CHECK-LABEL: test0:
17; CHECK: loop
Dan Gohman442bfce2016-02-16 16:22:41 +000018; CHECK-NEXT: block
Dan Gohman12de0b92016-05-17 20:19:47 +000019; CHECK-NEXT: i32.const
20; CHECK-NEXT: i32.add
21; CHECK: i32.lt_s
Dan Gohman8fe7e862015-12-14 22:51:54 +000022; CHECK-NEXT: br_if
Dan Gohman442bfce2016-02-16 16:22:41 +000023; CHECK-NEXT: return
24; CHECK-NEXT: .LBB0_3:
25; CHECK-NEXT: end_block
26; CHECK-NEXT: call
27; CHECK-NEXT: br
28; CHECK-NEXT: .LBB0_4:
29; CHECK-NEXT: end_loop
Dan Gohmanf0b165a2015-12-05 03:03:35 +000030; OPT-LABEL: test0:
31; OPT: loop
Dan Gohman12de0b92016-05-17 20:19:47 +000032; OPT-NEXT: i32.const
33; OPT-NEXT: i32.add
34; OPT: i32.ge_s
Dan Gohman8fe7e862015-12-14 22:51:54 +000035; OPT-NEXT: br_if
Dan Gohmanf0b165a2015-12-05 03:03:35 +000036; OPT-NOT: br
37; OPT: call
Dan Gohman1d68e80f2016-01-12 19:14:46 +000038; OPT: br 0{{$}}
Dan Gohmanf0b165a2015-12-05 03:03:35 +000039; OPT: return{{$}}
Dan Gohman950a13c2015-09-16 16:51:30 +000040define void @test0(i32 %n) {
41entry:
42 br label %header
43
44header:
45 %i = phi i32 [ 0, %entry ], [ %i.next, %back ]
46 %i.next = add i32 %i, 1
47
48 %c = icmp slt i32 %i.next, %n
49 br i1 %c, label %back, label %exit
50
51exit:
52 ret void
53
54back:
55 call void @something()
56 br label %header
57}
58
59; Same as test0, but the branch condition is reversed.
60
Dan Gohmane51c0582015-10-06 00:27:55 +000061; CHECK-LABEL: test1:
62; CHECK: loop
Dan Gohman442bfce2016-02-16 16:22:41 +000063; CHECK-NEXT: block
Dan Gohman12de0b92016-05-17 20:19:47 +000064; CHECK-NEXT: i32.const
65; CHECK-NEXT: i32.add
66; CHECK: i32.lt_s
Dan Gohman8fe7e862015-12-14 22:51:54 +000067; CHECK-NEXT: br_if
Dan Gohman442bfce2016-02-16 16:22:41 +000068; CHECK-NEXT: return
69; CHECK-NEXT: .LBB1_3:
70; CHECK-NEXT: end_block
71; CHECK-NEXT: call
72; CHECK-NEXT: br
73; CHECK-NEXT: .LBB1_4:
74; CHECK-NEXT: end_loop
Dan Gohmanf0b165a2015-12-05 03:03:35 +000075; OPT-LABEL: test1:
76; OPT: loop
Dan Gohman12de0b92016-05-17 20:19:47 +000077; OPT-NEXT: i32.const
78; OPT-NEXT: i32.add
79; OPT: i32.ge_s
Dan Gohman8fe7e862015-12-14 22:51:54 +000080; OPT-NEXT: br_if
Dan Gohmanf0b165a2015-12-05 03:03:35 +000081; OPT-NOT: br
82; OPT: call
Dan Gohman1d68e80f2016-01-12 19:14:46 +000083; OPT: br 0{{$}}
Dan Gohmanf0b165a2015-12-05 03:03:35 +000084; OPT: return{{$}}
Dan Gohman950a13c2015-09-16 16:51:30 +000085define void @test1(i32 %n) {
86entry:
87 br label %header
88
89header:
90 %i = phi i32 [ 0, %entry ], [ %i.next, %back ]
91 %i.next = add i32 %i, 1
92
93 %c = icmp sge i32 %i.next, %n
94 br i1 %c, label %exit, label %back
95
96exit:
97 ret void
98
99back:
100 call void @something()
101 br label %header
102}
103
104; Test that a simple loop is handled as expected.
105
Dan Gohmane51c0582015-10-06 00:27:55 +0000106; CHECK-LABEL: test2:
Dan Gohman8f59cf72016-01-06 18:29:35 +0000107; CHECK-NOT: local
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000108; CHECK: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000109; CHECK: br_if 0, {{[^,]+}}{{$}}
Dan Gohman0cfb5f82016-05-10 04:24:02 +0000110; CHECK: .LBB2_{{[0-9]+}}:
Dan Gohman12de0b92016-05-17 20:19:47 +0000111; CHECK: loop
112; CHECK: br_if 0, $pop{{[0-9]+}}{{$}}
Dan Gohman0cfb5f82016-05-10 04:24:02 +0000113; CHECK: .LBB2_{{[0-9]+}}:
Dan Gohman12de0b92016-05-17 20:19:47 +0000114; CHECK: end_loop
115; CHECK: end_block
Dan Gohmane51c0582015-10-06 00:27:55 +0000116; CHECK: return{{$}}
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000117; OPT-LABEL: test2:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000118; OPT-NOT: local
119; OPT: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000120; OPT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman0cfb5f82016-05-10 04:24:02 +0000121; OPT: .LBB2_{{[0-9]+}}:
Dan Gohman12de0b92016-05-17 20:19:47 +0000122; OPT: loop
123; OPT: br_if 0, $pop{{[0-9]+}}{{$}}
Dan Gohman0cfb5f82016-05-10 04:24:02 +0000124; OPT: .LBB2_{{[0-9]+}}:
Dan Gohman12de0b92016-05-17 20:19:47 +0000125; OPT: end_loop
126; OPT: end_block
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000127; OPT: return{{$}}
Dan Gohman950a13c2015-09-16 16:51:30 +0000128define void @test2(double* nocapture %p, i32 %n) {
129entry:
130 %cmp.4 = icmp sgt i32 %n, 0
131 br i1 %cmp.4, label %for.body.preheader, label %for.end
132
133for.body.preheader:
134 br label %for.body
135
136for.body:
137 %i.05 = phi i32 [ %inc, %for.body ], [ 0, %for.body.preheader ]
138 %arrayidx = getelementptr inbounds double, double* %p, i32 %i.05
139 %0 = load double, double* %arrayidx, align 8
140 %mul = fmul double %0, 3.200000e+00
141 store double %mul, double* %arrayidx, align 8
142 %inc = add nuw nsw i32 %i.05, 1
143 %exitcond = icmp eq i32 %inc, %n
144 br i1 %exitcond, label %for.end.loopexit, label %for.body
145
146for.end.loopexit:
147 br label %for.end
148
149for.end:
150 ret void
151}
152
Dan Gohmane51c0582015-10-06 00:27:55 +0000153; CHECK-LABEL: doublediamond:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000154; CHECK: block{{$}}
155; CHECK-NEXT: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000156; CHECK: br_if 0, ${{[^,]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000157; CHECK: br 1{{$}}
158; CHECK: .LBB3_2:
159; CHECK-NEXT: end_block{{$}}
160; CHECK: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000161; CHECK: br_if 0, ${{[^,]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000162; CHECK: br 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000163; CHECK: .LBB3_4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000164; CHECK-NEXT: end_block{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000165; CHECK: .LBB3_5:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000166; CHECK-NEXT: end_block{{$}}
Dan Gohmanb6fd39a2016-01-19 16:59:23 +0000167; CHECK: i32.const $push{{[0-9]+}}=, 0{{$}}
168; CHECK-NEXT: return $pop{{[0-9]+}}{{$}}
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000169; OPT-LABEL: doublediamond:
Dan Gohman442bfce2016-02-16 16:22:41 +0000170; OPT: block{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000171; OPT-NEXT: block{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +0000172; OPT-NEXT: block{{$}}
173; OPT: br_if 0, ${{[^,]+}}{{$}}
174; OPT: br_if 1, ${{[^,]+}}{{$}}
175; OPT: br 2{{$}}
176; OPT-NEXT: .LBB3_3:
177; OPT-NEXT: end_block
178; OPT: br 1{{$}}
179; OPT-NEXT: .LBB3_4:
180; OPT: .LBB3_5:
181; OPT-NEXT: end_block
182; OPT: return $pop{{[0-9]+}}{{$}}
Dan Gohman950a13c2015-09-16 16:51:30 +0000183define i32 @doublediamond(i32 %a, i32 %b, i32* %p) {
184entry:
185 %c = icmp eq i32 %a, 0
186 %d = icmp eq i32 %b, 0
187 store volatile i32 0, i32* %p
188 br i1 %c, label %true, label %false
189true:
190 store volatile i32 1, i32* %p
191 br label %exit
192false:
193 store volatile i32 2, i32* %p
194 br i1 %d, label %ft, label %ff
195ft:
196 store volatile i32 3, i32* %p
197 br label %exit
198ff:
199 store volatile i32 4, i32* %p
200 br label %exit
201exit:
202 store volatile i32 5, i32* %p
203 ret i32 0
204}
205
Dan Gohmane51c0582015-10-06 00:27:55 +0000206; CHECK-LABEL: triangle:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000207; CHECK: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000208; CHECK: br_if 0, $1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000209; CHECK: .LBB4_2:
Dan Gohman4ba48162015-11-18 16:12:01 +0000210; CHECK: return ${{[0-9]+}}{{$}}
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000211; OPT-LABEL: triangle:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000212; OPT: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000213; OPT: br_if 0, $1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000214; OPT: .LBB4_2:
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000215; OPT: return ${{[0-9]+}}{{$}}
Dan Gohman950a13c2015-09-16 16:51:30 +0000216define i32 @triangle(i32* %p, i32 %a) {
217entry:
218 %c = icmp eq i32 %a, 0
219 store volatile i32 0, i32* %p
220 br i1 %c, label %true, label %exit
221true:
222 store volatile i32 1, i32* %p
223 br label %exit
224exit:
225 store volatile i32 2, i32* %p
226 ret i32 0
227}
228
Dan Gohmane51c0582015-10-06 00:27:55 +0000229; CHECK-LABEL: diamond:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000230; CHECK: block{{$}}
231; CHECK: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000232; CHECK: br_if 0, $1{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000233; CHECK: br 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000234; CHECK: .LBB5_2:
235; CHECK: .LBB5_3:
Dan Gohmanb6fd39a2016-01-19 16:59:23 +0000236; CHECK: i32.const $push{{[0-9]+}}=, 0{{$}}
237; CHECK-NEXT: return $pop{{[0-9]+}}{{$}}
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000238; OPT-LABEL: diamond:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000239; OPT: block{{$}}
240; OPT: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000241; OPT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000242; OPT: br 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000243; OPT: .LBB5_2:
244; OPT: .LBB5_3:
Dan Gohmanb6fd39a2016-01-19 16:59:23 +0000245; OPT: i32.const $push{{[0-9]+}}=, 0{{$}}
246; OPT-NEXT: return $pop{{[0-9]+}}{{$}}
Dan Gohman950a13c2015-09-16 16:51:30 +0000247define i32 @diamond(i32* %p, i32 %a) {
248entry:
249 %c = icmp eq i32 %a, 0
250 store volatile i32 0, i32* %p
251 br i1 %c, label %true, label %false
252true:
253 store volatile i32 1, i32* %p
254 br label %exit
255false:
256 store volatile i32 2, i32* %p
257 br label %exit
258exit:
259 store volatile i32 3, i32* %p
260 ret i32 0
261}
262
Dan Gohmane51c0582015-10-06 00:27:55 +0000263; CHECK-LABEL: single_block:
Dan Gohman950a13c2015-09-16 16:51:30 +0000264; CHECK-NOT: br
Dan Gohman81719f82015-11-25 16:55:01 +0000265; CHECK: return $pop{{[0-9]+}}{{$}}
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000266; OPT-LABEL: single_block:
267; OPT-NOT: br
268; OPT: return $pop{{[0-9]+}}{{$}}
Dan Gohman950a13c2015-09-16 16:51:30 +0000269define i32 @single_block(i32* %p) {
270entry:
271 store volatile i32 0, i32* %p
272 ret i32 0
273}
274
Dan Gohmane51c0582015-10-06 00:27:55 +0000275; CHECK-LABEL: minimal_loop:
Dan Gohman950a13c2015-09-16 16:51:30 +0000276; CHECK-NOT: br
Dan Gohmana4730cf2016-01-07 18:49:53 +0000277; CHECK: .LBB7_1:
Derek Schuff9d779522015-12-05 00:26:39 +0000278; CHECK: i32.store $discard=, 0($0), $pop{{[0-9]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000279; CHECK: br 0{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000280; CHECK: .LBB7_2:
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000281; OPT-LABEL: minimal_loop:
282; OPT-NOT: br
Dan Gohmana4730cf2016-01-07 18:49:53 +0000283; OPT: .LBB7_1:
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000284; OPT: i32.store $discard=, 0($0), $pop{{[0-9]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000285; OPT: br 0{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000286; OPT: .LBB7_2:
Dan Gohman950a13c2015-09-16 16:51:30 +0000287define i32 @minimal_loop(i32* %p) {
288entry:
289 store volatile i32 0, i32* %p
290 br label %loop
291loop:
292 store volatile i32 1, i32* %p
293 br label %loop
294}
295
Dan Gohmane51c0582015-10-06 00:27:55 +0000296; CHECK-LABEL: simple_loop:
Dan Gohman950a13c2015-09-16 16:51:30 +0000297; CHECK-NOT: br
Dan Gohmana4730cf2016-01-07 18:49:53 +0000298; CHECK: .LBB8_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000299; CHECK: loop{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000300; CHECK: br_if 0, $pop{{[0-9]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000301; CHECK-NEXT: end_loop{{$}}
Dan Gohmanb6fd39a2016-01-19 16:59:23 +0000302; CHECK: i32.const $push{{[0-9]+}}=, 0{{$}}
303; CHECK-NEXT: return $pop{{[0-9]+}}{{$}}
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000304; OPT-LABEL: simple_loop:
305; OPT-NOT: br
Dan Gohmana4730cf2016-01-07 18:49:53 +0000306; OPT: .LBB8_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000307; OPT: loop{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000308; OPT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000309; OPT-NEXT: end_loop{{$}}
Dan Gohmanb6fd39a2016-01-19 16:59:23 +0000310; OPT: i32.const $push{{[0-9]+}}=, 0{{$}}
311; OPT-NEXT: return $pop{{[0-9]+}}{{$}}
Dan Gohman950a13c2015-09-16 16:51:30 +0000312define i32 @simple_loop(i32* %p, i32 %a) {
313entry:
314 %c = icmp eq i32 %a, 0
315 store volatile i32 0, i32* %p
316 br label %loop
317loop:
318 store volatile i32 1, i32* %p
319 br i1 %c, label %loop, label %exit
320exit:
321 store volatile i32 2, i32* %p
322 ret i32 0
323}
324
Dan Gohmane51c0582015-10-06 00:27:55 +0000325; CHECK-LABEL: doubletriangle:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000326; CHECK: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000327; CHECK: br_if 0, $0{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000328; CHECK: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000329; CHECK: br_if 0, $1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000330; CHECK: .LBB9_3:
331; CHECK: .LBB9_4:
Dan Gohman4ba48162015-11-18 16:12:01 +0000332; CHECK: return ${{[0-9]+}}{{$}}
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000333; OPT-LABEL: doubletriangle:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000334; OPT: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000335; OPT: br_if 0, $0{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000336; OPT: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000337; OPT: br_if 0, $1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000338; OPT: .LBB9_3:
339; OPT: .LBB9_4:
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000340; OPT: return ${{[0-9]+}}{{$}}
Dan Gohman950a13c2015-09-16 16:51:30 +0000341define i32 @doubletriangle(i32 %a, i32 %b, i32* %p) {
342entry:
343 %c = icmp eq i32 %a, 0
344 %d = icmp eq i32 %b, 0
345 store volatile i32 0, i32* %p
346 br i1 %c, label %true, label %exit
347true:
348 store volatile i32 2, i32* %p
349 br i1 %d, label %tt, label %tf
350tt:
351 store volatile i32 3, i32* %p
352 br label %tf
353tf:
354 store volatile i32 4, i32* %p
355 br label %exit
356exit:
357 store volatile i32 5, i32* %p
358 ret i32 0
359}
360
Dan Gohmane51c0582015-10-06 00:27:55 +0000361; CHECK-LABEL: ifelse_earlyexits:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000362; CHECK: block{{$}}
363; CHECK: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000364; CHECK: br_if 0, $0{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000365; CHECK: br 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000366; CHECK: .LBB10_2:
Dan Gohman06b49582016-02-08 21:50:13 +0000367; CHECK: br_if 0, $1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000368; CHECK: .LBB10_4:
Dan Gohmanb6fd39a2016-01-19 16:59:23 +0000369; CHECK: i32.const $push{{[0-9]+}}=, 0{{$}}
370; CHECK-NEXT: return $pop{{[0-9]+}}{{$}}
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000371; OPT-LABEL: ifelse_earlyexits:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000372; OPT: block{{$}}
373; OPT: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000374; OPT: br_if 0, {{[^,]+}}{{$}}
375; OPT: br_if 1, $1{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000376; OPT: br 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000377; OPT: .LBB10_3:
378; OPT: .LBB10_4:
Dan Gohmanb6fd39a2016-01-19 16:59:23 +0000379; OPT: i32.const $push{{[0-9]+}}=, 0{{$}}
380; OPT-NEXT: return $pop{{[0-9]+}}{{$}}
Dan Gohman950a13c2015-09-16 16:51:30 +0000381define i32 @ifelse_earlyexits(i32 %a, i32 %b, i32* %p) {
382entry:
383 %c = icmp eq i32 %a, 0
384 %d = icmp eq i32 %b, 0
385 store volatile i32 0, i32* %p
386 br i1 %c, label %true, label %false
387true:
388 store volatile i32 1, i32* %p
389 br label %exit
390false:
391 store volatile i32 2, i32* %p
392 br i1 %d, label %ft, label %exit
393ft:
394 store volatile i32 3, i32* %p
395 br label %exit
396exit:
397 store volatile i32 4, i32* %p
398 ret i32 0
399}
Dan Gohmane3e4a5f2015-10-02 21:11:36 +0000400
Dan Gohman32807932015-11-23 16:19:56 +0000401; CHECK-LABEL: doublediamond_in_a_loop:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000402; CHECK: .LBB11_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000403; CHECK: loop{{$}}
404; CHECK: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000405; CHECK: br_if 0, $0{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000406; CHECK: br 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000407; CHECK: .LBB11_3:
Dan Gohman0cfb5f82016-05-10 04:24:02 +0000408; CHECK: end_block{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000409; CHECK: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000410; CHECK: br_if 0, $1{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000411; CHECK: br 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000412; CHECK: .LBB11_5:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000413; CHECK: br 0{{$}}
Dan Gohman0cfb5f82016-05-10 04:24:02 +0000414; CHECK: .LBB11_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000415; CHECK-NEXT: end_loop{{$}}
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000416; OPT-LABEL: doublediamond_in_a_loop:
Dan Gohman442bfce2016-02-16 16:22:41 +0000417; OPT: .LBB11_1:
418; OPT: loop{{$}}
419; OPT: block{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +0000420; OPT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman0cfb5f82016-05-10 04:24:02 +0000421; OPT: block{{$}}
422; OPT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +0000423; OPT: br 2{{$}}
424; OPT-NEXT: .LBB11_4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000425; OPT-NEXT: end_block{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +0000426; OPT: br 1{{$}}
427; OPT: .LBB11_5:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000428; OPT-NEXT: end_block{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +0000429; OPT: br 0{{$}}
Dan Gohman0cfb5f82016-05-10 04:24:02 +0000430; OPT: .LBB11_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000431; OPT-NEXT: end_loop{{$}}
Dan Gohman32807932015-11-23 16:19:56 +0000432define i32 @doublediamond_in_a_loop(i32 %a, i32 %b, i32* %p) {
433entry:
434 br label %header
435header:
436 %c = icmp eq i32 %a, 0
437 %d = icmp eq i32 %b, 0
438 store volatile i32 0, i32* %p
439 br i1 %c, label %true, label %false
440true:
441 store volatile i32 1, i32* %p
442 br label %exit
443false:
444 store volatile i32 2, i32* %p
445 br i1 %d, label %ft, label %ff
446ft:
447 store volatile i32 3, i32* %p
448 br label %exit
449ff:
450 store volatile i32 4, i32* %p
451 br label %exit
452exit:
453 store volatile i32 5, i32* %p
454 br label %header
455}
456
Dan Gohmane3e4a5f2015-10-02 21:11:36 +0000457; Test that nested loops are handled.
458
Dan Gohman8fe7e862015-12-14 22:51:54 +0000459; CHECK-LABEL: test3:
460; CHECK: loop
461; CHECK-NEXT: br_if
Dan Gohmana4730cf2016-01-07 18:49:53 +0000462; CHECK-NEXT: .LBB{{[0-9]+}}_{{[0-9]+}}:
Dan Gohman8fe7e862015-12-14 22:51:54 +0000463; CHECK-NEXT: loop
464; OPT-LABEL: test3:
Dan Gohman442bfce2016-02-16 16:22:41 +0000465; OPT: block
466; OPT: br_if
Dan Gohmand85ab7f2016-02-18 06:32:53 +0000467; OPT: .LBB{{[0-9]+}}_{{[0-9]+}}:
Dan Gohman442bfce2016-02-16 16:22:41 +0000468; OPT-NEXT: loop
469; OPT-NEXT: block
470; OPT-NEXT: block
Dan Gohman8fe7e862015-12-14 22:51:54 +0000471; OPT-NEXT: br_if
Dan Gohmana4730cf2016-01-07 18:49:53 +0000472; OPT-NEXT: .LBB{{[0-9]+}}_{{[0-9]+}}:
Dan Gohman8fe7e862015-12-14 22:51:54 +0000473; OPT-NEXT: loop
Dan Gohman442bfce2016-02-16 16:22:41 +0000474; OPT: br_if
475; OPT-NEXT: br
476; OPT-NEXT: .LBB{{[0-9]+}}_{{[0-9]+}}:
477; OPT-NEXT: end_loop
478; OPT-NEXT: end_block
479; OPT-NEXT: unreachable
480; OPT-NEXT: .LBB{{[0-9]+}}_{{[0-9]+}}:
481; OPT-NEXT: end_block
482; OPT: br
483; OPT-NEXT: .LBB{{[0-9]+}}_{{[0-9]+}}:
484; OPT-NEXT: end_loop
Dan Gohmane3e4a5f2015-10-02 21:11:36 +0000485declare void @bar()
Dan Gohmane3e4a5f2015-10-02 21:11:36 +0000486define void @test3(i32 %w) {
487entry:
488 br i1 undef, label %outer.ph, label %exit
489
490outer.ph:
491 br label %outer
492
493outer:
494 %tobool = icmp eq i32 undef, 0
495 br i1 %tobool, label %inner, label %unreachable
496
497unreachable:
498 unreachable
499
500inner:
501 %c = icmp eq i32 undef, %w
502 br i1 %c, label %if.end, label %inner
503
504exit:
505 ret void
506
507if.end:
508 call void @bar()
509 br label %outer
510}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000511
512; Test switch lowering and block placement.
513
514; CHECK-LABEL: test4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000515; CHECK-NEXT: .param i32{{$}}
516; CHECK: block{{$}}
517; CHECK-NEXT: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000518; CHECK: br_if 0, $pop{{[0-9]+}}{{$}}
Dan Gohmand85ab7f2016-02-18 06:32:53 +0000519; CHECK: br_if 1, $pop{{[0-9]+}}{{$}}
520; CHECK: br 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000521; CHECK-NEXT: .LBB13_3:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000522; CHECK-NEXT: end_block{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +0000523; CHECK-NEXT: block{{$}}
Dan Gohmand85ab7f2016-02-18 06:32:53 +0000524; CHECK: br_if 0, $pop{{[0-9]+}}{{$}}
525; CHECK: br_if 1, $pop{{[0-9]+}}{{$}}
526; CHECK-NEXT: .LBB13_5:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000527; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000528; CHECK-NEXT: return{{$}}
Dan Gohmand85ab7f2016-02-18 06:32:53 +0000529; CHECK-NEXT: .LBB13_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000530; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000531; CHECK-NEXT: return{{$}}
532; OPT-LABEL: test4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000533; OPT-NEXT: .param i32{{$}}
534; OPT: block{{$}}
535; OPT-NEXT: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000536; OPT: br_if 0, $pop{{[0-9]+}}{{$}}
Dan Gohmand85ab7f2016-02-18 06:32:53 +0000537; OPT: br_if 1, $pop{{[0-9]+}}{{$}}
538; OPT: br 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000539; OPT-NEXT: .LBB13_3:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000540; OPT-NEXT: end_block{{$}}
Dan Gohmand85ab7f2016-02-18 06:32:53 +0000541; OPT-NEXT: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000542; OPT: br_if 0, $pop{{[0-9]+}}{{$}}
Dan Gohmand85ab7f2016-02-18 06:32:53 +0000543; OPT: br_if 1, $pop{{[0-9]+}}{{$}}
544; OPT-NEXT: .LBB13_5:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000545; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000546; OPT-NEXT: return{{$}}
Dan Gohmand85ab7f2016-02-18 06:32:53 +0000547; OPT-NEXT: .LBB13_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000548; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000549; OPT-NEXT: return{{$}}
550define void @test4(i32 %t) {
551entry:
552 switch i32 %t, label %default [
553 i32 0, label %bb2
554 i32 2, label %bb2
555 i32 4, label %bb1
556 i32 622, label %bb0
557 ]
558
559bb0:
560 ret void
561
562bb1:
563 ret void
564
565bb2:
566 ret void
567
568default:
569 ret void
570}
571
572; Test a case where the BLOCK needs to be placed before the LOOP in the
573; same basic block.
574
575; CHECK-LABEL: test5:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000576; CHECK: .LBB14_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000577; CHECK-NEXT: block{{$}}
578; CHECK-NEXT: loop{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000579; CHECK: br_if 2, {{[^,]+}}{{$}}
580; CHECK: br_if 0, {{[^,]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000581; CHECK-NEXT: end_loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000582; CHECK: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000583; CHECK-NEXT: .LBB14_4:
Dan Gohman8fe7e862015-12-14 22:51:54 +0000584; CHECK: return{{$}}
585; OPT-LABEL: test5:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000586; OPT: .LBB14_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000587; OPT-NEXT: block{{$}}
588; OPT-NEXT: loop{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000589; OPT: br_if 2, {{[^,]+}}{{$}}
590; OPT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000591; OPT-NEXT: end_loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000592; OPT: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000593; OPT-NEXT: .LBB14_4:
Dan Gohman8fe7e862015-12-14 22:51:54 +0000594; OPT: return{{$}}
595define void @test5(i1 %p, i1 %q) {
596entry:
597 br label %header
598
599header:
600 store volatile i32 0, i32* null
601 br i1 %p, label %more, label %alt
602
603more:
604 store volatile i32 1, i32* null
605 br i1 %q, label %header, label %return
606
607alt:
608 store volatile i32 2, i32* null
609 ret void
610
611return:
612 store volatile i32 3, i32* null
613 ret void
614}
615
616; Test an interesting case of a loop with multiple exits, which
617; aren't to layout successors of the loop, and one of which is to a successors
618; which has another predecessor.
619
620; CHECK-LABEL: test6:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000621; CHECK: .LBB15_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000622; CHECK-NEXT: block{{$}}
623; CHECK-NEXT: block{{$}}
624; CHECK-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000625; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000626; CHECK: br_if 3, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000627; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000628; CHECK: br_if 2, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000629; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000630; CHECK: br_if 0, {{[^,]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000631; CHECK-NEXT: end_loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000632; CHECK-NOT: block
633; CHECK: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000634; CHECK-NEXT: .LBB15_5:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000635; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000636; CHECK-NOT: block
Dan Gohmana4730cf2016-01-07 18:49:53 +0000637; CHECK: .LBB15_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000638; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000639; CHECK-NOT: block
640; CHECK: return{{$}}
641; OPT-LABEL: test6:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000642; OPT: .LBB15_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000643; OPT-NEXT: block{{$}}
644; OPT-NEXT: block{{$}}
645; OPT-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000646; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000647; OPT: br_if 3, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000648; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000649; OPT: br_if 2, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000650; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000651; OPT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000652; OPT-NEXT: end_loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000653; OPT-NOT: block
654; OPT: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000655; OPT-NEXT: .LBB15_5:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000656; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000657; OPT-NOT: block
Dan Gohmana4730cf2016-01-07 18:49:53 +0000658; OPT: .LBB15_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000659; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000660; OPT-NOT: block
661; OPT: return{{$}}
662define void @test6(i1 %p, i1 %q) {
663entry:
664 br label %header
665
666header:
667 store volatile i32 0, i32* null
668 br i1 %p, label %more, label %second
669
670more:
671 store volatile i32 1, i32* null
672 br i1 %q, label %evenmore, label %first
673
674evenmore:
675 store volatile i32 1, i32* null
676 br i1 %q, label %header, label %return
677
678return:
679 store volatile i32 2, i32* null
680 ret void
681
682first:
683 store volatile i32 3, i32* null
684 br label %second
685
686second:
687 store volatile i32 4, i32* null
688 ret void
689}
690
691; Test a case where there are multiple backedges and multiple loop exits
692; that end in unreachable.
693
694; CHECK-LABEL: test7:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000695; CHECK: .LBB16_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000696; CHECK-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000697; CHECK-NOT: block
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000698; CHECK: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000699; CHECK: br_if 0, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000700; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000701; CHECK: br_if 1, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000702; CHECK-NOT: block
703; CHECK: unreachable
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000704; CHECK-NEXT: .LBB16_4:
705; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000706; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000707; CHECK: br_if 0, {{[^,]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000708; CHECK-NEXT: end_loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000709; CHECK-NOT: block
710; CHECK: unreachable
711; OPT-LABEL: test7:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000712; OPT: .LBB16_1:
Dan Gohman442bfce2016-02-16 16:22:41 +0000713; OPT-NEXT: block
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000714; OPT-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000715; OPT-NOT: block
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000716; OPT: block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000717; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000718; OPT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000719; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000720; OPT: br_if 1, {{[^,]+}}{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +0000721; OPT: br 3{{$}}
722; OPT-NEXT: .LBB16_3:
723; OPT-NEXT: end_block
Dan Gohman8fe7e862015-12-14 22:51:54 +0000724; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000725; OPT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +0000726; OPT-NEXT: end_loop
727; OPT-NOT: block
728; OPT: unreachable
729; OPT-NEXT: .LBB16_5:
730; OPT-NEXT: end_block
Dan Gohman8fe7e862015-12-14 22:51:54 +0000731; OPT-NOT: block
732; OPT: unreachable
733define void @test7(i1 %tobool2, i1 %tobool9) {
734entry:
735 store volatile i32 0, i32* null
736 br label %loop
737
738loop:
739 store volatile i32 1, i32* null
740 br i1 %tobool2, label %l1, label %l0
741
742l0:
743 store volatile i32 2, i32* null
744 br i1 %tobool9, label %loop, label %u0
745
746l1:
747 store volatile i32 3, i32* null
748 br i1 %tobool9, label %loop, label %u1
749
750u0:
751 store volatile i32 4, i32* null
752 unreachable
753
754u1:
755 store volatile i32 5, i32* null
756 unreachable
757}
758
759; Test an interesting case using nested loops and switches.
760
761; CHECK-LABEL: test8:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000762; CHECK: .LBB17_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000763; CHECK-NEXT: loop{{$}}
Dan Gohmane5d3c152016-01-20 05:55:09 +0000764; CHECK-NEXT: i32.const $push{{[^,]+}}, 0{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000765; CHECK-NEXT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman0cfb5f82016-05-10 04:24:02 +0000766; CHECK-NEXT: br 0{{$}}
767; CHECK-NEXT: .LBB17_2:
768; CHECK-NEXT: end_loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000769; OPT-LABEL: test8:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000770; OPT: .LBB17_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000771; OPT-NEXT: loop{{$}}
Dan Gohmane5d3c152016-01-20 05:55:09 +0000772; OPT-NEXT: i32.const $push{{[^,]+}}, 0{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000773; OPT-NEXT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman0cfb5f82016-05-10 04:24:02 +0000774; OPT-NEXT: br 0{{$}}
775; OPT-NEXT: .LBB17_2:
776; OPT-NEXT: end_loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000777define i32 @test8() {
778bb:
779 br label %bb1
780
781bb1:
782 br i1 undef, label %bb2, label %bb3
783
784bb2:
785 switch i8 undef, label %bb1 [
786 i8 44, label %bb2
787 ]
788
789bb3:
790 switch i8 undef, label %bb1 [
791 i8 44, label %bb2
792 ]
793}
794
795; Test an interesting case using nested loops that share a bottom block.
796
797; CHECK-LABEL: test9:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000798; CHECK: .LBB18_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000799; CHECK-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000800; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000801; CHECK: br_if 1, {{[^,]+}}{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000802; CHECK-NEXT: .LBB18_2:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000803; CHECK-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000804; CHECK-NOT: block
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000805; CHECK: block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000806; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000807; CHECK: br_if 0, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000808; CHECK-NOT: block
Dan Gohmand85ab7f2016-02-18 06:32:53 +0000809; CHECK: br_if 3, {{[^,]+}}{{$}}
810; CHECK-NEXT: br 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000811; CHECK-NEXT: .LBB18_4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000812; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000813; CHECK-NOT: block
Dan Gohmand85ab7f2016-02-18 06:32:53 +0000814; CHECK: br_if 2, {{[^,]+}}{{$}}
815; CHECK-NEXT: br 0{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000816; CHECK-NEXT: .LBB18_5:
Dan Gohman8fe7e862015-12-14 22:51:54 +0000817; CHECK-NOT: block
818; CHECK: return{{$}}
819; OPT-LABEL: test9:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000820; OPT: .LBB18_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000821; OPT-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000822; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000823; OPT: br_if 1, {{[^,]+}}{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000824; OPT-NEXT: .LBB18_2:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000825; OPT-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000826; OPT-NOT: block
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000827; OPT: block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000828; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000829; OPT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000830; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000831; OPT: br_if 1, {{[^,]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000832; OPT-NEXT: br 3{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000833; OPT-NEXT: .LBB18_4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000834; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000835; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000836; OPT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000837; OPT-NEXT: br 2{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000838; OPT-NEXT: .LBB18_5:
Dan Gohman8fe7e862015-12-14 22:51:54 +0000839; OPT-NOT: block
840; OPT: return{{$}}
841declare i1 @a()
842define void @test9() {
843entry:
844 store volatile i32 0, i32* null
845 br label %header
846
847header:
848 store volatile i32 1, i32* null
849 %call4 = call i1 @a()
850 br i1 %call4, label %header2, label %end
851
852header2:
853 store volatile i32 2, i32* null
854 %call = call i1 @a()
855 br i1 %call, label %if.then, label %if.else
856
857if.then:
858 store volatile i32 3, i32* null
859 %call3 = call i1 @a()
860 br i1 %call3, label %header2, label %header
861
862if.else:
863 store volatile i32 4, i32* null
864 %call2 = call i1 @a()
865 br i1 %call2, label %header2, label %header
866
867end:
868 store volatile i32 5, i32* null
869 ret void
870}
871
872; Test an interesting case involving nested loops sharing a loop bottom,
873; and loop exits to a block with unreachable.
874
875; CHECK-LABEL: test10:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000876; CHECK: .LBB19_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000877; CHECK-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000878; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000879; CHECK: br_if 0, {{[^,]+}}{{$}}
JF Bastienc6ba5ea2016-04-05 17:01:52 +0000880; CHECK: .LBB19_3:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000881; CHECK-NEXT: block{{$}}
882; CHECK-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000883; CHECK-NOT: block
JF Bastienc6ba5ea2016-04-05 17:01:52 +0000884; CHECK: .LBB19_4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000885; CHECK-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000886; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000887; CHECK: br_if 5, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000888; CHECK-NOT: block
Dan Gohman14026062016-03-08 03:18:12 +0000889; CHECK: br_table {{[^,]+}}, 0, 1, 5, 2, 4, 0{{$}}
JF Bastienc6ba5ea2016-04-05 17:01:52 +0000890; CHECK-NEXT: .LBB19_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000891; CHECK-NEXT: end_loop{{$}}
892; CHECK-NEXT: end_loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000893; CHECK-NEXT: return{{$}}
JF Bastienc6ba5ea2016-04-05 17:01:52 +0000894; CHECK-NEXT: .LBB19_7:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000895; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000896; CHECK-NOT: block
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000897; CHECK: br 0{{$}}
JF Bastienc6ba5ea2016-04-05 17:01:52 +0000898; CHECK-NEXT: .LBB19_8:
Dan Gohman8fe7e862015-12-14 22:51:54 +0000899; OPT-LABEL: test10:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000900; OPT: .LBB19_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000901; OPT-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000902; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000903; OPT: br_if 0, {{[^,]+}}{{$}}
JF Bastienc6ba5ea2016-04-05 17:01:52 +0000904; OPT: .LBB19_3:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000905; OPT-NEXT: block{{$}}
906; OPT-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000907; OPT-NOT: block
JF Bastienc6ba5ea2016-04-05 17:01:52 +0000908; OPT: .LBB19_4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000909; OPT-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000910; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000911; OPT: br_if 5, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000912; OPT-NOT: block
Dan Gohman14026062016-03-08 03:18:12 +0000913; OPT: br_table {{[^,]+}}, 0, 1, 5, 2, 4, 0{{$}}
JF Bastienc6ba5ea2016-04-05 17:01:52 +0000914; OPT-NEXT: .LBB19_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000915; OPT-NEXT: end_loop{{$}}
916; OPT-NEXT: end_loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000917; OPT-NEXT: return{{$}}
JF Bastienc6ba5ea2016-04-05 17:01:52 +0000918; OPT-NEXT: .LBB19_7:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000919; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000920; OPT-NOT: block
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000921; OPT: br 0{{$}}
JF Bastienc6ba5ea2016-04-05 17:01:52 +0000922; OPT-NEXT: .LBB19_8:
Dan Gohman8fe7e862015-12-14 22:51:54 +0000923define void @test10() {
924bb0:
925 br label %bb1
926
927bb1:
928 %tmp = phi i32 [ 2, %bb0 ], [ 3, %bb3 ]
929 %tmp3 = phi i32 [ undef, %bb0 ], [ %tmp11, %bb3 ]
930 %tmp4 = icmp eq i32 %tmp3, 0
931 br i1 %tmp4, label %bb4, label %bb2
932
933bb2:
934 br label %bb3
935
936bb3:
937 %tmp11 = phi i32 [ 1, %bb5 ], [ 0, %bb2 ]
938 br label %bb1
939
940bb4:
941 %tmp6 = phi i32 [ %tmp9, %bb5 ], [ 4, %bb1 ]
942 %tmp7 = phi i32 [ %tmp6, %bb5 ], [ %tmp, %bb1 ]
943 br label %bb5
944
945bb5:
946 %tmp9 = phi i32 [ %tmp6, %bb5 ], [ %tmp7, %bb4 ]
947 switch i32 %tmp9, label %bb2 [
948 i32 0, label %bb5
949 i32 1, label %bb6
950 i32 3, label %bb4
951 i32 4, label %bb3
952 ]
953
954bb6:
955 ret void
956}
957
958; Test a CFG DAG with interesting merging.
959
960; CHECK-LABEL: test11:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000961; CHECK: block{{$}}
962; CHECK-NEXT: block{{$}}
963; CHECK-NEXT: block{{$}}
964; CHECK-NEXT: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000965; CHECK: br_if 0, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000966; CHECK-NOT: block
Dan Gohmaned0f1132016-01-30 05:01:06 +0000967; CHECK: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000968; CHECK-NEXT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000969; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000970; CHECK: br_if 2, {{[^,]+}}{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000971; CHECK-NEXT: .LBB20_3:
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_4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000976; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000977; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000978; CHECK: br_if 1, {{[^,]+}}{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +0000979; CHECK-NOT: block
980; CHECK: br_if 2, {{[^,]+}}{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000981; CHECK-NEXT: .LBB20_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000982; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000983; CHECK-NOT: block
984; CHECK: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000985; CHECK-NEXT: .LBB20_7:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000986; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000987; CHECK-NOT: block
988; CHECK: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000989; CHECK-NEXT: .LBB20_8:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000990; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000991; CHECK-NOT: block
992; CHECK: return{{$}}
993; OPT-LABEL: test11:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000994; OPT: block{{$}}
995; OPT-NEXT: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000996; OPT: br_if 0, $pop{{[0-9]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000997; OPT-NOT: block
Dan Gohmaned0f1132016-01-30 05:01:06 +0000998; OPT: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000999; OPT-NEXT: br_if 0, $0{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001000; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +00001001; OPT: br_if 2, {{[^,]+}}{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +00001002; OPT-NEXT: .LBB20_3:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001003; OPT-NEXT: end_block{{$}}
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_4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001007; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001008; OPT-NOT: block
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001009; OPT: block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001010; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +00001011; OPT: br_if 0, $pop{{[0-9]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001012; OPT-NOT: block
1013; OPT: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +00001014; OPT-NEXT: .LBB20_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001015; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001016; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +00001017; OPT: br_if 0, $pop{{[0-9]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001018; OPT-NOT: block
1019; OPT: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +00001020; OPT-NEXT: .LBB20_8:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001021; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001022; OPT-NOT: block
1023; OPT: return{{$}}
1024define void @test11() {
1025bb0:
1026 store volatile i32 0, i32* null
1027 br i1 undef, label %bb1, label %bb4
1028bb1:
1029 store volatile i32 1, i32* null
1030 br i1 undef, label %bb3, label %bb2
1031bb2:
1032 store volatile i32 2, i32* null
1033 br i1 undef, label %bb3, label %bb7
1034bb3:
1035 store volatile i32 3, i32* null
1036 ret void
1037bb4:
1038 store volatile i32 4, i32* null
1039 br i1 undef, label %bb8, label %bb5
1040bb5:
1041 store volatile i32 5, i32* null
1042 br i1 undef, label %bb6, label %bb7
1043bb6:
1044 store volatile i32 6, i32* null
1045 ret void
1046bb7:
1047 store volatile i32 7, i32* null
1048 ret void
1049bb8:
1050 store volatile i32 8, i32* null
1051 ret void
1052}
1053
1054; CHECK-LABEL: test12:
Dan Gohmana4730cf2016-01-07 18:49:53 +00001055; CHECK: .LBB21_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001056; CHECK-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001057; CHECK-NOT: block
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001058; CHECK: block{{$}}
1059; CHECK-NEXT: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +00001060; CHECK: br_if 0, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001061; CHECK-NOT: block
Dan Gohman442bfce2016-02-16 16:22:41 +00001062; CHECK: br_if 1, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001063; CHECK-NOT: block
Dan Gohman442bfce2016-02-16 16:22:41 +00001064; CHECK: br_if 1, {{[^,]+}}{{$}}
1065; CHECK-NEXT: br 3{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +00001066; CHECK-NEXT: .LBB21_4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001067; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001068; CHECK-NOT: block
Dan Gohman442bfce2016-02-16 16:22:41 +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 2, {{[^,]+}}{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +00001072; CHECK-NEXT: .LBB21_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001073; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001074; CHECK-NOT: block
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001075; CHECK: br 0{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +00001076; CHECK-NEXT: .LBB21_7:
1077; CHECK-NEXT: end_loop{{$}}
1078; CHECK-NEXT: return{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001079; OPT-LABEL: test12:
Dan Gohmana4730cf2016-01-07 18:49:53 +00001080; OPT: .LBB21_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001081; OPT-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001082; OPT-NOT: block
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001083; OPT: block{{$}}
1084; OPT-NEXT: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +00001085; OPT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001086; OPT-NOT: block
Dan Gohman442bfce2016-02-16 16:22:41 +00001087; OPT: br_if 1, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001088; OPT-NOT: block
Dan Gohman442bfce2016-02-16 16:22:41 +00001089; OPT: br_if 1, {{[^,]+}}{{$}}
1090; OPT-NEXT: br 3{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +00001091; OPT-NEXT: .LBB21_4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001092; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001093; OPT-NOT: block
Dan Gohman442bfce2016-02-16 16:22:41 +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 2, {{[^,]+}}{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +00001097; OPT-NEXT: .LBB21_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001098; OPT-NEXT: end_block{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001099; OPT: br 0{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +00001100; OPT-NEXT: .LBB21_7:
1101; OPT-NEXT: end_loop{{$}}
1102; OPT-NEXT: return{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001103define void @test12(i8* %arg) {
1104bb:
1105 br label %bb1
1106
1107bb1:
1108 %tmp = phi i32 [ 0, %bb ], [ %tmp5, %bb4 ]
1109 %tmp2 = getelementptr i8, i8* %arg, i32 %tmp
1110 %tmp3 = load i8, i8* %tmp2
1111 switch i8 %tmp3, label %bb7 [
1112 i8 42, label %bb4
1113 i8 76, label %bb4
1114 i8 108, label %bb4
1115 i8 104, label %bb4
1116 ]
1117
1118bb4:
1119 %tmp5 = add i32 %tmp, 1
1120 br label %bb1
1121
1122bb7:
1123 ret void
1124}
Dan Gohmanb3aa1ec2015-12-16 19:06:41 +00001125
1126; A block can be "branched to" from another even if it is also reachable via
1127; fallthrough from the other. This would normally be optimized away, so use
1128; optnone to disable optimizations to test this case.
1129
1130; CHECK-LABEL: test13:
Dan Gohmanb6fd39a2016-01-19 16:59:23 +00001131; CHECK-NEXT: .local i32{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +00001132; CHECK-NEXT: block{{$}}
1133; CHECK-NEXT: block{{$}}
1134; CHECK: br_if 0, $pop0{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001135; CHECK: block{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +00001136; CHECK: br_if 0, $pop3{{$}}
1137; CHECK: .LBB22_3:
1138; CHECK-NEXT: end_block{{$}}
1139; CHECK: br_if 1, $pop{{[0-9]+}}{{$}}
1140; CHECK-NEXT: br 1{{$}}
1141; CHECK-NEXT: .LBB22_4:
1142; CHECK-NEXT: end_block{{$}}
Dan Gohmanb3aa1ec2015-12-16 19:06:41 +00001143; CHECK-NEXT: return{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +00001144; CHECK-NEXT: .LBB22_5:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001145; CHECK-NEXT: end_block{{$}}
Dan Gohmanb3aa1ec2015-12-16 19:06:41 +00001146; CHECK-NEXT: unreachable{{$}}
1147; OPT-LABEL: test13:
Dan Gohmanb6fd39a2016-01-19 16:59:23 +00001148; OPT-NEXT: .local i32{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +00001149; OPT-NEXT: block{{$}}
1150; OPT-NEXT: block{{$}}
1151; OPT: br_if 0, $pop0{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001152; OPT: block{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +00001153; OPT: br_if 0, $pop3{{$}}
1154; OPT: .LBB22_3:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001155; OPT-NEXT: end_block{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +00001156; OPT: br_if 1, $pop{{[0-9]+}}{{$}}
1157; OPT-NEXT: br 1{{$}}
1158; OPT-NEXT: .LBB22_4:
1159; OPT-NEXT: end_block
1160; OPT-NEXT: return
1161; OPT-NEXT: .LBB22_5:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001162; OPT-NEXT: end_block{{$}}
Dan Gohmanb3aa1ec2015-12-16 19:06:41 +00001163; OPT-NEXT: unreachable{{$}}
1164define void @test13() noinline optnone {
1165bb:
1166 br i1 undef, label %bb5, label %bb2
1167bb1:
1168 unreachable
1169bb2:
1170 br i1 undef, label %bb3, label %bb4
1171bb3:
1172 br label %bb4
1173bb4:
1174 %tmp = phi i1 [ false, %bb2 ], [ false, %bb3 ]
1175 br i1 %tmp, label %bb1, label %bb1
1176bb5:
1177 ret void
1178}
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001179
1180; Test a case with a single-block loop that has another loop
1181; as a successor. The end_loop for the first loop should go
1182; before the loop for the second.
1183
1184; CHECK-LABEL: test14:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001185; CHECK-NEXT: .LBB23_1:{{$}}
1186; CHECK-NEXT: loop{{$}}
Dan Gohmanb6fd39a2016-01-19 16:59:23 +00001187; CHECK-NEXT: i32.const $push0=, 0{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +00001188; CHECK-NEXT: br_if 0, $pop0{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001189; CHECK-NEXT: end_loop{{$}}
Dan Gohman0cfb5f82016-05-10 04:24:02 +00001190; CHECK-NEXT: .LBB23_3:{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001191; CHECK-NEXT: loop{{$}}
Dan Gohmanb6fd39a2016-01-19 16:59:23 +00001192; CHECK-NEXT: i32.const $push1=, 0{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +00001193; CHECK-NEXT: br_if 0, $pop1{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001194; CHECK-NEXT: end_loop{{$}}
1195; CHECK-NEXT: return{{$}}
1196define void @test14() {
1197bb:
1198 br label %bb1
1199
1200bb1:
1201 %tmp = bitcast i1 undef to i1
1202 br i1 %tmp, label %bb3, label %bb1
1203
1204bb3:
1205 br label %bb4
1206
1207bb4:
1208 br i1 undef, label %bb7, label %bb48
1209
1210bb7:
1211 br i1 undef, label %bb12, label %bb12
1212
1213bb12:
1214 br i1 undef, label %bb17, label %bb17
1215
1216bb17:
1217 br i1 undef, label %bb22, label %bb22
1218
1219bb22:
1220 br i1 undef, label %bb27, label %bb27
1221
1222bb27:
1223 br i1 undef, label %bb30, label %bb30
1224
1225bb30:
1226 br i1 undef, label %bb35, label %bb35
1227
1228bb35:
1229 br i1 undef, label %bb38, label %bb38
1230
1231bb38:
1232 br i1 undef, label %bb48, label %bb48
1233
1234bb48:
1235 %tmp49 = bitcast i1 undef to i1
1236 br i1 %tmp49, label %bb3, label %bb50
1237
1238bb50:
1239 ret void
1240}
Dan Gohmana187ab22016-02-12 21:19:25 +00001241
1242; Test that a block boundary which ends one block, begins another block, and
1243; also begins a loop, has the markers placed in the correct order.
1244
1245; CHECK-LABEL: test15:
1246; CHECK: block
Dan Gohmana187ab22016-02-12 21:19:25 +00001247; CHECK-NEXT: block
Dan Gohman442bfce2016-02-16 16:22:41 +00001248; CHECK: br_if 0, $pop{{.*}}{{$}}
Dan Gohmand85ab7f2016-02-18 06:32:53 +00001249; CHECK: .LBB24_2:
Dan Gohman442bfce2016-02-16 16:22:41 +00001250; CHECK-NEXT: block{{$}}
1251; CHECK-NEXT: loop{{$}}
1252; CHECK: br_if 1, $pop{{.*}}{{$}}
Dan Gohmand85ab7f2016-02-18 06:32:53 +00001253; CHECK: br_if 0, ${{.*}}{{$}}
1254; CHECK-NEXT: br 2{{$}}
1255; CHECK-NEXT: .LBB24_4:
Dan Gohman442bfce2016-02-16 16:22:41 +00001256; CHECK-NEXT: end_loop{{$}}
Dan Gohmand85ab7f2016-02-18 06:32:53 +00001257; CHECK: .LBB24_5:
Dan Gohman442bfce2016-02-16 16:22:41 +00001258; CHECK-NEXT: end_block{{$}}
1259; CHECK: br_if 1, $pop{{.*}}{{$}}
1260; CHECK: return{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +00001261; CHECK: .LBB24_7:
1262; CHECK-NEXT: end_block{{$}}
Dan Gohmand85ab7f2016-02-18 06:32:53 +00001263; CHECK: .LBB24_8:
1264; CHECK-NEXT: end_block{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +00001265; CHECK-NEXT: return{{$}}
Dan Gohmana187ab22016-02-12 21:19:25 +00001266; OPT-LABEL: test15:
1267; OPT: block
Dan Gohmand85ab7f2016-02-18 06:32:53 +00001268; OPT: block
Dan Gohmana187ab22016-02-12 21:19:25 +00001269; OPT-NEXT: i32.const $push
Dan Gohman804749c2016-05-16 18:59:34 +00001270; OPT-NEXT: i32.eqz $push{{.*}}=, $pop{{.*}}{{$}}
Dan Gohmana187ab22016-02-12 21:19:25 +00001271; OPT-NEXT: br_if 0, $pop{{.*}}{{$}}
1272; OPT-NEXT: call test15_callee1@FUNCTION{{$}}
Dan Gohmand85ab7f2016-02-18 06:32:53 +00001273; OPT-NEXT: br 1{{$}}
Dan Gohmana187ab22016-02-12 21:19:25 +00001274; OPT-NEXT: .LBB24_2:
1275; OPT-NEXT: end_block
Dan Gohmand85ab7f2016-02-18 06:32:53 +00001276; OPT-NEXT: i32.const
1277; OPT-NEXT: .LBB24_3:
Dan Gohmana187ab22016-02-12 21:19:25 +00001278; OPT-NEXT: block
1279; OPT-NEXT: loop
1280%0 = type { i8, i32 }
1281declare void @test15_callee0()
1282declare void @test15_callee1()
1283define void @test15() {
1284bb:
1285 %tmp1 = icmp eq i8 1, 0
1286 br i1 %tmp1, label %bb2, label %bb14
1287
1288bb2:
1289 %tmp3 = phi %0** [ %tmp6, %bb5 ], [ null, %bb ]
1290 %tmp4 = icmp eq i32 0, 11
1291 br i1 %tmp4, label %bb5, label %bb8
1292
1293bb5:
1294 %tmp = bitcast i8* null to %0**
1295 %tmp6 = getelementptr %0*, %0** %tmp3, i32 1
1296 %tmp7 = icmp eq %0** %tmp6, null
1297 br i1 %tmp7, label %bb10, label %bb2
1298
1299bb8:
1300 %tmp9 = icmp eq %0** null, undef
1301 br label %bb10
1302
1303bb10:
1304 %tmp11 = phi %0** [ null, %bb8 ], [ %tmp, %bb5 ]
1305 %tmp12 = icmp eq %0** null, %tmp11
1306 br i1 %tmp12, label %bb15, label %bb13
1307
1308bb13:
1309 call void @test15_callee0()
1310 ret void
1311
1312bb14:
1313 call void @test15_callee1()
1314 ret void
1315
1316bb15:
1317 ret void
1318}