xref: /aosp_15_r20/external/llvm/test/CodeGen/WebAssembly/cfg-stackify.ll (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -disable-block-placement -verify-machineinstrs -fast-isel=false | FileCheck %s
2*9880d681SAndroid Build Coastguard Worker; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -verify-machineinstrs -fast-isel=false | FileCheck -check-prefix=OPT %s
3*9880d681SAndroid Build Coastguard Worker
4*9880d681SAndroid Build Coastguard Worker; Test the CFG stackifier pass.
5*9880d681SAndroid Build Coastguard Worker
6*9880d681SAndroid Build Coastguard Worker; Explicitly disable fast-isel, since it gets implicitly enabled in the
7*9880d681SAndroid Build Coastguard Worker; optnone test.
8*9880d681SAndroid Build Coastguard Worker
9*9880d681SAndroid Build Coastguard Workertarget datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
10*9880d681SAndroid Build Coastguard Workertarget triple = "wasm32-unknown-unknown"
11*9880d681SAndroid Build Coastguard Worker
12*9880d681SAndroid Build Coastguard Workerdeclare void @something()
13*9880d681SAndroid Build Coastguard Worker
14*9880d681SAndroid Build Coastguard Worker; Test that loops are made contiguous, even in the presence of split backedges.
15*9880d681SAndroid Build Coastguard Worker
16*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: test0:
17*9880d681SAndroid Build Coastguard Worker; CHECK: loop
18*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: block
19*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: i32.const
20*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: i32.add
21*9880d681SAndroid Build Coastguard Worker; CHECK:      i32.lt_s
22*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: br_if
23*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: return
24*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: .LBB0_3:
25*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: end_block
26*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: call
27*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: br
28*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: .LBB0_4:
29*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: end_loop
30*9880d681SAndroid Build Coastguard Worker; OPT-LABEL: test0:
31*9880d681SAndroid Build Coastguard Worker; OPT: loop
32*9880d681SAndroid Build Coastguard Worker; OPT-NEXT: i32.const
33*9880d681SAndroid Build Coastguard Worker; OPT-NEXT: i32.add
34*9880d681SAndroid Build Coastguard Worker; OPT:      i32.ge_s
35*9880d681SAndroid Build Coastguard Worker; OPT-NEXT: br_if
36*9880d681SAndroid Build Coastguard Worker; OPT-NOT: br
37*9880d681SAndroid Build Coastguard Worker; OPT: call
38*9880d681SAndroid Build Coastguard Worker; OPT: br 0{{$}}
39*9880d681SAndroid Build Coastguard Worker; OPT: return{{$}}
40*9880d681SAndroid Build Coastguard Workerdefine void @test0(i32 %n) {
41*9880d681SAndroid Build Coastguard Workerentry:
42*9880d681SAndroid Build Coastguard Worker  br label %header
43*9880d681SAndroid Build Coastguard Worker
44*9880d681SAndroid Build Coastguard Workerheader:
45*9880d681SAndroid Build Coastguard Worker  %i = phi i32 [ 0, %entry ], [ %i.next, %back ]
46*9880d681SAndroid Build Coastguard Worker  %i.next = add i32 %i, 1
47*9880d681SAndroid Build Coastguard Worker
48*9880d681SAndroid Build Coastguard Worker  %c = icmp slt i32 %i.next, %n
49*9880d681SAndroid Build Coastguard Worker  br i1 %c, label %back, label %exit
50*9880d681SAndroid Build Coastguard Worker
51*9880d681SAndroid Build Coastguard Workerexit:
52*9880d681SAndroid Build Coastguard Worker  ret void
53*9880d681SAndroid Build Coastguard Worker
54*9880d681SAndroid Build Coastguard Workerback:
55*9880d681SAndroid Build Coastguard Worker  call void @something()
56*9880d681SAndroid Build Coastguard Worker  br label %header
57*9880d681SAndroid Build Coastguard Worker}
58*9880d681SAndroid Build Coastguard Worker
59*9880d681SAndroid Build Coastguard Worker; Same as test0, but the branch condition is reversed.
60*9880d681SAndroid Build Coastguard Worker
61*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: test1:
62*9880d681SAndroid Build Coastguard Worker; CHECK: loop
63*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: block
64*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: i32.const
65*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: i32.add
66*9880d681SAndroid Build Coastguard Worker; CHECK:      i32.lt_s
67*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: br_if
68*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: return
69*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: .LBB1_3:
70*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: end_block
71*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: call
72*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: br
73*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: .LBB1_4:
74*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: end_loop
75*9880d681SAndroid Build Coastguard Worker; OPT-LABEL: test1:
76*9880d681SAndroid Build Coastguard Worker; OPT: loop
77*9880d681SAndroid Build Coastguard Worker; OPT-NEXT: i32.const
78*9880d681SAndroid Build Coastguard Worker; OPT-NEXT: i32.add
79*9880d681SAndroid Build Coastguard Worker; OPT:      i32.ge_s
80*9880d681SAndroid Build Coastguard Worker; OPT-NEXT: br_if
81*9880d681SAndroid Build Coastguard Worker; OPT-NOT: br
82*9880d681SAndroid Build Coastguard Worker; OPT: call
83*9880d681SAndroid Build Coastguard Worker; OPT: br 0{{$}}
84*9880d681SAndroid Build Coastguard Worker; OPT: return{{$}}
85*9880d681SAndroid Build Coastguard Workerdefine void @test1(i32 %n) {
86*9880d681SAndroid Build Coastguard Workerentry:
87*9880d681SAndroid Build Coastguard Worker  br label %header
88*9880d681SAndroid Build Coastguard Worker
89*9880d681SAndroid Build Coastguard Workerheader:
90*9880d681SAndroid Build Coastguard Worker  %i = phi i32 [ 0, %entry ], [ %i.next, %back ]
91*9880d681SAndroid Build Coastguard Worker  %i.next = add i32 %i, 1
92*9880d681SAndroid Build Coastguard Worker
93*9880d681SAndroid Build Coastguard Worker  %c = icmp sge i32 %i.next, %n
94*9880d681SAndroid Build Coastguard Worker  br i1 %c, label %exit, label %back
95*9880d681SAndroid Build Coastguard Worker
96*9880d681SAndroid Build Coastguard Workerexit:
97*9880d681SAndroid Build Coastguard Worker  ret void
98*9880d681SAndroid Build Coastguard Worker
99*9880d681SAndroid Build Coastguard Workerback:
100*9880d681SAndroid Build Coastguard Worker  call void @something()
101*9880d681SAndroid Build Coastguard Worker  br label %header
102*9880d681SAndroid Build Coastguard Worker}
103*9880d681SAndroid Build Coastguard Worker
104*9880d681SAndroid Build Coastguard Worker; Test that a simple loop is handled as expected.
105*9880d681SAndroid Build Coastguard Worker
106*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: test2:
107*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: local
108*9880d681SAndroid Build Coastguard Worker; CHECK: block{{$}}
109*9880d681SAndroid Build Coastguard Worker; CHECK: br_if 0, {{[^,]+}}{{$}}
110*9880d681SAndroid Build Coastguard Worker; CHECK: .LBB2_{{[0-9]+}}:
111*9880d681SAndroid Build Coastguard Worker; CHECK: loop
112*9880d681SAndroid Build Coastguard Worker; CHECK: br_if 0, $pop{{[0-9]+}}{{$}}
113*9880d681SAndroid Build Coastguard Worker; CHECK: .LBB2_{{[0-9]+}}:
114*9880d681SAndroid Build Coastguard Worker; CHECK: end_loop
115*9880d681SAndroid Build Coastguard Worker; CHECK: end_block
116*9880d681SAndroid Build Coastguard Worker; CHECK: return{{$}}
117*9880d681SAndroid Build Coastguard Worker; OPT-LABEL: test2:
118*9880d681SAndroid Build Coastguard Worker; OPT-NOT: local
119*9880d681SAndroid Build Coastguard Worker; OPT: block{{$}}
120*9880d681SAndroid Build Coastguard Worker; OPT: br_if 0, {{[^,]+}}{{$}}
121*9880d681SAndroid Build Coastguard Worker; OPT: .LBB2_{{[0-9]+}}:
122*9880d681SAndroid Build Coastguard Worker; OPT: loop
123*9880d681SAndroid Build Coastguard Worker; OPT: br_if 0, $pop{{[0-9]+}}{{$}}
124*9880d681SAndroid Build Coastguard Worker; OPT: .LBB2_{{[0-9]+}}:
125*9880d681SAndroid Build Coastguard Worker; OPT: end_loop
126*9880d681SAndroid Build Coastguard Worker; OPT: end_block
127*9880d681SAndroid Build Coastguard Worker; OPT: return{{$}}
128*9880d681SAndroid Build Coastguard Workerdefine void @test2(double* nocapture %p, i32 %n) {
129*9880d681SAndroid Build Coastguard Workerentry:
130*9880d681SAndroid Build Coastguard Worker  %cmp.4 = icmp sgt i32 %n, 0
131*9880d681SAndroid Build Coastguard Worker  br i1 %cmp.4, label %for.body.preheader, label %for.end
132*9880d681SAndroid Build Coastguard Worker
133*9880d681SAndroid Build Coastguard Workerfor.body.preheader:
134*9880d681SAndroid Build Coastguard Worker  br label %for.body
135*9880d681SAndroid Build Coastguard Worker
136*9880d681SAndroid Build Coastguard Workerfor.body:
137*9880d681SAndroid Build Coastguard Worker  %i.05 = phi i32 [ %inc, %for.body ], [ 0, %for.body.preheader ]
138*9880d681SAndroid Build Coastguard Worker  %arrayidx = getelementptr inbounds double, double* %p, i32 %i.05
139*9880d681SAndroid Build Coastguard Worker  %0 = load double, double* %arrayidx, align 8
140*9880d681SAndroid Build Coastguard Worker  %mul = fmul double %0, 3.200000e+00
141*9880d681SAndroid Build Coastguard Worker  store double %mul, double* %arrayidx, align 8
142*9880d681SAndroid Build Coastguard Worker  %inc = add nuw nsw i32 %i.05, 1
143*9880d681SAndroid Build Coastguard Worker  %exitcond = icmp eq i32 %inc, %n
144*9880d681SAndroid Build Coastguard Worker  br i1 %exitcond, label %for.end.loopexit, label %for.body
145*9880d681SAndroid Build Coastguard Worker
146*9880d681SAndroid Build Coastguard Workerfor.end.loopexit:
147*9880d681SAndroid Build Coastguard Worker  br label %for.end
148*9880d681SAndroid Build Coastguard Worker
149*9880d681SAndroid Build Coastguard Workerfor.end:
150*9880d681SAndroid Build Coastguard Worker  ret void
151*9880d681SAndroid Build Coastguard Worker}
152*9880d681SAndroid Build Coastguard Worker
153*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: doublediamond:
154*9880d681SAndroid Build Coastguard Worker; CHECK: block{{$}}
155*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: block{{$}}
156*9880d681SAndroid Build Coastguard Worker; CHECK: br_if 0, ${{[^,]+}}{{$}}
157*9880d681SAndroid Build Coastguard Worker; CHECK: br 1{{$}}
158*9880d681SAndroid Build Coastguard Worker; CHECK: .LBB3_2:
159*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: end_block{{$}}
160*9880d681SAndroid Build Coastguard Worker; CHECK: block{{$}}
161*9880d681SAndroid Build Coastguard Worker; CHECK: br_if 0, ${{[^,]+}}{{$}}
162*9880d681SAndroid Build Coastguard Worker; CHECK: br 1{{$}}
163*9880d681SAndroid Build Coastguard Worker; CHECK: .LBB3_4:
164*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: end_block{{$}}
165*9880d681SAndroid Build Coastguard Worker; CHECK: .LBB3_5:
166*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: end_block{{$}}
167*9880d681SAndroid Build Coastguard Worker; CHECK: i32.const $push{{[0-9]+}}=, 0{{$}}
168*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: return $pop{{[0-9]+}}{{$}}
169*9880d681SAndroid Build Coastguard Worker; OPT-LABEL: doublediamond:
170*9880d681SAndroid Build Coastguard Worker; OPT:      block{{$}}
171*9880d681SAndroid Build Coastguard Worker; OPT-NEXT: block{{$}}
172*9880d681SAndroid Build Coastguard Worker; OPT-NEXT: block{{$}}
173*9880d681SAndroid Build Coastguard Worker; OPT:      br_if 0, ${{[^,]+}}{{$}}
174*9880d681SAndroid Build Coastguard Worker; OPT:      br_if 1, ${{[^,]+}}{{$}}
175*9880d681SAndroid Build Coastguard Worker; OPT:      br 2{{$}}
176*9880d681SAndroid Build Coastguard Worker; OPT-NEXT: .LBB3_3:
177*9880d681SAndroid Build Coastguard Worker; OPT-NEXT: end_block
178*9880d681SAndroid Build Coastguard Worker; OPT:      br 1{{$}}
179*9880d681SAndroid Build Coastguard Worker; OPT-NEXT: .LBB3_4:
180*9880d681SAndroid Build Coastguard Worker; OPT:      .LBB3_5:
181*9880d681SAndroid Build Coastguard Worker; OPT-NEXT: end_block
182*9880d681SAndroid Build Coastguard Worker; OPT:      return $pop{{[0-9]+}}{{$}}
183*9880d681SAndroid Build Coastguard Workerdefine i32 @doublediamond(i32 %a, i32 %b, i32* %p) {
184*9880d681SAndroid Build Coastguard Workerentry:
185*9880d681SAndroid Build Coastguard Worker  %c = icmp eq i32 %a, 0
186*9880d681SAndroid Build Coastguard Worker  %d = icmp eq i32 %b, 0
187*9880d681SAndroid Build Coastguard Worker  store volatile i32 0, i32* %p
188*9880d681SAndroid Build Coastguard Worker  br i1 %c, label %true, label %false
189*9880d681SAndroid Build Coastguard Workertrue:
190*9880d681SAndroid Build Coastguard Worker  store volatile i32 1, i32* %p
191*9880d681SAndroid Build Coastguard Worker  br label %exit
192*9880d681SAndroid Build Coastguard Workerfalse:
193*9880d681SAndroid Build Coastguard Worker  store volatile i32 2, i32* %p
194*9880d681SAndroid Build Coastguard Worker  br i1 %d, label %ft, label %ff
195*9880d681SAndroid Build Coastguard Workerft:
196*9880d681SAndroid Build Coastguard Worker  store volatile i32 3, i32* %p
197*9880d681SAndroid Build Coastguard Worker  br label %exit
198*9880d681SAndroid Build Coastguard Workerff:
199*9880d681SAndroid Build Coastguard Worker  store volatile i32 4, i32* %p
200*9880d681SAndroid Build Coastguard Worker  br label %exit
201*9880d681SAndroid Build Coastguard Workerexit:
202*9880d681SAndroid Build Coastguard Worker  store volatile i32 5, i32* %p
203*9880d681SAndroid Build Coastguard Worker  ret i32 0
204*9880d681SAndroid Build Coastguard Worker}
205*9880d681SAndroid Build Coastguard Worker
206*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: triangle:
207*9880d681SAndroid Build Coastguard Worker; CHECK: block{{$}}
208*9880d681SAndroid Build Coastguard Worker; CHECK: br_if 0, $1{{$}}
209*9880d681SAndroid Build Coastguard Worker; CHECK: .LBB4_2:
210*9880d681SAndroid Build Coastguard Worker; CHECK: return ${{[0-9]+}}{{$}}
211*9880d681SAndroid Build Coastguard Worker; OPT-LABEL: triangle:
212*9880d681SAndroid Build Coastguard Worker; OPT: block{{$}}
213*9880d681SAndroid Build Coastguard Worker; OPT: br_if 0, $1{{$}}
214*9880d681SAndroid Build Coastguard Worker; OPT: .LBB4_2:
215*9880d681SAndroid Build Coastguard Worker; OPT: return ${{[0-9]+}}{{$}}
216*9880d681SAndroid Build Coastguard Workerdefine i32 @triangle(i32* %p, i32 %a) {
217*9880d681SAndroid Build Coastguard Workerentry:
218*9880d681SAndroid Build Coastguard Worker  %c = icmp eq i32 %a, 0
219*9880d681SAndroid Build Coastguard Worker  store volatile i32 0, i32* %p
220*9880d681SAndroid Build Coastguard Worker  br i1 %c, label %true, label %exit
221*9880d681SAndroid Build Coastguard Workertrue:
222*9880d681SAndroid Build Coastguard Worker  store volatile i32 1, i32* %p
223*9880d681SAndroid Build Coastguard Worker  br label %exit
224*9880d681SAndroid Build Coastguard Workerexit:
225*9880d681SAndroid Build Coastguard Worker  store volatile i32 2, i32* %p
226*9880d681SAndroid Build Coastguard Worker  ret i32 0
227*9880d681SAndroid Build Coastguard Worker}
228*9880d681SAndroid Build Coastguard Worker
229*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: diamond:
230*9880d681SAndroid Build Coastguard Worker; CHECK: block{{$}}
231*9880d681SAndroid Build Coastguard Worker; CHECK: block{{$}}
232*9880d681SAndroid Build Coastguard Worker; CHECK: br_if 0, $1{{$}}
233*9880d681SAndroid Build Coastguard Worker; CHECK: br 1{{$}}
234*9880d681SAndroid Build Coastguard Worker; CHECK: .LBB5_2:
235*9880d681SAndroid Build Coastguard Worker; CHECK: .LBB5_3:
236*9880d681SAndroid Build Coastguard Worker; CHECK: i32.const $push{{[0-9]+}}=, 0{{$}}
237*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: return $pop{{[0-9]+}}{{$}}
238*9880d681SAndroid Build Coastguard Worker; OPT-LABEL: diamond:
239*9880d681SAndroid Build Coastguard Worker; OPT: block{{$}}
240*9880d681SAndroid Build Coastguard Worker; OPT: block{{$}}
241*9880d681SAndroid Build Coastguard Worker; OPT: br_if 0, {{[^,]+}}{{$}}
242*9880d681SAndroid Build Coastguard Worker; OPT: br 1{{$}}
243*9880d681SAndroid Build Coastguard Worker; OPT: .LBB5_2:
244*9880d681SAndroid Build Coastguard Worker; OPT: .LBB5_3:
245*9880d681SAndroid Build Coastguard Worker; OPT: i32.const $push{{[0-9]+}}=, 0{{$}}
246*9880d681SAndroid Build Coastguard Worker; OPT-NEXT: return $pop{{[0-9]+}}{{$}}
247*9880d681SAndroid Build Coastguard Workerdefine i32 @diamond(i32* %p, i32 %a) {
248*9880d681SAndroid Build Coastguard Workerentry:
249*9880d681SAndroid Build Coastguard Worker  %c = icmp eq i32 %a, 0
250*9880d681SAndroid Build Coastguard Worker  store volatile i32 0, i32* %p
251*9880d681SAndroid Build Coastguard Worker  br i1 %c, label %true, label %false
252*9880d681SAndroid Build Coastguard Workertrue:
253*9880d681SAndroid Build Coastguard Worker  store volatile i32 1, i32* %p
254*9880d681SAndroid Build Coastguard Worker  br label %exit
255*9880d681SAndroid Build Coastguard Workerfalse:
256*9880d681SAndroid Build Coastguard Worker  store volatile i32 2, i32* %p
257*9880d681SAndroid Build Coastguard Worker  br label %exit
258*9880d681SAndroid Build Coastguard Workerexit:
259*9880d681SAndroid Build Coastguard Worker  store volatile i32 3, i32* %p
260*9880d681SAndroid Build Coastguard Worker  ret i32 0
261*9880d681SAndroid Build Coastguard Worker}
262*9880d681SAndroid Build Coastguard Worker
263*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: single_block:
264*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: br
265*9880d681SAndroid Build Coastguard Worker; CHECK: return $pop{{[0-9]+}}{{$}}
266*9880d681SAndroid Build Coastguard Worker; OPT-LABEL: single_block:
267*9880d681SAndroid Build Coastguard Worker; OPT-NOT: br
268*9880d681SAndroid Build Coastguard Worker; OPT: return $pop{{[0-9]+}}{{$}}
269*9880d681SAndroid Build Coastguard Workerdefine i32 @single_block(i32* %p) {
270*9880d681SAndroid Build Coastguard Workerentry:
271*9880d681SAndroid Build Coastguard Worker  store volatile i32 0, i32* %p
272*9880d681SAndroid Build Coastguard Worker  ret i32 0
273*9880d681SAndroid Build Coastguard Worker}
274*9880d681SAndroid Build Coastguard Worker
275*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: minimal_loop:
276*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: br
277*9880d681SAndroid Build Coastguard Worker; CHECK: .LBB7_1:
278*9880d681SAndroid Build Coastguard Worker; CHECK: i32.store $drop=, 0($0), $pop{{[0-9]+}}{{$}}
279*9880d681SAndroid Build Coastguard Worker; CHECK: br 0{{$}}
280*9880d681SAndroid Build Coastguard Worker; CHECK: .LBB7_2:
281*9880d681SAndroid Build Coastguard Worker; OPT-LABEL: minimal_loop:
282*9880d681SAndroid Build Coastguard Worker; OPT-NOT: br
283*9880d681SAndroid Build Coastguard Worker; OPT: .LBB7_1:
284*9880d681SAndroid Build Coastguard Worker; OPT: i32.store $drop=, 0($0), $pop{{[0-9]+}}{{$}}
285*9880d681SAndroid Build Coastguard Worker; OPT: br 0{{$}}
286*9880d681SAndroid Build Coastguard Worker; OPT: .LBB7_2:
287*9880d681SAndroid Build Coastguard Workerdefine i32 @minimal_loop(i32* %p) {
288*9880d681SAndroid Build Coastguard Workerentry:
289*9880d681SAndroid Build Coastguard Worker  store volatile i32 0, i32* %p
290*9880d681SAndroid Build Coastguard Worker  br label %loop
291*9880d681SAndroid Build Coastguard Workerloop:
292*9880d681SAndroid Build Coastguard Worker  store volatile i32 1, i32* %p
293*9880d681SAndroid Build Coastguard Worker  br label %loop
294*9880d681SAndroid Build Coastguard Worker}
295*9880d681SAndroid Build Coastguard Worker
296*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: simple_loop:
297*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: br
298*9880d681SAndroid Build Coastguard Worker; CHECK: .LBB8_1:
299*9880d681SAndroid Build Coastguard Worker; CHECK: loop{{$}}
300*9880d681SAndroid Build Coastguard Worker; CHECK: br_if 0, $pop{{[0-9]+}}{{$}}
301*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: end_loop{{$}}
302*9880d681SAndroid Build Coastguard Worker; CHECK: i32.const $push{{[0-9]+}}=, 0{{$}}
303*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: return $pop{{[0-9]+}}{{$}}
304*9880d681SAndroid Build Coastguard Worker; OPT-LABEL: simple_loop:
305*9880d681SAndroid Build Coastguard Worker; OPT-NOT: br
306*9880d681SAndroid Build Coastguard Worker; OPT: .LBB8_1:
307*9880d681SAndroid Build Coastguard Worker; OPT: loop{{$}}
308*9880d681SAndroid Build Coastguard Worker; OPT: br_if 0, {{[^,]+}}{{$}}
309*9880d681SAndroid Build Coastguard Worker; OPT-NEXT: end_loop{{$}}
310*9880d681SAndroid Build Coastguard Worker; OPT: i32.const $push{{[0-9]+}}=, 0{{$}}
311*9880d681SAndroid Build Coastguard Worker; OPT-NEXT: return $pop{{[0-9]+}}{{$}}
312*9880d681SAndroid Build Coastguard Workerdefine i32 @simple_loop(i32* %p, i32 %a) {
313*9880d681SAndroid Build Coastguard Workerentry:
314*9880d681SAndroid Build Coastguard Worker  %c = icmp eq i32 %a, 0
315*9880d681SAndroid Build Coastguard Worker  store volatile i32 0, i32* %p
316*9880d681SAndroid Build Coastguard Worker  br label %loop
317*9880d681SAndroid Build Coastguard Workerloop:
318*9880d681SAndroid Build Coastguard Worker  store volatile i32 1, i32* %p
319*9880d681SAndroid Build Coastguard Worker  br i1 %c, label %loop, label %exit
320*9880d681SAndroid Build Coastguard Workerexit:
321*9880d681SAndroid Build Coastguard Worker  store volatile i32 2, i32* %p
322*9880d681SAndroid Build Coastguard Worker  ret i32 0
323*9880d681SAndroid Build Coastguard Worker}
324*9880d681SAndroid Build Coastguard Worker
325*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: doubletriangle:
326*9880d681SAndroid Build Coastguard Worker; CHECK: block{{$}}
327*9880d681SAndroid Build Coastguard Worker; CHECK: br_if 0, $0{{$}}
328*9880d681SAndroid Build Coastguard Worker; CHECK: block{{$}}
329*9880d681SAndroid Build Coastguard Worker; CHECK: br_if 0, $1{{$}}
330*9880d681SAndroid Build Coastguard Worker; CHECK: .LBB9_3:
331*9880d681SAndroid Build Coastguard Worker; CHECK: .LBB9_4:
332*9880d681SAndroid Build Coastguard Worker; CHECK: return ${{[0-9]+}}{{$}}
333*9880d681SAndroid Build Coastguard Worker; OPT-LABEL: doubletriangle:
334*9880d681SAndroid Build Coastguard Worker; OPT: block{{$}}
335*9880d681SAndroid Build Coastguard Worker; OPT: br_if 0, $0{{$}}
336*9880d681SAndroid Build Coastguard Worker; OPT: block{{$}}
337*9880d681SAndroid Build Coastguard Worker; OPT: br_if 0, $1{{$}}
338*9880d681SAndroid Build Coastguard Worker; OPT: .LBB9_3:
339*9880d681SAndroid Build Coastguard Worker; OPT: .LBB9_4:
340*9880d681SAndroid Build Coastguard Worker; OPT: return ${{[0-9]+}}{{$}}
341*9880d681SAndroid Build Coastguard Workerdefine i32 @doubletriangle(i32 %a, i32 %b, i32* %p) {
342*9880d681SAndroid Build Coastguard Workerentry:
343*9880d681SAndroid Build Coastguard Worker  %c = icmp eq i32 %a, 0
344*9880d681SAndroid Build Coastguard Worker  %d = icmp eq i32 %b, 0
345*9880d681SAndroid Build Coastguard Worker  store volatile i32 0, i32* %p
346*9880d681SAndroid Build Coastguard Worker  br i1 %c, label %true, label %exit
347*9880d681SAndroid Build Coastguard Workertrue:
348*9880d681SAndroid Build Coastguard Worker  store volatile i32 2, i32* %p
349*9880d681SAndroid Build Coastguard Worker  br i1 %d, label %tt, label %tf
350*9880d681SAndroid Build Coastguard Workertt:
351*9880d681SAndroid Build Coastguard Worker  store volatile i32 3, i32* %p
352*9880d681SAndroid Build Coastguard Worker  br label %tf
353*9880d681SAndroid Build Coastguard Workertf:
354*9880d681SAndroid Build Coastguard Worker  store volatile i32 4, i32* %p
355*9880d681SAndroid Build Coastguard Worker  br label %exit
356*9880d681SAndroid Build Coastguard Workerexit:
357*9880d681SAndroid Build Coastguard Worker  store volatile i32 5, i32* %p
358*9880d681SAndroid Build Coastguard Worker  ret i32 0
359*9880d681SAndroid Build Coastguard Worker}
360*9880d681SAndroid Build Coastguard Worker
361*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: ifelse_earlyexits:
362*9880d681SAndroid Build Coastguard Worker; CHECK: block{{$}}
363*9880d681SAndroid Build Coastguard Worker; CHECK: block{{$}}
364*9880d681SAndroid Build Coastguard Worker; CHECK: br_if 0, $0{{$}}
365*9880d681SAndroid Build Coastguard Worker; CHECK: br 1{{$}}
366*9880d681SAndroid Build Coastguard Worker; CHECK: .LBB10_2:
367*9880d681SAndroid Build Coastguard Worker; CHECK: br_if 0, $1{{$}}
368*9880d681SAndroid Build Coastguard Worker; CHECK: .LBB10_4:
369*9880d681SAndroid Build Coastguard Worker; CHECK: i32.const $push{{[0-9]+}}=, 0{{$}}
370*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: return $pop{{[0-9]+}}{{$}}
371*9880d681SAndroid Build Coastguard Worker; OPT-LABEL: ifelse_earlyexits:
372*9880d681SAndroid Build Coastguard Worker; OPT: block{{$}}
373*9880d681SAndroid Build Coastguard Worker; OPT: block{{$}}
374*9880d681SAndroid Build Coastguard Worker; OPT: br_if 0, {{[^,]+}}{{$}}
375*9880d681SAndroid Build Coastguard Worker; OPT: br_if 1, $1{{$}}
376*9880d681SAndroid Build Coastguard Worker; OPT: br 1{{$}}
377*9880d681SAndroid Build Coastguard Worker; OPT: .LBB10_3:
378*9880d681SAndroid Build Coastguard Worker; OPT: .LBB10_4:
379*9880d681SAndroid Build Coastguard Worker; OPT: i32.const $push{{[0-9]+}}=, 0{{$}}
380*9880d681SAndroid Build Coastguard Worker; OPT-NEXT: return $pop{{[0-9]+}}{{$}}
381*9880d681SAndroid Build Coastguard Workerdefine i32 @ifelse_earlyexits(i32 %a, i32 %b, i32* %p) {
382*9880d681SAndroid Build Coastguard Workerentry:
383*9880d681SAndroid Build Coastguard Worker  %c = icmp eq i32 %a, 0
384*9880d681SAndroid Build Coastguard Worker  %d = icmp eq i32 %b, 0
385*9880d681SAndroid Build Coastguard Worker  store volatile i32 0, i32* %p
386*9880d681SAndroid Build Coastguard Worker  br i1 %c, label %true, label %false
387*9880d681SAndroid Build Coastguard Workertrue:
388*9880d681SAndroid Build Coastguard Worker  store volatile i32 1, i32* %p
389*9880d681SAndroid Build Coastguard Worker  br label %exit
390*9880d681SAndroid Build Coastguard Workerfalse:
391*9880d681SAndroid Build Coastguard Worker  store volatile i32 2, i32* %p
392*9880d681SAndroid Build Coastguard Worker  br i1 %d, label %ft, label %exit
393*9880d681SAndroid Build Coastguard Workerft:
394*9880d681SAndroid Build Coastguard Worker  store volatile i32 3, i32* %p
395*9880d681SAndroid Build Coastguard Worker  br label %exit
396*9880d681SAndroid Build Coastguard Workerexit:
397*9880d681SAndroid Build Coastguard Worker  store volatile i32 4, i32* %p
398*9880d681SAndroid Build Coastguard Worker  ret i32 0
399*9880d681SAndroid Build Coastguard Worker}
400*9880d681SAndroid Build Coastguard Worker
401*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: doublediamond_in_a_loop:
402*9880d681SAndroid Build Coastguard Worker; CHECK: .LBB11_1:
403*9880d681SAndroid Build Coastguard Worker; CHECK: loop{{$}}
404*9880d681SAndroid Build Coastguard Worker; CHECK: block{{$}}
405*9880d681SAndroid Build Coastguard Worker; CHECK: br_if           0, $0{{$}}
406*9880d681SAndroid Build Coastguard Worker; CHECK: br              1{{$}}
407*9880d681SAndroid Build Coastguard Worker; CHECK: .LBB11_3:
408*9880d681SAndroid Build Coastguard Worker; CHECK: end_block{{$}}
409*9880d681SAndroid Build Coastguard Worker; CHECK: block{{$}}
410*9880d681SAndroid Build Coastguard Worker; CHECK: br_if           0, $1{{$}}
411*9880d681SAndroid Build Coastguard Worker; CHECK: br              1{{$}}
412*9880d681SAndroid Build Coastguard Worker; CHECK: .LBB11_5:
413*9880d681SAndroid Build Coastguard Worker; CHECK: br              0{{$}}
414*9880d681SAndroid Build Coastguard Worker; CHECK: .LBB11_6:
415*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: end_loop{{$}}
416*9880d681SAndroid Build Coastguard Worker; OPT-LABEL: doublediamond_in_a_loop:
417*9880d681SAndroid Build Coastguard Worker; OPT:      .LBB11_1:
418*9880d681SAndroid Build Coastguard Worker; OPT:      loop{{$}}
419*9880d681SAndroid Build Coastguard Worker; OPT:      block{{$}}
420*9880d681SAndroid Build Coastguard Worker; OPT:      br_if           0, {{[^,]+}}{{$}}
421*9880d681SAndroid Build Coastguard Worker; OPT:      block{{$}}
422*9880d681SAndroid Build Coastguard Worker; OPT:      br_if           0, {{[^,]+}}{{$}}
423*9880d681SAndroid Build Coastguard Worker; OPT:      br              2{{$}}
424*9880d681SAndroid Build Coastguard Worker; OPT-NEXT: .LBB11_4:
425*9880d681SAndroid Build Coastguard Worker; OPT-NEXT: end_block{{$}}
426*9880d681SAndroid Build Coastguard Worker; OPT:      br              1{{$}}
427*9880d681SAndroid Build Coastguard Worker; OPT:      .LBB11_5:
428*9880d681SAndroid Build Coastguard Worker; OPT-NEXT: end_block{{$}}
429*9880d681SAndroid Build Coastguard Worker; OPT:      br              0{{$}}
430*9880d681SAndroid Build Coastguard Worker; OPT:      .LBB11_6:
431*9880d681SAndroid Build Coastguard Worker; OPT-NEXT: end_loop{{$}}
432*9880d681SAndroid Build Coastguard Workerdefine i32 @doublediamond_in_a_loop(i32 %a, i32 %b, i32* %p) {
433*9880d681SAndroid Build Coastguard Workerentry:
434*9880d681SAndroid Build Coastguard Worker  br label %header
435*9880d681SAndroid Build Coastguard Workerheader:
436*9880d681SAndroid Build Coastguard Worker  %c = icmp eq i32 %a, 0
437*9880d681SAndroid Build Coastguard Worker  %d = icmp eq i32 %b, 0
438*9880d681SAndroid Build Coastguard Worker  store volatile i32 0, i32* %p
439*9880d681SAndroid Build Coastguard Worker  br i1 %c, label %true, label %false
440*9880d681SAndroid Build Coastguard Workertrue:
441*9880d681SAndroid Build Coastguard Worker  store volatile i32 1, i32* %p
442*9880d681SAndroid Build Coastguard Worker  br label %exit
443*9880d681SAndroid Build Coastguard Workerfalse:
444*9880d681SAndroid Build Coastguard Worker  store volatile i32 2, i32* %p
445*9880d681SAndroid Build Coastguard Worker  br i1 %d, label %ft, label %ff
446*9880d681SAndroid Build Coastguard Workerft:
447*9880d681SAndroid Build Coastguard Worker  store volatile i32 3, i32* %p
448*9880d681SAndroid Build Coastguard Worker  br label %exit
449*9880d681SAndroid Build Coastguard Workerff:
450*9880d681SAndroid Build Coastguard Worker  store volatile i32 4, i32* %p
451*9880d681SAndroid Build Coastguard Worker  br label %exit
452*9880d681SAndroid Build Coastguard Workerexit:
453*9880d681SAndroid Build Coastguard Worker  store volatile i32 5, i32* %p
454*9880d681SAndroid Build Coastguard Worker  br label %header
455*9880d681SAndroid Build Coastguard Worker}
456*9880d681SAndroid Build Coastguard Worker
457*9880d681SAndroid Build Coastguard Worker; Test that nested loops are handled.
458*9880d681SAndroid Build Coastguard Worker
459*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: test3:
460*9880d681SAndroid Build Coastguard Worker; CHECK: loop
461*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: br_if
462*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: .LBB{{[0-9]+}}_{{[0-9]+}}:
463*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: loop
464*9880d681SAndroid Build Coastguard Worker; OPT-LABEL: test3:
465*9880d681SAndroid Build Coastguard Worker; OPT: block
466*9880d681SAndroid Build Coastguard Worker; OPT: br_if
467*9880d681SAndroid Build Coastguard Worker; OPT: .LBB{{[0-9]+}}_{{[0-9]+}}:
468*9880d681SAndroid Build Coastguard Worker; OPT-NEXT: loop
469*9880d681SAndroid Build Coastguard Worker; OPT-NEXT: block
470*9880d681SAndroid Build Coastguard Worker; OPT-NEXT: block
471*9880d681SAndroid Build Coastguard Worker; OPT-NEXT: br_if
472*9880d681SAndroid Build Coastguard Worker; OPT-NEXT: .LBB{{[0-9]+}}_{{[0-9]+}}:
473*9880d681SAndroid Build Coastguard Worker; OPT-NEXT: loop
474*9880d681SAndroid Build Coastguard Worker; OPT: br_if
475*9880d681SAndroid Build Coastguard Worker; OPT-NEXT: br
476*9880d681SAndroid Build Coastguard Worker; OPT-NEXT: .LBB{{[0-9]+}}_{{[0-9]+}}:
477*9880d681SAndroid Build Coastguard Worker; OPT-NEXT: end_loop
478*9880d681SAndroid Build Coastguard Worker; OPT-NEXT: end_block
479*9880d681SAndroid Build Coastguard Worker; OPT-NEXT: unreachable
480*9880d681SAndroid Build Coastguard Worker; OPT-NEXT: .LBB{{[0-9]+}}_{{[0-9]+}}:
481*9880d681SAndroid Build Coastguard Worker; OPT-NEXT: end_block
482*9880d681SAndroid Build Coastguard Worker; OPT: br
483*9880d681SAndroid Build Coastguard Worker; OPT-NEXT: .LBB{{[0-9]+}}_{{[0-9]+}}:
484*9880d681SAndroid Build Coastguard Worker; OPT-NEXT: end_loop
485*9880d681SAndroid Build Coastguard Workerdeclare void @bar()
486*9880d681SAndroid Build Coastguard Workerdefine void @test3(i32 %w)  {
487*9880d681SAndroid Build Coastguard Workerentry:
488*9880d681SAndroid Build Coastguard Worker  br i1 undef, label %outer.ph, label %exit
489*9880d681SAndroid Build Coastguard Worker
490*9880d681SAndroid Build Coastguard Workerouter.ph:
491*9880d681SAndroid Build Coastguard Worker  br label %outer
492*9880d681SAndroid Build Coastguard Worker
493*9880d681SAndroid Build Coastguard Workerouter:
494*9880d681SAndroid Build Coastguard Worker  %tobool = icmp eq i32 undef, 0
495*9880d681SAndroid Build Coastguard Worker  br i1 %tobool, label %inner, label %unreachable
496*9880d681SAndroid Build Coastguard Worker
497*9880d681SAndroid Build Coastguard Workerunreachable:
498*9880d681SAndroid Build Coastguard Worker  unreachable
499*9880d681SAndroid Build Coastguard Worker
500*9880d681SAndroid Build Coastguard Workerinner:
501*9880d681SAndroid Build Coastguard Worker  %c = icmp eq i32 undef, %w
502*9880d681SAndroid Build Coastguard Worker  br i1 %c, label %if.end, label %inner
503*9880d681SAndroid Build Coastguard Worker
504*9880d681SAndroid Build Coastguard Workerexit:
505*9880d681SAndroid Build Coastguard Worker  ret void
506*9880d681SAndroid Build Coastguard Worker
507*9880d681SAndroid Build Coastguard Workerif.end:
508*9880d681SAndroid Build Coastguard Worker  call void @bar()
509*9880d681SAndroid Build Coastguard Worker  br label %outer
510*9880d681SAndroid Build Coastguard Worker}
511*9880d681SAndroid Build Coastguard Worker
512*9880d681SAndroid Build Coastguard Worker; Test switch lowering and block placement.
513*9880d681SAndroid Build Coastguard Worker
514*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: test4:
515*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: .param       i32{{$}}
516*9880d681SAndroid Build Coastguard Worker; CHECK:      block{{$}}
517*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: block{{$}}
518*9880d681SAndroid Build Coastguard Worker; CHECK:      br_if       0, $pop{{[0-9]+}}{{$}}
519*9880d681SAndroid Build Coastguard Worker; CHECK:      br_if       1, $pop{{[0-9]+}}{{$}}
520*9880d681SAndroid Build Coastguard Worker; CHECK:      br          1{{$}}
521*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: .LBB13_3:
522*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: end_block{{$}}
523*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: block{{$}}
524*9880d681SAndroid Build Coastguard Worker; CHECK:      br_if 0, $pop{{[0-9]+}}{{$}}
525*9880d681SAndroid Build Coastguard Worker; CHECK:      br_if 1, $pop{{[0-9]+}}{{$}}
526*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: .LBB13_5:
527*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: end_block{{$}}
528*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: return{{$}}
529*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: .LBB13_6:
530*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: end_block{{$}}
531*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: return{{$}}
532*9880d681SAndroid Build Coastguard Worker; OPT-LABEL: test4:
533*9880d681SAndroid Build Coastguard Worker; OPT-NEXT: .param       i32{{$}}
534*9880d681SAndroid Build Coastguard Worker; OPT:      block{{$}}
535*9880d681SAndroid Build Coastguard Worker; OPT-NEXT: block{{$}}
536*9880d681SAndroid Build Coastguard Worker; OPT:      br_if       0, $pop{{[0-9]+}}{{$}}
537*9880d681SAndroid Build Coastguard Worker; OPT:      br_if       1, $pop{{[0-9]+}}{{$}}
538*9880d681SAndroid Build Coastguard Worker; OPT:      br          1{{$}}
539*9880d681SAndroid Build Coastguard Worker; OPT-NEXT: .LBB13_3:
540*9880d681SAndroid Build Coastguard Worker; OPT-NEXT: end_block{{$}}
541*9880d681SAndroid Build Coastguard Worker; OPT-NEXT: block{{$}}
542*9880d681SAndroid Build Coastguard Worker; OPT:      br_if       0, $pop{{[0-9]+}}{{$}}
543*9880d681SAndroid Build Coastguard Worker; OPT:      br_if       1, $pop{{[0-9]+}}{{$}}
544*9880d681SAndroid Build Coastguard Worker; OPT-NEXT: .LBB13_5:
545*9880d681SAndroid Build Coastguard Worker; OPT-NEXT: end_block{{$}}
546*9880d681SAndroid Build Coastguard Worker; OPT-NEXT: return{{$}}
547*9880d681SAndroid Build Coastguard Worker; OPT-NEXT: .LBB13_6:
548*9880d681SAndroid Build Coastguard Worker; OPT-NEXT: end_block{{$}}
549*9880d681SAndroid Build Coastguard Worker; OPT-NEXT: return{{$}}
550*9880d681SAndroid Build Coastguard Workerdefine void @test4(i32 %t) {
551*9880d681SAndroid Build Coastguard Workerentry:
552*9880d681SAndroid Build Coastguard Worker  switch i32 %t, label %default [
553*9880d681SAndroid Build Coastguard Worker    i32 0, label %bb2
554*9880d681SAndroid Build Coastguard Worker    i32 2, label %bb2
555*9880d681SAndroid Build Coastguard Worker    i32 4, label %bb1
556*9880d681SAndroid Build Coastguard Worker    i32 622, label %bb0
557*9880d681SAndroid Build Coastguard Worker  ]
558*9880d681SAndroid Build Coastguard Worker
559*9880d681SAndroid Build Coastguard Workerbb0:
560*9880d681SAndroid Build Coastguard Worker  ret void
561*9880d681SAndroid Build Coastguard Worker
562*9880d681SAndroid Build Coastguard Workerbb1:
563*9880d681SAndroid Build Coastguard Worker  ret void
564*9880d681SAndroid Build Coastguard Worker
565*9880d681SAndroid Build Coastguard Workerbb2:
566*9880d681SAndroid Build Coastguard Worker  ret void
567*9880d681SAndroid Build Coastguard Worker
568*9880d681SAndroid Build Coastguard Workerdefault:
569*9880d681SAndroid Build Coastguard Worker  ret void
570*9880d681SAndroid Build Coastguard Worker}
571*9880d681SAndroid Build Coastguard Worker
572*9880d681SAndroid Build Coastguard Worker; Test a case where the BLOCK needs to be placed before the LOOP in the
573*9880d681SAndroid Build Coastguard Worker; same basic block.
574*9880d681SAndroid Build Coastguard Worker
575*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: test5:
576*9880d681SAndroid Build Coastguard Worker; CHECK:       .LBB14_1:
577*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:  block{{$}}
578*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:  loop{{$}}
579*9880d681SAndroid Build Coastguard Worker; CHECK:       br_if 2, {{[^,]+}}{{$}}
580*9880d681SAndroid Build Coastguard Worker; CHECK:       br_if 0, {{[^,]+}}{{$}}
581*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:  end_loop{{$}}
582*9880d681SAndroid Build Coastguard Worker; CHECK:       return{{$}}
583*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:  .LBB14_4:
584*9880d681SAndroid Build Coastguard Worker; CHECK:       return{{$}}
585*9880d681SAndroid Build Coastguard Worker; OPT-LABEL: test5:
586*9880d681SAndroid Build Coastguard Worker; OPT:       .LBB14_1:
587*9880d681SAndroid Build Coastguard Worker; OPT-NEXT:  block{{$}}
588*9880d681SAndroid Build Coastguard Worker; OPT-NEXT:  loop{{$}}
589*9880d681SAndroid Build Coastguard Worker; OPT:       br_if 2, {{[^,]+}}{{$}}
590*9880d681SAndroid Build Coastguard Worker; OPT:       br_if 0, {{[^,]+}}{{$}}
591*9880d681SAndroid Build Coastguard Worker; OPT-NEXT:  end_loop{{$}}
592*9880d681SAndroid Build Coastguard Worker; OPT:       return{{$}}
593*9880d681SAndroid Build Coastguard Worker; OPT-NEXT:  .LBB14_4:
594*9880d681SAndroid Build Coastguard Worker; OPT:       return{{$}}
595*9880d681SAndroid Build Coastguard Workerdefine void @test5(i1 %p, i1 %q) {
596*9880d681SAndroid Build Coastguard Workerentry:
597*9880d681SAndroid Build Coastguard Worker  br label %header
598*9880d681SAndroid Build Coastguard Worker
599*9880d681SAndroid Build Coastguard Workerheader:
600*9880d681SAndroid Build Coastguard Worker  store volatile i32 0, i32* null
601*9880d681SAndroid Build Coastguard Worker  br i1 %p, label %more, label %alt
602*9880d681SAndroid Build Coastguard Worker
603*9880d681SAndroid Build Coastguard Workermore:
604*9880d681SAndroid Build Coastguard Worker  store volatile i32 1, i32* null
605*9880d681SAndroid Build Coastguard Worker  br i1 %q, label %header, label %return
606*9880d681SAndroid Build Coastguard Worker
607*9880d681SAndroid Build Coastguard Workeralt:
608*9880d681SAndroid Build Coastguard Worker  store volatile i32 2, i32* null
609*9880d681SAndroid Build Coastguard Worker  ret void
610*9880d681SAndroid Build Coastguard Worker
611*9880d681SAndroid Build Coastguard Workerreturn:
612*9880d681SAndroid Build Coastguard Worker  store volatile i32 3, i32* null
613*9880d681SAndroid Build Coastguard Worker  ret void
614*9880d681SAndroid Build Coastguard Worker}
615*9880d681SAndroid Build Coastguard Worker
616*9880d681SAndroid Build Coastguard Worker; Test an interesting case of a loop with multiple exits, which
617*9880d681SAndroid Build Coastguard Worker; aren't to layout successors of the loop, and one of which is to a successors
618*9880d681SAndroid Build Coastguard Worker; which has another predecessor.
619*9880d681SAndroid Build Coastguard Worker
620*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: test6:
621*9880d681SAndroid Build Coastguard Worker; CHECK:       .LBB15_1:
622*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:  block{{$}}
623*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:  block{{$}}
624*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:  loop{{$}}
625*9880d681SAndroid Build Coastguard Worker; CHECK-NOT:   block
626*9880d681SAndroid Build Coastguard Worker; CHECK:       br_if 3, {{[^,]+}}{{$}}
627*9880d681SAndroid Build Coastguard Worker; CHECK-NOT:   block
628*9880d681SAndroid Build Coastguard Worker; CHECK:       br_if 2, {{[^,]+}}{{$}}
629*9880d681SAndroid Build Coastguard Worker; CHECK-NOT:   block
630*9880d681SAndroid Build Coastguard Worker; CHECK:       br_if 0, {{[^,]+}}{{$}}
631*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:  end_loop{{$}}
632*9880d681SAndroid Build Coastguard Worker; CHECK-NOT:   block
633*9880d681SAndroid Build Coastguard Worker; CHECK:       return{{$}}
634*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:  .LBB15_5:
635*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:  end_block{{$}}
636*9880d681SAndroid Build Coastguard Worker; CHECK-NOT:   block
637*9880d681SAndroid Build Coastguard Worker; CHECK:       .LBB15_6:
638*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:  end_block{{$}}
639*9880d681SAndroid Build Coastguard Worker; CHECK-NOT:   block
640*9880d681SAndroid Build Coastguard Worker; CHECK:       return{{$}}
641*9880d681SAndroid Build Coastguard Worker; OPT-LABEL: test6:
642*9880d681SAndroid Build Coastguard Worker; OPT:       .LBB15_1:
643*9880d681SAndroid Build Coastguard Worker; OPT-NEXT:  block{{$}}
644*9880d681SAndroid Build Coastguard Worker; OPT-NEXT:  block{{$}}
645*9880d681SAndroid Build Coastguard Worker; OPT-NEXT:  loop{{$}}
646*9880d681SAndroid Build Coastguard Worker; OPT-NOT:   block
647*9880d681SAndroid Build Coastguard Worker; OPT:       br_if 3, {{[^,]+}}{{$}}
648*9880d681SAndroid Build Coastguard Worker; OPT-NOT:   block
649*9880d681SAndroid Build Coastguard Worker; OPT:       br_if 2, {{[^,]+}}{{$}}
650*9880d681SAndroid Build Coastguard Worker; OPT-NOT:   block
651*9880d681SAndroid Build Coastguard Worker; OPT:       br_if 0, {{[^,]+}}{{$}}
652*9880d681SAndroid Build Coastguard Worker; OPT-NEXT:  end_loop{{$}}
653*9880d681SAndroid Build Coastguard Worker; OPT-NOT:   block
654*9880d681SAndroid Build Coastguard Worker; OPT:       return{{$}}
655*9880d681SAndroid Build Coastguard Worker; OPT-NEXT:  .LBB15_5:
656*9880d681SAndroid Build Coastguard Worker; OPT-NEXT:  end_block{{$}}
657*9880d681SAndroid Build Coastguard Worker; OPT-NOT:   block
658*9880d681SAndroid Build Coastguard Worker; OPT:       .LBB15_6:
659*9880d681SAndroid Build Coastguard Worker; OPT-NEXT:  end_block{{$}}
660*9880d681SAndroid Build Coastguard Worker; OPT-NOT:   block
661*9880d681SAndroid Build Coastguard Worker; OPT:       return{{$}}
662*9880d681SAndroid Build Coastguard Workerdefine void @test6(i1 %p, i1 %q) {
663*9880d681SAndroid Build Coastguard Workerentry:
664*9880d681SAndroid Build Coastguard Worker  br label %header
665*9880d681SAndroid Build Coastguard Worker
666*9880d681SAndroid Build Coastguard Workerheader:
667*9880d681SAndroid Build Coastguard Worker  store volatile i32 0, i32* null
668*9880d681SAndroid Build Coastguard Worker  br i1 %p, label %more, label %second
669*9880d681SAndroid Build Coastguard Worker
670*9880d681SAndroid Build Coastguard Workermore:
671*9880d681SAndroid Build Coastguard Worker  store volatile i32 1, i32* null
672*9880d681SAndroid Build Coastguard Worker  br i1 %q, label %evenmore, label %first
673*9880d681SAndroid Build Coastguard Worker
674*9880d681SAndroid Build Coastguard Workerevenmore:
675*9880d681SAndroid Build Coastguard Worker  store volatile i32 1, i32* null
676*9880d681SAndroid Build Coastguard Worker  br i1 %q, label %header, label %return
677*9880d681SAndroid Build Coastguard Worker
678*9880d681SAndroid Build Coastguard Workerreturn:
679*9880d681SAndroid Build Coastguard Worker  store volatile i32 2, i32* null
680*9880d681SAndroid Build Coastguard Worker  ret void
681*9880d681SAndroid Build Coastguard Worker
682*9880d681SAndroid Build Coastguard Workerfirst:
683*9880d681SAndroid Build Coastguard Worker  store volatile i32 3, i32* null
684*9880d681SAndroid Build Coastguard Worker  br label %second
685*9880d681SAndroid Build Coastguard Worker
686*9880d681SAndroid Build Coastguard Workersecond:
687*9880d681SAndroid Build Coastguard Worker  store volatile i32 4, i32* null
688*9880d681SAndroid Build Coastguard Worker  ret void
689*9880d681SAndroid Build Coastguard Worker}
690*9880d681SAndroid Build Coastguard Worker
691*9880d681SAndroid Build Coastguard Worker; Test a case where there are multiple backedges and multiple loop exits
692*9880d681SAndroid Build Coastguard Worker; that end in unreachable.
693*9880d681SAndroid Build Coastguard Worker
694*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: test7:
695*9880d681SAndroid Build Coastguard Worker; CHECK:       .LBB16_1:
696*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:  loop{{$}}
697*9880d681SAndroid Build Coastguard Worker; CHECK-NOT:   block
698*9880d681SAndroid Build Coastguard Worker; CHECK:       block{{$}}
699*9880d681SAndroid Build Coastguard Worker; CHECK:       br_if 0, {{[^,]+}}{{$}}
700*9880d681SAndroid Build Coastguard Worker; CHECK-NOT:   block
701*9880d681SAndroid Build Coastguard Worker; CHECK:       br_if 1, {{[^,]+}}{{$}}
702*9880d681SAndroid Build Coastguard Worker; CHECK-NOT:   block
703*9880d681SAndroid Build Coastguard Worker; CHECK:       unreachable
704*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:  .LBB16_4:
705*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:  end_block{{$}}
706*9880d681SAndroid Build Coastguard Worker; CHECK-NOT:   block
707*9880d681SAndroid Build Coastguard Worker; CHECK:       br_if 0, {{[^,]+}}{{$}}
708*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:  end_loop{{$}}
709*9880d681SAndroid Build Coastguard Worker; CHECK-NOT:   block
710*9880d681SAndroid Build Coastguard Worker; CHECK:       unreachable
711*9880d681SAndroid Build Coastguard Worker; OPT-LABEL: test7:
712*9880d681SAndroid Build Coastguard Worker; OPT:       .LBB16_1:
713*9880d681SAndroid Build Coastguard Worker; OPT-NEXT:  block
714*9880d681SAndroid Build Coastguard Worker; OPT-NEXT:  loop{{$}}
715*9880d681SAndroid Build Coastguard Worker; OPT-NOT:   block
716*9880d681SAndroid Build Coastguard Worker; OPT:       block{{$}}
717*9880d681SAndroid Build Coastguard Worker; OPT-NOT:   block
718*9880d681SAndroid Build Coastguard Worker; OPT:       br_if 0, {{[^,]+}}{{$}}
719*9880d681SAndroid Build Coastguard Worker; OPT-NOT:   block
720*9880d681SAndroid Build Coastguard Worker; OPT:       br_if 1, {{[^,]+}}{{$}}
721*9880d681SAndroid Build Coastguard Worker; OPT:       br 3{{$}}
722*9880d681SAndroid Build Coastguard Worker; OPT-NEXT:  .LBB16_3:
723*9880d681SAndroid Build Coastguard Worker; OPT-NEXT:  end_block
724*9880d681SAndroid Build Coastguard Worker; OPT-NOT:   block
725*9880d681SAndroid Build Coastguard Worker; OPT:       br_if 0, {{[^,]+}}{{$}}
726*9880d681SAndroid Build Coastguard Worker; OPT-NEXT:  end_loop
727*9880d681SAndroid Build Coastguard Worker; OPT-NOT:   block
728*9880d681SAndroid Build Coastguard Worker; OPT:       unreachable
729*9880d681SAndroid Build Coastguard Worker; OPT-NEXT:  .LBB16_5:
730*9880d681SAndroid Build Coastguard Worker; OPT-NEXT:  end_block
731*9880d681SAndroid Build Coastguard Worker; OPT-NOT:   block
732*9880d681SAndroid Build Coastguard Worker; OPT:       unreachable
733*9880d681SAndroid Build Coastguard Workerdefine void @test7(i1 %tobool2, i1 %tobool9) {
734*9880d681SAndroid Build Coastguard Workerentry:
735*9880d681SAndroid Build Coastguard Worker  store volatile i32 0, i32* null
736*9880d681SAndroid Build Coastguard Worker  br label %loop
737*9880d681SAndroid Build Coastguard Worker
738*9880d681SAndroid Build Coastguard Workerloop:
739*9880d681SAndroid Build Coastguard Worker  store volatile i32 1, i32* null
740*9880d681SAndroid Build Coastguard Worker  br i1 %tobool2, label %l1, label %l0
741*9880d681SAndroid Build Coastguard Worker
742*9880d681SAndroid Build Coastguard Workerl0:
743*9880d681SAndroid Build Coastguard Worker  store volatile i32 2, i32* null
744*9880d681SAndroid Build Coastguard Worker  br i1 %tobool9, label %loop, label %u0
745*9880d681SAndroid Build Coastguard Worker
746*9880d681SAndroid Build Coastguard Workerl1:
747*9880d681SAndroid Build Coastguard Worker  store volatile i32 3, i32* null
748*9880d681SAndroid Build Coastguard Worker  br i1 %tobool9, label %loop, label %u1
749*9880d681SAndroid Build Coastguard Worker
750*9880d681SAndroid Build Coastguard Workeru0:
751*9880d681SAndroid Build Coastguard Worker  store volatile i32 4, i32* null
752*9880d681SAndroid Build Coastguard Worker  unreachable
753*9880d681SAndroid Build Coastguard Worker
754*9880d681SAndroid Build Coastguard Workeru1:
755*9880d681SAndroid Build Coastguard Worker  store volatile i32 5, i32* null
756*9880d681SAndroid Build Coastguard Worker  unreachable
757*9880d681SAndroid Build Coastguard Worker}
758*9880d681SAndroid Build Coastguard Worker
759*9880d681SAndroid Build Coastguard Worker; Test an interesting case using nested loops and switches.
760*9880d681SAndroid Build Coastguard Worker
761*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: test8:
762*9880d681SAndroid Build Coastguard Worker; CHECK:       .LBB17_1:
763*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:  loop{{$}}
764*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:  i32.const $push{{[^,]+}}, 0{{$}}
765*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:  br_if    0, {{[^,]+}}{{$}}
766*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:  br       0{{$}}
767*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:  .LBB17_2:
768*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:  end_loop{{$}}
769*9880d681SAndroid Build Coastguard Worker; OPT-LABEL: test8:
770*9880d681SAndroid Build Coastguard Worker; OPT:       .LBB17_1:
771*9880d681SAndroid Build Coastguard Worker; OPT-NEXT:  loop{{$}}
772*9880d681SAndroid Build Coastguard Worker; OPT-NEXT:  i32.const $push{{[^,]+}}, 0{{$}}
773*9880d681SAndroid Build Coastguard Worker; OPT-NEXT:  br_if    0, {{[^,]+}}{{$}}
774*9880d681SAndroid Build Coastguard Worker; OPT-NEXT:  br       0{{$}}
775*9880d681SAndroid Build Coastguard Worker; OPT-NEXT:  .LBB17_2:
776*9880d681SAndroid Build Coastguard Worker; OPT-NEXT:  end_loop{{$}}
777*9880d681SAndroid Build Coastguard Workerdefine i32 @test8() {
778*9880d681SAndroid Build Coastguard Workerbb:
779*9880d681SAndroid Build Coastguard Worker  br label %bb1
780*9880d681SAndroid Build Coastguard Worker
781*9880d681SAndroid Build Coastguard Workerbb1:
782*9880d681SAndroid Build Coastguard Worker  br i1 undef, label %bb2, label %bb3
783*9880d681SAndroid Build Coastguard Worker
784*9880d681SAndroid Build Coastguard Workerbb2:
785*9880d681SAndroid Build Coastguard Worker  switch i8 undef, label %bb1 [
786*9880d681SAndroid Build Coastguard Worker    i8 44, label %bb2
787*9880d681SAndroid Build Coastguard Worker  ]
788*9880d681SAndroid Build Coastguard Worker
789*9880d681SAndroid Build Coastguard Workerbb3:
790*9880d681SAndroid Build Coastguard Worker  switch i8 undef, label %bb1 [
791*9880d681SAndroid Build Coastguard Worker    i8 44, label %bb2
792*9880d681SAndroid Build Coastguard Worker  ]
793*9880d681SAndroid Build Coastguard Worker}
794*9880d681SAndroid Build Coastguard Worker
795*9880d681SAndroid Build Coastguard Worker; Test an interesting case using nested loops that share a bottom block.
796*9880d681SAndroid Build Coastguard Worker
797*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: test9:
798*9880d681SAndroid Build Coastguard Worker; CHECK:       .LBB18_1:
799*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:  loop{{$}}
800*9880d681SAndroid Build Coastguard Worker; CHECK-NOT:   block
801*9880d681SAndroid Build Coastguard Worker; CHECK:       br_if     1, {{[^,]+}}{{$}}
802*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:  .LBB18_2:
803*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:  loop{{$}}
804*9880d681SAndroid Build Coastguard Worker; CHECK-NOT:   block
805*9880d681SAndroid Build Coastguard Worker; CHECK:       block{{$}}
806*9880d681SAndroid Build Coastguard Worker; CHECK-NOT:   block
807*9880d681SAndroid Build Coastguard Worker; CHECK:       br_if     0, {{[^,]+}}{{$}}
808*9880d681SAndroid Build Coastguard Worker; CHECK-NOT:   block
809*9880d681SAndroid Build Coastguard Worker; CHECK:       br_if     3, {{[^,]+}}{{$}}
810*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:  br        1{{$}}
811*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:  .LBB18_4:
812*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:  end_block{{$}}
813*9880d681SAndroid Build Coastguard Worker; CHECK-NOT:   block
814*9880d681SAndroid Build Coastguard Worker; CHECK:       br_if     2, {{[^,]+}}{{$}}
815*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:  br        0{{$}}
816*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:  .LBB18_5:
817*9880d681SAndroid Build Coastguard Worker; CHECK-NOT:   block
818*9880d681SAndroid Build Coastguard Worker; CHECK:       return{{$}}
819*9880d681SAndroid Build Coastguard Worker; OPT-LABEL: test9:
820*9880d681SAndroid Build Coastguard Worker; OPT:       .LBB18_1:
821*9880d681SAndroid Build Coastguard Worker; OPT-NEXT:  loop{{$}}
822*9880d681SAndroid Build Coastguard Worker; OPT-NOT:   block
823*9880d681SAndroid Build Coastguard Worker; OPT:       br_if     1, {{[^,]+}}{{$}}
824*9880d681SAndroid Build Coastguard Worker; OPT-NEXT:  .LBB18_2:
825*9880d681SAndroid Build Coastguard Worker; OPT-NEXT:  loop{{$}}
826*9880d681SAndroid Build Coastguard Worker; OPT-NOT:   block
827*9880d681SAndroid Build Coastguard Worker; OPT:       block{{$}}
828*9880d681SAndroid Build Coastguard Worker; OPT-NOT:   block
829*9880d681SAndroid Build Coastguard Worker; OPT:       br_if     0, {{[^,]+}}{{$}}
830*9880d681SAndroid Build Coastguard Worker; OPT-NOT:   block
831*9880d681SAndroid Build Coastguard Worker; OPT:       br_if     1, {{[^,]+}}{{$}}
832*9880d681SAndroid Build Coastguard Worker; OPT-NEXT:  br        3{{$}}
833*9880d681SAndroid Build Coastguard Worker; OPT-NEXT:  .LBB18_4:
834*9880d681SAndroid Build Coastguard Worker; OPT-NEXT:  end_block{{$}}
835*9880d681SAndroid Build Coastguard Worker; OPT-NOT:   block
836*9880d681SAndroid Build Coastguard Worker; OPT:       br_if     0, {{[^,]+}}{{$}}
837*9880d681SAndroid Build Coastguard Worker; OPT-NEXT:  br        2{{$}}
838*9880d681SAndroid Build Coastguard Worker; OPT-NEXT:  .LBB18_5:
839*9880d681SAndroid Build Coastguard Worker; OPT-NOT:   block
840*9880d681SAndroid Build Coastguard Worker; OPT:       return{{$}}
841*9880d681SAndroid Build Coastguard Workerdeclare i1 @a()
842*9880d681SAndroid Build Coastguard Workerdefine void @test9() {
843*9880d681SAndroid Build Coastguard Workerentry:
844*9880d681SAndroid Build Coastguard Worker  store volatile i32 0, i32* null
845*9880d681SAndroid Build Coastguard Worker  br label %header
846*9880d681SAndroid Build Coastguard Worker
847*9880d681SAndroid Build Coastguard Workerheader:
848*9880d681SAndroid Build Coastguard Worker  store volatile i32 1, i32* null
849*9880d681SAndroid Build Coastguard Worker  %call4 = call i1 @a()
850*9880d681SAndroid Build Coastguard Worker  br i1 %call4, label %header2, label %end
851*9880d681SAndroid Build Coastguard Worker
852*9880d681SAndroid Build Coastguard Workerheader2:
853*9880d681SAndroid Build Coastguard Worker  store volatile i32 2, i32* null
854*9880d681SAndroid Build Coastguard Worker  %call = call i1 @a()
855*9880d681SAndroid Build Coastguard Worker  br i1 %call, label %if.then, label %if.else
856*9880d681SAndroid Build Coastguard Worker
857*9880d681SAndroid Build Coastguard Workerif.then:
858*9880d681SAndroid Build Coastguard Worker  store volatile i32 3, i32* null
859*9880d681SAndroid Build Coastguard Worker  %call3 = call i1 @a()
860*9880d681SAndroid Build Coastguard Worker  br i1 %call3, label %header2, label %header
861*9880d681SAndroid Build Coastguard Worker
862*9880d681SAndroid Build Coastguard Workerif.else:
863*9880d681SAndroid Build Coastguard Worker  store volatile i32 4, i32* null
864*9880d681SAndroid Build Coastguard Worker  %call2 = call i1 @a()
865*9880d681SAndroid Build Coastguard Worker  br i1 %call2, label %header2, label %header
866*9880d681SAndroid Build Coastguard Worker
867*9880d681SAndroid Build Coastguard Workerend:
868*9880d681SAndroid Build Coastguard Worker  store volatile i32 5, i32* null
869*9880d681SAndroid Build Coastguard Worker  ret void
870*9880d681SAndroid Build Coastguard Worker}
871*9880d681SAndroid Build Coastguard Worker
872*9880d681SAndroid Build Coastguard Worker; Test an interesting case involving nested loops sharing a loop bottom,
873*9880d681SAndroid Build Coastguard Worker; and loop exits to a block with unreachable.
874*9880d681SAndroid Build Coastguard Worker
875*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: test10:
876*9880d681SAndroid Build Coastguard Worker; CHECK:       .LBB19_1:
877*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:  loop{{$}}
878*9880d681SAndroid Build Coastguard Worker; CHECK-NOT:   block
879*9880d681SAndroid Build Coastguard Worker; CHECK:       br_if    0, {{[^,]+}}{{$}}
880*9880d681SAndroid Build Coastguard Worker; CHECK:       .LBB19_3:
881*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:  block{{$}}
882*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:  loop{{$}}
883*9880d681SAndroid Build Coastguard Worker; CHECK-NOT:   block
884*9880d681SAndroid Build Coastguard Worker; CHECK:       .LBB19_4:
885*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:  loop{{$}}
886*9880d681SAndroid Build Coastguard Worker; CHECK-NOT:   block
887*9880d681SAndroid Build Coastguard Worker; CHECK:       br_if    5, {{[^,]+}}{{$}}
888*9880d681SAndroid Build Coastguard Worker; CHECK-NOT:   block
889*9880d681SAndroid Build Coastguard Worker; CHECK:       br_table  {{[^,]+}}, 0, 1, 5, 2, 4, 0{{$}}
890*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:  .LBB19_6:
891*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:  end_loop{{$}}
892*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:  end_loop{{$}}
893*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:  return{{$}}
894*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:  .LBB19_7:
895*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:  end_block{{$}}
896*9880d681SAndroid Build Coastguard Worker; CHECK-NOT:   block
897*9880d681SAndroid Build Coastguard Worker; CHECK:       br       0{{$}}
898*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:  .LBB19_8:
899*9880d681SAndroid Build Coastguard Worker; OPT-LABEL: test10:
900*9880d681SAndroid Build Coastguard Worker; OPT:       .LBB19_1:
901*9880d681SAndroid Build Coastguard Worker; OPT-NEXT:  loop{{$}}
902*9880d681SAndroid Build Coastguard Worker; OPT-NOT:   block
903*9880d681SAndroid Build Coastguard Worker; OPT:       br_if    0, {{[^,]+}}{{$}}
904*9880d681SAndroid Build Coastguard Worker; OPT:       .LBB19_3:
905*9880d681SAndroid Build Coastguard Worker; OPT-NEXT:  block{{$}}
906*9880d681SAndroid Build Coastguard Worker; OPT-NEXT:  loop{{$}}
907*9880d681SAndroid Build Coastguard Worker; OPT-NOT:   block
908*9880d681SAndroid Build Coastguard Worker; OPT:       .LBB19_4:
909*9880d681SAndroid Build Coastguard Worker; OPT-NEXT:  loop{{$}}
910*9880d681SAndroid Build Coastguard Worker; OPT-NOT:   block
911*9880d681SAndroid Build Coastguard Worker; OPT:       br_if    5, {{[^,]+}}{{$}}
912*9880d681SAndroid Build Coastguard Worker; OPT-NOT:   block
913*9880d681SAndroid Build Coastguard Worker; OPT:       br_table  {{[^,]+}}, 0, 1, 5, 2, 4, 0{{$}}
914*9880d681SAndroid Build Coastguard Worker; OPT-NEXT:  .LBB19_6:
915*9880d681SAndroid Build Coastguard Worker; OPT-NEXT:  end_loop{{$}}
916*9880d681SAndroid Build Coastguard Worker; OPT-NEXT:  end_loop{{$}}
917*9880d681SAndroid Build Coastguard Worker; OPT-NEXT:  return{{$}}
918*9880d681SAndroid Build Coastguard Worker; OPT-NEXT:  .LBB19_7:
919*9880d681SAndroid Build Coastguard Worker; OPT-NEXT:  end_block{{$}}
920*9880d681SAndroid Build Coastguard Worker; OPT-NOT:   block
921*9880d681SAndroid Build Coastguard Worker; OPT:       br       0{{$}}
922*9880d681SAndroid Build Coastguard Worker; OPT-NEXT:  .LBB19_8:
923*9880d681SAndroid Build Coastguard Workerdefine void @test10() {
924*9880d681SAndroid Build Coastguard Workerbb0:
925*9880d681SAndroid Build Coastguard Worker  br label %bb1
926*9880d681SAndroid Build Coastguard Worker
927*9880d681SAndroid Build Coastguard Workerbb1:
928*9880d681SAndroid Build Coastguard Worker  %tmp = phi i32 [ 2, %bb0 ], [ 3, %bb3 ]
929*9880d681SAndroid Build Coastguard Worker  %tmp3 = phi i32 [ undef, %bb0 ], [ %tmp11, %bb3 ]
930*9880d681SAndroid Build Coastguard Worker  %tmp4 = icmp eq i32 %tmp3, 0
931*9880d681SAndroid Build Coastguard Worker  br i1 %tmp4, label %bb4, label %bb2
932*9880d681SAndroid Build Coastguard Worker
933*9880d681SAndroid Build Coastguard Workerbb2:
934*9880d681SAndroid Build Coastguard Worker  br label %bb3
935*9880d681SAndroid Build Coastguard Worker
936*9880d681SAndroid Build Coastguard Workerbb3:
937*9880d681SAndroid Build Coastguard Worker  %tmp11 = phi i32 [ 1, %bb5 ], [ 0, %bb2 ]
938*9880d681SAndroid Build Coastguard Worker  br label %bb1
939*9880d681SAndroid Build Coastguard Worker
940*9880d681SAndroid Build Coastguard Workerbb4:
941*9880d681SAndroid Build Coastguard Worker  %tmp6 = phi i32 [ %tmp9, %bb5 ], [ 4, %bb1 ]
942*9880d681SAndroid Build Coastguard Worker  %tmp7 = phi i32 [ %tmp6, %bb5 ], [ %tmp, %bb1 ]
943*9880d681SAndroid Build Coastguard Worker  br label %bb5
944*9880d681SAndroid Build Coastguard Worker
945*9880d681SAndroid Build Coastguard Workerbb5:
946*9880d681SAndroid Build Coastguard Worker  %tmp9 = phi i32 [ %tmp6, %bb5 ], [ %tmp7, %bb4 ]
947*9880d681SAndroid Build Coastguard Worker  switch i32 %tmp9, label %bb2 [
948*9880d681SAndroid Build Coastguard Worker    i32 0, label %bb5
949*9880d681SAndroid Build Coastguard Worker    i32 1, label %bb6
950*9880d681SAndroid Build Coastguard Worker    i32 3, label %bb4
951*9880d681SAndroid Build Coastguard Worker    i32 4, label %bb3
952*9880d681SAndroid Build Coastguard Worker  ]
953*9880d681SAndroid Build Coastguard Worker
954*9880d681SAndroid Build Coastguard Workerbb6:
955*9880d681SAndroid Build Coastguard Worker  ret void
956*9880d681SAndroid Build Coastguard Worker}
957*9880d681SAndroid Build Coastguard Worker
958*9880d681SAndroid Build Coastguard Worker; Test a CFG DAG with interesting merging.
959*9880d681SAndroid Build Coastguard Worker
960*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: test11:
961*9880d681SAndroid Build Coastguard Worker; CHECK:       block{{$}}
962*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:  block{{$}}
963*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:  block{{$}}
964*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:  block{{$}}
965*9880d681SAndroid Build Coastguard Worker; CHECK:       br_if        0, {{[^,]+}}{{$}}
966*9880d681SAndroid Build Coastguard Worker; CHECK-NOT:   block
967*9880d681SAndroid Build Coastguard Worker; CHECK:       block{{$}}
968*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:  br_if        0, {{[^,]+}}{{$}}
969*9880d681SAndroid Build Coastguard Worker; CHECK-NOT:   block
970*9880d681SAndroid Build Coastguard Worker; CHECK:       br_if        2, {{[^,]+}}{{$}}
971*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:  .LBB20_3:
972*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:  end_block{{$}}
973*9880d681SAndroid Build Coastguard Worker; CHECK-NOT:   block
974*9880d681SAndroid Build Coastguard Worker; CHECK:       return{{$}}
975*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:  .LBB20_4:
976*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:  end_block{{$}}
977*9880d681SAndroid Build Coastguard Worker; CHECK-NOT:   block
978*9880d681SAndroid Build Coastguard Worker; CHECK:       br_if        1, {{[^,]+}}{{$}}
979*9880d681SAndroid Build Coastguard Worker; CHECK-NOT:   block
980*9880d681SAndroid Build Coastguard Worker; CHECK:       br_if        2, {{[^,]+}}{{$}}
981*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:  .LBB20_6:
982*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:  end_block{{$}}
983*9880d681SAndroid Build Coastguard Worker; CHECK-NOT:   block
984*9880d681SAndroid Build Coastguard Worker; CHECK:       return{{$}}
985*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:  .LBB20_7:
986*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:  end_block{{$}}
987*9880d681SAndroid Build Coastguard Worker; CHECK-NOT:   block
988*9880d681SAndroid Build Coastguard Worker; CHECK:       return{{$}}
989*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:  .LBB20_8:
990*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:  end_block{{$}}
991*9880d681SAndroid Build Coastguard Worker; CHECK-NOT:   block
992*9880d681SAndroid Build Coastguard Worker; CHECK:       return{{$}}
993*9880d681SAndroid Build Coastguard Worker; OPT-LABEL: test11:
994*9880d681SAndroid Build Coastguard Worker; OPT:       block{{$}}
995*9880d681SAndroid Build Coastguard Worker; OPT-NEXT:  block{{$}}
996*9880d681SAndroid Build Coastguard Worker; OPT:       br_if        0, $pop{{[0-9]+}}{{$}}
997*9880d681SAndroid Build Coastguard Worker; OPT-NOT:   block
998*9880d681SAndroid Build Coastguard Worker; OPT:       block{{$}}
999*9880d681SAndroid Build Coastguard Worker; OPT-NEXT:  br_if        0, $0{{$}}
1000*9880d681SAndroid Build Coastguard Worker; OPT-NOT:   block
1001*9880d681SAndroid Build Coastguard Worker; OPT:       br_if        2, {{[^,]+}}{{$}}
1002*9880d681SAndroid Build Coastguard Worker; OPT-NEXT:  .LBB20_3:
1003*9880d681SAndroid Build Coastguard Worker; OPT-NEXT:  end_block{{$}}
1004*9880d681SAndroid Build Coastguard Worker; OPT-NOT:   block
1005*9880d681SAndroid Build Coastguard Worker; OPT:       return{{$}}
1006*9880d681SAndroid Build Coastguard Worker; OPT-NEXT:  .LBB20_4:
1007*9880d681SAndroid Build Coastguard Worker; OPT-NEXT:  end_block{{$}}
1008*9880d681SAndroid Build Coastguard Worker; OPT-NOT:   block
1009*9880d681SAndroid Build Coastguard Worker; OPT:       block{{$}}
1010*9880d681SAndroid Build Coastguard Worker; OPT-NOT:   block
1011*9880d681SAndroid Build Coastguard Worker; OPT:       br_if        0, $pop{{[0-9]+}}{{$}}
1012*9880d681SAndroid Build Coastguard Worker; OPT-NOT:   block
1013*9880d681SAndroid Build Coastguard Worker; OPT:       return{{$}}
1014*9880d681SAndroid Build Coastguard Worker; OPT-NEXT:  .LBB20_6:
1015*9880d681SAndroid Build Coastguard Worker; OPT-NEXT:  end_block{{$}}
1016*9880d681SAndroid Build Coastguard Worker; OPT-NOT:   block
1017*9880d681SAndroid Build Coastguard Worker; OPT:       br_if        0, $pop{{[0-9]+}}{{$}}
1018*9880d681SAndroid Build Coastguard Worker; OPT-NOT:   block
1019*9880d681SAndroid Build Coastguard Worker; OPT:       return{{$}}
1020*9880d681SAndroid Build Coastguard Worker; OPT-NEXT:  .LBB20_8:
1021*9880d681SAndroid Build Coastguard Worker; OPT-NEXT:  end_block{{$}}
1022*9880d681SAndroid Build Coastguard Worker; OPT-NOT:   block
1023*9880d681SAndroid Build Coastguard Worker; OPT:       return{{$}}
1024*9880d681SAndroid Build Coastguard Workerdefine void @test11() {
1025*9880d681SAndroid Build Coastguard Workerbb0:
1026*9880d681SAndroid Build Coastguard Worker  store volatile i32 0, i32* null
1027*9880d681SAndroid Build Coastguard Worker  br i1 undef, label %bb1, label %bb4
1028*9880d681SAndroid Build Coastguard Workerbb1:
1029*9880d681SAndroid Build Coastguard Worker  store volatile i32 1, i32* null
1030*9880d681SAndroid Build Coastguard Worker  br i1 undef, label %bb3, label %bb2
1031*9880d681SAndroid Build Coastguard Workerbb2:
1032*9880d681SAndroid Build Coastguard Worker  store volatile i32 2, i32* null
1033*9880d681SAndroid Build Coastguard Worker  br i1 undef, label %bb3, label %bb7
1034*9880d681SAndroid Build Coastguard Workerbb3:
1035*9880d681SAndroid Build Coastguard Worker  store volatile i32 3, i32* null
1036*9880d681SAndroid Build Coastguard Worker  ret void
1037*9880d681SAndroid Build Coastguard Workerbb4:
1038*9880d681SAndroid Build Coastguard Worker  store volatile i32 4, i32* null
1039*9880d681SAndroid Build Coastguard Worker  br i1 undef, label %bb8, label %bb5
1040*9880d681SAndroid Build Coastguard Workerbb5:
1041*9880d681SAndroid Build Coastguard Worker  store volatile i32 5, i32* null
1042*9880d681SAndroid Build Coastguard Worker  br i1 undef, label %bb6, label %bb7
1043*9880d681SAndroid Build Coastguard Workerbb6:
1044*9880d681SAndroid Build Coastguard Worker  store volatile i32 6, i32* null
1045*9880d681SAndroid Build Coastguard Worker  ret void
1046*9880d681SAndroid Build Coastguard Workerbb7:
1047*9880d681SAndroid Build Coastguard Worker  store volatile i32 7, i32* null
1048*9880d681SAndroid Build Coastguard Worker  ret void
1049*9880d681SAndroid Build Coastguard Workerbb8:
1050*9880d681SAndroid Build Coastguard Worker  store volatile i32 8, i32* null
1051*9880d681SAndroid Build Coastguard Worker  ret void
1052*9880d681SAndroid Build Coastguard Worker}
1053*9880d681SAndroid Build Coastguard Worker
1054*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: test12:
1055*9880d681SAndroid Build Coastguard Worker; CHECK:       .LBB21_1:
1056*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:  loop{{$}}
1057*9880d681SAndroid Build Coastguard Worker; CHECK-NOT:   block
1058*9880d681SAndroid Build Coastguard Worker; CHECK:       block{{$}}
1059*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:  block{{$}}
1060*9880d681SAndroid Build Coastguard Worker; CHECK:       br_if       0, {{[^,]+}}{{$}}
1061*9880d681SAndroid Build Coastguard Worker; CHECK-NOT:   block
1062*9880d681SAndroid Build Coastguard Worker; CHECK:       br_if       1, {{[^,]+}}{{$}}
1063*9880d681SAndroid Build Coastguard Worker; CHECK-NOT:   block
1064*9880d681SAndroid Build Coastguard Worker; CHECK:       br_if       1, {{[^,]+}}{{$}}
1065*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:  br          3{{$}}
1066*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:  .LBB21_4:
1067*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:  end_block{{$}}
1068*9880d681SAndroid Build Coastguard Worker; CHECK-NOT:   block
1069*9880d681SAndroid Build Coastguard Worker; CHECK:       br_if       0, {{[^,]+}}{{$}}
1070*9880d681SAndroid Build Coastguard Worker; CHECK-NOT:   block
1071*9880d681SAndroid Build Coastguard Worker; CHECK:       br_if       2, {{[^,]+}}{{$}}
1072*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:  .LBB21_6:
1073*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:  end_block{{$}}
1074*9880d681SAndroid Build Coastguard Worker; CHECK-NOT:   block
1075*9880d681SAndroid Build Coastguard Worker; CHECK:       br          0{{$}}
1076*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:  .LBB21_7:
1077*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:  end_loop{{$}}
1078*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:  return{{$}}
1079*9880d681SAndroid Build Coastguard Worker; OPT-LABEL: test12:
1080*9880d681SAndroid Build Coastguard Worker; OPT:       .LBB21_1:
1081*9880d681SAndroid Build Coastguard Worker; OPT-NEXT:  loop{{$}}
1082*9880d681SAndroid Build Coastguard Worker; OPT-NOT:   block
1083*9880d681SAndroid Build Coastguard Worker; OPT:       block{{$}}
1084*9880d681SAndroid Build Coastguard Worker; OPT-NEXT:  block{{$}}
1085*9880d681SAndroid Build Coastguard Worker; OPT:       br_if       0, {{[^,]+}}{{$}}
1086*9880d681SAndroid Build Coastguard Worker; OPT-NOT:   block
1087*9880d681SAndroid Build Coastguard Worker; OPT:       br_if       1, {{[^,]+}}{{$}}
1088*9880d681SAndroid Build Coastguard Worker; OPT-NOT:   block
1089*9880d681SAndroid Build Coastguard Worker; OPT:       br_if       1, {{[^,]+}}{{$}}
1090*9880d681SAndroid Build Coastguard Worker; OPT-NEXT:  br          3{{$}}
1091*9880d681SAndroid Build Coastguard Worker; OPT-NEXT:  .LBB21_4:
1092*9880d681SAndroid Build Coastguard Worker; OPT-NEXT:  end_block{{$}}
1093*9880d681SAndroid Build Coastguard Worker; OPT-NOT:   block
1094*9880d681SAndroid Build Coastguard Worker; OPT:       br_if       0, {{[^,]+}}{{$}}
1095*9880d681SAndroid Build Coastguard Worker; OPT-NOT:   block
1096*9880d681SAndroid Build Coastguard Worker; OPT:       br_if       2, {{[^,]+}}{{$}}
1097*9880d681SAndroid Build Coastguard Worker; OPT-NEXT:  .LBB21_6:
1098*9880d681SAndroid Build Coastguard Worker; OPT-NEXT:  end_block{{$}}
1099*9880d681SAndroid Build Coastguard Worker; OPT:       br          0{{$}}
1100*9880d681SAndroid Build Coastguard Worker; OPT-NEXT:  .LBB21_7:
1101*9880d681SAndroid Build Coastguard Worker; OPT-NEXT:  end_loop{{$}}
1102*9880d681SAndroid Build Coastguard Worker; OPT-NEXT:  return{{$}}
1103*9880d681SAndroid Build Coastguard Workerdefine void @test12(i8* %arg) {
1104*9880d681SAndroid Build Coastguard Workerbb:
1105*9880d681SAndroid Build Coastguard Worker  br label %bb1
1106*9880d681SAndroid Build Coastguard Worker
1107*9880d681SAndroid Build Coastguard Workerbb1:
1108*9880d681SAndroid Build Coastguard Worker  %tmp = phi i32 [ 0, %bb ], [ %tmp5, %bb4 ]
1109*9880d681SAndroid Build Coastguard Worker  %tmp2 = getelementptr i8, i8* %arg, i32 %tmp
1110*9880d681SAndroid Build Coastguard Worker  %tmp3 = load i8, i8* %tmp2
1111*9880d681SAndroid Build Coastguard Worker  switch i8 %tmp3, label %bb7 [
1112*9880d681SAndroid Build Coastguard Worker    i8 42, label %bb4
1113*9880d681SAndroid Build Coastguard Worker    i8 76, label %bb4
1114*9880d681SAndroid Build Coastguard Worker    i8 108, label %bb4
1115*9880d681SAndroid Build Coastguard Worker    i8 104, label %bb4
1116*9880d681SAndroid Build Coastguard Worker  ]
1117*9880d681SAndroid Build Coastguard Worker
1118*9880d681SAndroid Build Coastguard Workerbb4:
1119*9880d681SAndroid Build Coastguard Worker  %tmp5 = add i32 %tmp, 1
1120*9880d681SAndroid Build Coastguard Worker  br label %bb1
1121*9880d681SAndroid Build Coastguard Worker
1122*9880d681SAndroid Build Coastguard Workerbb7:
1123*9880d681SAndroid Build Coastguard Worker  ret void
1124*9880d681SAndroid Build Coastguard Worker}
1125*9880d681SAndroid Build Coastguard Worker
1126*9880d681SAndroid Build Coastguard Worker; A block can be "branched to" from another even if it is also reachable via
1127*9880d681SAndroid Build Coastguard Worker; fallthrough from the other. This would normally be optimized away, so use
1128*9880d681SAndroid Build Coastguard Worker; optnone to disable optimizations to test this case.
1129*9880d681SAndroid Build Coastguard Worker
1130*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: test13:
1131*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:  .local i32{{$}}
1132*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:  block{{$}}
1133*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:  block{{$}}
1134*9880d681SAndroid Build Coastguard Worker; CHECK:       br_if 0, $pop0{{$}}
1135*9880d681SAndroid Build Coastguard Worker; CHECK:       block{{$}}
1136*9880d681SAndroid Build Coastguard Worker; CHECK:       br_if 0, $pop3{{$}}
1137*9880d681SAndroid Build Coastguard Worker; CHECK:       .LBB22_3:
1138*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:  end_block{{$}}
1139*9880d681SAndroid Build Coastguard Worker; CHECK:       br_if 1, $pop{{[0-9]+}}{{$}}
1140*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:  br 1{{$}}
1141*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:  .LBB22_4:
1142*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:  end_block{{$}}
1143*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:  return{{$}}
1144*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:  .LBB22_5:
1145*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:  end_block{{$}}
1146*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:  unreachable{{$}}
1147*9880d681SAndroid Build Coastguard Worker; OPT-LABEL: test13:
1148*9880d681SAndroid Build Coastguard Worker; OPT-NEXT:  .local i32{{$}}
1149*9880d681SAndroid Build Coastguard Worker; OPT-NEXT:  block{{$}}
1150*9880d681SAndroid Build Coastguard Worker; OPT-NEXT:  block{{$}}
1151*9880d681SAndroid Build Coastguard Worker; OPT:       br_if 0, $pop0{{$}}
1152*9880d681SAndroid Build Coastguard Worker; OPT:       block{{$}}
1153*9880d681SAndroid Build Coastguard Worker; OPT:       br_if 0, $pop3{{$}}
1154*9880d681SAndroid Build Coastguard Worker; OPT:       .LBB22_3:
1155*9880d681SAndroid Build Coastguard Worker; OPT-NEXT:  end_block{{$}}
1156*9880d681SAndroid Build Coastguard Worker; OPT:       br_if 1, $pop{{[0-9]+}}{{$}}
1157*9880d681SAndroid Build Coastguard Worker; OPT-NEXT:  br 1{{$}}
1158*9880d681SAndroid Build Coastguard Worker; OPT-NEXT:  .LBB22_4:
1159*9880d681SAndroid Build Coastguard Worker; OPT-NEXT:  end_block
1160*9880d681SAndroid Build Coastguard Worker; OPT-NEXT:  return
1161*9880d681SAndroid Build Coastguard Worker; OPT-NEXT:  .LBB22_5:
1162*9880d681SAndroid Build Coastguard Worker; OPT-NEXT:  end_block{{$}}
1163*9880d681SAndroid Build Coastguard Worker; OPT-NEXT:  unreachable{{$}}
1164*9880d681SAndroid Build Coastguard Workerdefine void @test13() noinline optnone {
1165*9880d681SAndroid Build Coastguard Workerbb:
1166*9880d681SAndroid Build Coastguard Worker  br i1 undef, label %bb5, label %bb2
1167*9880d681SAndroid Build Coastguard Workerbb1:
1168*9880d681SAndroid Build Coastguard Worker  unreachable
1169*9880d681SAndroid Build Coastguard Workerbb2:
1170*9880d681SAndroid Build Coastguard Worker  br i1 undef, label %bb3, label %bb4
1171*9880d681SAndroid Build Coastguard Workerbb3:
1172*9880d681SAndroid Build Coastguard Worker  br label %bb4
1173*9880d681SAndroid Build Coastguard Workerbb4:
1174*9880d681SAndroid Build Coastguard Worker  %tmp = phi i1 [ false, %bb2 ], [ false, %bb3 ]
1175*9880d681SAndroid Build Coastguard Worker  br i1 %tmp, label %bb1, label %bb1
1176*9880d681SAndroid Build Coastguard Workerbb5:
1177*9880d681SAndroid Build Coastguard Worker  ret void
1178*9880d681SAndroid Build Coastguard Worker}
1179*9880d681SAndroid Build Coastguard Worker
1180*9880d681SAndroid Build Coastguard Worker; Test a case with a single-block loop that has another loop
1181*9880d681SAndroid Build Coastguard Worker; as a successor. The end_loop for the first loop should go
1182*9880d681SAndroid Build Coastguard Worker; before the loop for the second.
1183*9880d681SAndroid Build Coastguard Worker
1184*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: test14:
1185*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: .LBB23_1:{{$}}
1186*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:     loop{{$}}
1187*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:     i32.const   $push0=, 0{{$}}
1188*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:     br_if       0, $pop0{{$}}
1189*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:     end_loop{{$}}
1190*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: .LBB23_3:{{$}}
1191*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:     loop{{$}}
1192*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:     i32.const   $push1=, 0{{$}}
1193*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:     br_if       0, $pop1{{$}}
1194*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:     end_loop{{$}}
1195*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:     return{{$}}
1196*9880d681SAndroid Build Coastguard Workerdefine void @test14() {
1197*9880d681SAndroid Build Coastguard Workerbb:
1198*9880d681SAndroid Build Coastguard Worker  br label %bb1
1199*9880d681SAndroid Build Coastguard Worker
1200*9880d681SAndroid Build Coastguard Workerbb1:
1201*9880d681SAndroid Build Coastguard Worker  %tmp = bitcast i1 undef to i1
1202*9880d681SAndroid Build Coastguard Worker  br i1 %tmp, label %bb3, label %bb1
1203*9880d681SAndroid Build Coastguard Worker
1204*9880d681SAndroid Build Coastguard Workerbb3:
1205*9880d681SAndroid Build Coastguard Worker  br label %bb4
1206*9880d681SAndroid Build Coastguard Worker
1207*9880d681SAndroid Build Coastguard Workerbb4:
1208*9880d681SAndroid Build Coastguard Worker  br i1 undef, label %bb7, label %bb48
1209*9880d681SAndroid Build Coastguard Worker
1210*9880d681SAndroid Build Coastguard Workerbb7:
1211*9880d681SAndroid Build Coastguard Worker  br i1 undef, label %bb12, label %bb12
1212*9880d681SAndroid Build Coastguard Worker
1213*9880d681SAndroid Build Coastguard Workerbb12:
1214*9880d681SAndroid Build Coastguard Worker  br i1 undef, label %bb17, label %bb17
1215*9880d681SAndroid Build Coastguard Worker
1216*9880d681SAndroid Build Coastguard Workerbb17:
1217*9880d681SAndroid Build Coastguard Worker  br i1 undef, label %bb22, label %bb22
1218*9880d681SAndroid Build Coastguard Worker
1219*9880d681SAndroid Build Coastguard Workerbb22:
1220*9880d681SAndroid Build Coastguard Worker  br i1 undef, label %bb27, label %bb27
1221*9880d681SAndroid Build Coastguard Worker
1222*9880d681SAndroid Build Coastguard Workerbb27:
1223*9880d681SAndroid Build Coastguard Worker  br i1 undef, label %bb30, label %bb30
1224*9880d681SAndroid Build Coastguard Worker
1225*9880d681SAndroid Build Coastguard Workerbb30:
1226*9880d681SAndroid Build Coastguard Worker  br i1 undef, label %bb35, label %bb35
1227*9880d681SAndroid Build Coastguard Worker
1228*9880d681SAndroid Build Coastguard Workerbb35:
1229*9880d681SAndroid Build Coastguard Worker  br i1 undef, label %bb38, label %bb38
1230*9880d681SAndroid Build Coastguard Worker
1231*9880d681SAndroid Build Coastguard Workerbb38:
1232*9880d681SAndroid Build Coastguard Worker  br i1 undef, label %bb48, label %bb48
1233*9880d681SAndroid Build Coastguard Worker
1234*9880d681SAndroid Build Coastguard Workerbb48:
1235*9880d681SAndroid Build Coastguard Worker  %tmp49 = bitcast i1 undef to i1
1236*9880d681SAndroid Build Coastguard Worker  br i1 %tmp49, label %bb3, label %bb50
1237*9880d681SAndroid Build Coastguard Worker
1238*9880d681SAndroid Build Coastguard Workerbb50:
1239*9880d681SAndroid Build Coastguard Worker  ret void
1240*9880d681SAndroid Build Coastguard Worker}
1241*9880d681SAndroid Build Coastguard Worker
1242*9880d681SAndroid Build Coastguard Worker; Test that a block boundary which ends one block, begins another block, and
1243*9880d681SAndroid Build Coastguard Worker; also begins a loop, has the markers placed in the correct order.
1244*9880d681SAndroid Build Coastguard Worker
1245*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: test15:
1246*9880d681SAndroid Build Coastguard Worker; CHECK:        block
1247*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:   block
1248*9880d681SAndroid Build Coastguard Worker; CHECK:        br_if       0, $pop{{.*}}{{$}}
1249*9880d681SAndroid Build Coastguard Worker; CHECK:        .LBB24_2:
1250*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:   block{{$}}
1251*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:   loop{{$}}
1252*9880d681SAndroid Build Coastguard Worker; CHECK:        br_if       1, $pop{{.*}}{{$}}
1253*9880d681SAndroid Build Coastguard Worker; CHECK:        br_if       0, ${{.*}}{{$}}
1254*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:   br          2{{$}}
1255*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:   .LBB24_4:
1256*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:   end_loop{{$}}
1257*9880d681SAndroid Build Coastguard Worker; CHECK:        .LBB24_5:
1258*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:   end_block{{$}}
1259*9880d681SAndroid Build Coastguard Worker; CHECK:        br_if       1, $pop{{.*}}{{$}}
1260*9880d681SAndroid Build Coastguard Worker; CHECK:        return{{$}}
1261*9880d681SAndroid Build Coastguard Worker; CHECK:        .LBB24_7:
1262*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:   end_block{{$}}
1263*9880d681SAndroid Build Coastguard Worker; CHECK:        .LBB24_8:
1264*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:   end_block{{$}}
1265*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:   return{{$}}
1266*9880d681SAndroid Build Coastguard Worker; OPT-LABEL: test15:
1267*9880d681SAndroid Build Coastguard Worker; OPT:        block
1268*9880d681SAndroid Build Coastguard Worker; OPT:        block
1269*9880d681SAndroid Build Coastguard Worker; OPT-NEXT:   i32.const   $push
1270*9880d681SAndroid Build Coastguard Worker; OPT-NEXT:   i32.eqz     $push{{.*}}=, $pop{{.*}}{{$}}
1271*9880d681SAndroid Build Coastguard Worker; OPT-NEXT:   br_if       0, $pop{{.*}}{{$}}
1272*9880d681SAndroid Build Coastguard Worker; OPT-NEXT:   call        test15_callee1@FUNCTION{{$}}
1273*9880d681SAndroid Build Coastguard Worker; OPT-NEXT:   br          1{{$}}
1274*9880d681SAndroid Build Coastguard Worker; OPT-NEXT: .LBB24_2:
1275*9880d681SAndroid Build Coastguard Worker; OPT-NEXT:   end_block
1276*9880d681SAndroid Build Coastguard Worker; OPT-NEXT:   i32.const
1277*9880d681SAndroid Build Coastguard Worker; OPT-NEXT: .LBB24_3:
1278*9880d681SAndroid Build Coastguard Worker; OPT-NEXT:   block
1279*9880d681SAndroid Build Coastguard Worker; OPT-NEXT:   loop
1280*9880d681SAndroid Build Coastguard Worker%0 = type { i8, i32 }
1281*9880d681SAndroid Build Coastguard Workerdeclare void @test15_callee0()
1282*9880d681SAndroid Build Coastguard Workerdeclare void @test15_callee1()
1283*9880d681SAndroid Build Coastguard Workerdefine void @test15() {
1284*9880d681SAndroid Build Coastguard Workerbb:
1285*9880d681SAndroid Build Coastguard Worker  %tmp1 = icmp eq i8 1, 0
1286*9880d681SAndroid Build Coastguard Worker  br i1 %tmp1, label %bb2, label %bb14
1287*9880d681SAndroid Build Coastguard Worker
1288*9880d681SAndroid Build Coastguard Workerbb2:
1289*9880d681SAndroid Build Coastguard Worker  %tmp3 = phi %0** [ %tmp6, %bb5 ], [ null, %bb ]
1290*9880d681SAndroid Build Coastguard Worker  %tmp4 = icmp eq i32 0, 11
1291*9880d681SAndroid Build Coastguard Worker  br i1 %tmp4, label %bb5, label %bb8
1292*9880d681SAndroid Build Coastguard Worker
1293*9880d681SAndroid Build Coastguard Workerbb5:
1294*9880d681SAndroid Build Coastguard Worker  %tmp = bitcast i8* null to %0**
1295*9880d681SAndroid Build Coastguard Worker  %tmp6 = getelementptr %0*, %0** %tmp3, i32 1
1296*9880d681SAndroid Build Coastguard Worker  %tmp7 = icmp eq %0** %tmp6, null
1297*9880d681SAndroid Build Coastguard Worker  br i1 %tmp7, label %bb10, label %bb2
1298*9880d681SAndroid Build Coastguard Worker
1299*9880d681SAndroid Build Coastguard Workerbb8:
1300*9880d681SAndroid Build Coastguard Worker  %tmp9 = icmp eq %0** null, undef
1301*9880d681SAndroid Build Coastguard Worker  br label %bb10
1302*9880d681SAndroid Build Coastguard Worker
1303*9880d681SAndroid Build Coastguard Workerbb10:
1304*9880d681SAndroid Build Coastguard Worker  %tmp11 = phi %0** [ null, %bb8 ], [ %tmp, %bb5 ]
1305*9880d681SAndroid Build Coastguard Worker  %tmp12 = icmp eq %0** null, %tmp11
1306*9880d681SAndroid Build Coastguard Worker  br i1 %tmp12, label %bb15, label %bb13
1307*9880d681SAndroid Build Coastguard Worker
1308*9880d681SAndroid Build Coastguard Workerbb13:
1309*9880d681SAndroid Build Coastguard Worker  call void @test15_callee0()
1310*9880d681SAndroid Build Coastguard Worker  ret void
1311*9880d681SAndroid Build Coastguard Worker
1312*9880d681SAndroid Build Coastguard Workerbb14:
1313*9880d681SAndroid Build Coastguard Worker  call void @test15_callee1()
1314*9880d681SAndroid Build Coastguard Worker  ret void
1315*9880d681SAndroid Build Coastguard Worker
1316*9880d681SAndroid Build Coastguard Workerbb15:
1317*9880d681SAndroid Build Coastguard Worker  ret void
1318*9880d681SAndroid Build Coastguard Worker}
1319