blob: 442d0d4ea25bfa16ea9582f082faab533a0e982e [file] [log] [blame]
Dan Gohman8fe7e862015-12-14 22:51:54 +00001; RUN: llc < %s -asm-verbose=false -disable-block-placement -verify-machineinstrs | FileCheck %s
2; RUN: llc < %s -asm-verbose=false -verify-machineinstrs | FileCheck -check-prefix=OPT %s
Dan Gohman950a13c2015-09-16 16:51:30 +00003
4; Test the CFG stackifier pass.
5
Dan Gohman0c6f5ac2016-01-07 03:19:23 +00006target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
Dan Gohman950a13c2015-09-16 16:51:30 +00007target triple = "wasm32-unknown-unknown"
8
9declare void @something()
10
11; Test that loops are made contiguous, even in the presence of split backedges.
12
Dan Gohmane51c0582015-10-06 00:27:55 +000013; CHECK-LABEL: test0:
14; CHECK: loop
Dan Gohmanf0b165a2015-12-05 03:03:35 +000015; CHECK-NOT: br
Dan Gohman8fe7e862015-12-14 22:51:54 +000016; CHECK: i32.add
Dan Gohman442bfce2016-02-16 16:22:41 +000017; CHECK-NEXT: block
18; CHECK-NEXT: i32.lt_s
Dan Gohman8fe7e862015-12-14 22:51:54 +000019; CHECK-NEXT: br_if
Dan Gohman442bfce2016-02-16 16:22:41 +000020; CHECK-NEXT: return
21; CHECK-NEXT: .LBB0_3:
22; CHECK-NEXT: end_block
23; CHECK-NEXT: call
24; CHECK-NEXT: br
25; CHECK-NEXT: .LBB0_4:
26; CHECK-NEXT: end_loop
Dan Gohmanf0b165a2015-12-05 03:03:35 +000027; OPT-LABEL: test0:
28; OPT: loop
Dan Gohmanf0b165a2015-12-05 03:03:35 +000029; OPT-NOT: br
Dan Gohman8fe7e862015-12-14 22:51:54 +000030; OPT: i32.add
31; OPT-NEXT: i32.ge_s
32; OPT-NEXT: br_if
Dan Gohmanf0b165a2015-12-05 03:03:35 +000033; OPT-NOT: br
34; OPT: call
Dan Gohman1d68e80f2016-01-12 19:14:46 +000035; OPT: br 0{{$}}
Dan Gohmanf0b165a2015-12-05 03:03:35 +000036; OPT: return{{$}}
Dan Gohman950a13c2015-09-16 16:51:30 +000037define void @test0(i32 %n) {
38entry:
39 br label %header
40
41header:
42 %i = phi i32 [ 0, %entry ], [ %i.next, %back ]
43 %i.next = add i32 %i, 1
44
45 %c = icmp slt i32 %i.next, %n
46 br i1 %c, label %back, label %exit
47
48exit:
49 ret void
50
51back:
52 call void @something()
53 br label %header
54}
55
56; Same as test0, but the branch condition is reversed.
57
Dan Gohmane51c0582015-10-06 00:27:55 +000058; CHECK-LABEL: test1:
59; CHECK: loop
Dan Gohmanf0b165a2015-12-05 03:03:35 +000060; CHECK-NOT: br
Dan Gohman8fe7e862015-12-14 22:51:54 +000061; CHECK: i32.add
Dan Gohman442bfce2016-02-16 16:22:41 +000062; CHECK-NEXT: block
63; CHECK-NEXT: i32.lt_s
Dan Gohman8fe7e862015-12-14 22:51:54 +000064; CHECK-NEXT: br_if
Dan Gohman442bfce2016-02-16 16:22:41 +000065; CHECK-NEXT: return
66; CHECK-NEXT: .LBB1_3:
67; CHECK-NEXT: end_block
68; CHECK-NEXT: call
69; CHECK-NEXT: br
70; CHECK-NEXT: .LBB1_4:
71; CHECK-NEXT: end_loop
Dan Gohmanf0b165a2015-12-05 03:03:35 +000072; OPT-LABEL: test1:
73; OPT: loop
Dan Gohmanf0b165a2015-12-05 03:03:35 +000074; OPT-NOT: br
Dan Gohman8fe7e862015-12-14 22:51:54 +000075; OPT: i32.add
76; OPT-NEXT: i32.ge_s
77; OPT-NEXT: br_if
Dan Gohmanf0b165a2015-12-05 03:03:35 +000078; OPT-NOT: br
79; OPT: call
Dan Gohman1d68e80f2016-01-12 19:14:46 +000080; OPT: br 0{{$}}
Dan Gohmanf0b165a2015-12-05 03:03:35 +000081; OPT: return{{$}}
Dan Gohman950a13c2015-09-16 16:51:30 +000082define void @test1(i32 %n) {
83entry:
84 br label %header
85
86header:
87 %i = phi i32 [ 0, %entry ], [ %i.next, %back ]
88 %i.next = add i32 %i, 1
89
90 %c = icmp sge i32 %i.next, %n
91 br i1 %c, label %exit, label %back
92
93exit:
94 ret void
95
96back:
97 call void @something()
98 br label %header
99}
100
101; Test that a simple loop is handled as expected.
102
Dan Gohmane51c0582015-10-06 00:27:55 +0000103; CHECK-LABEL: test2:
Dan Gohman8f59cf72016-01-06 18:29:35 +0000104; CHECK-NOT: local
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000105; CHECK: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000106; CHECK: br_if 0, {{[^,]+}}{{$}}
Dan Gohman0cfb5f82016-05-10 04:24:02 +0000107; CHECK: .LBB2_{{[0-9]+}}:
Dan Gohman06b49582016-02-08 21:50:13 +0000108; CHECK: br_if 0, ${{[0-9]+}}{{$}}
Dan Gohman0cfb5f82016-05-10 04:24:02 +0000109; CHECK: .LBB2_{{[0-9]+}}:
Dan Gohmane51c0582015-10-06 00:27:55 +0000110; CHECK: return{{$}}
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000111; OPT-LABEL: test2:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000112; OPT-NOT: local
113; OPT: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000114; OPT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman0cfb5f82016-05-10 04:24:02 +0000115; OPT: .LBB2_{{[0-9]+}}:
Dan Gohman06b49582016-02-08 21:50:13 +0000116; OPT: br_if 0, ${{[0-9]+}}{{$}}
Dan Gohman0cfb5f82016-05-10 04:24:02 +0000117; OPT: .LBB2_{{[0-9]+}}:
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000118; OPT: return{{$}}
Dan Gohman950a13c2015-09-16 16:51:30 +0000119define void @test2(double* nocapture %p, i32 %n) {
120entry:
121 %cmp.4 = icmp sgt i32 %n, 0
122 br i1 %cmp.4, label %for.body.preheader, label %for.end
123
124for.body.preheader:
125 br label %for.body
126
127for.body:
128 %i.05 = phi i32 [ %inc, %for.body ], [ 0, %for.body.preheader ]
129 %arrayidx = getelementptr inbounds double, double* %p, i32 %i.05
130 %0 = load double, double* %arrayidx, align 8
131 %mul = fmul double %0, 3.200000e+00
132 store double %mul, double* %arrayidx, align 8
133 %inc = add nuw nsw i32 %i.05, 1
134 %exitcond = icmp eq i32 %inc, %n
135 br i1 %exitcond, label %for.end.loopexit, label %for.body
136
137for.end.loopexit:
138 br label %for.end
139
140for.end:
141 ret void
142}
143
Dan Gohmane51c0582015-10-06 00:27:55 +0000144; CHECK-LABEL: doublediamond:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000145; CHECK: block{{$}}
146; CHECK-NEXT: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000147; CHECK: br_if 0, ${{[^,]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000148; CHECK: br 1{{$}}
149; CHECK: .LBB3_2:
150; CHECK-NEXT: end_block{{$}}
151; CHECK: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000152; CHECK: br_if 0, ${{[^,]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000153; CHECK: br 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000154; CHECK: .LBB3_4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000155; CHECK-NEXT: end_block{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000156; CHECK: .LBB3_5:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000157; CHECK-NEXT: end_block{{$}}
Dan Gohmanb6fd39a2016-01-19 16:59:23 +0000158; CHECK: i32.const $push{{[0-9]+}}=, 0{{$}}
159; CHECK-NEXT: return $pop{{[0-9]+}}{{$}}
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000160; OPT-LABEL: doublediamond:
Dan Gohman442bfce2016-02-16 16:22:41 +0000161; OPT: block{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000162; OPT-NEXT: block{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +0000163; OPT-NEXT: block{{$}}
164; OPT: br_if 0, ${{[^,]+}}{{$}}
165; OPT: br_if 1, ${{[^,]+}}{{$}}
166; OPT: br 2{{$}}
167; OPT-NEXT: .LBB3_3:
168; OPT-NEXT: end_block
169; OPT: br 1{{$}}
170; OPT-NEXT: .LBB3_4:
171; OPT: .LBB3_5:
172; OPT-NEXT: end_block
173; OPT: return $pop{{[0-9]+}}{{$}}
Dan Gohman950a13c2015-09-16 16:51:30 +0000174define i32 @doublediamond(i32 %a, i32 %b, i32* %p) {
175entry:
176 %c = icmp eq i32 %a, 0
177 %d = icmp eq i32 %b, 0
178 store volatile i32 0, i32* %p
179 br i1 %c, label %true, label %false
180true:
181 store volatile i32 1, i32* %p
182 br label %exit
183false:
184 store volatile i32 2, i32* %p
185 br i1 %d, label %ft, label %ff
186ft:
187 store volatile i32 3, i32* %p
188 br label %exit
189ff:
190 store volatile i32 4, i32* %p
191 br label %exit
192exit:
193 store volatile i32 5, i32* %p
194 ret i32 0
195}
196
Dan Gohmane51c0582015-10-06 00:27:55 +0000197; CHECK-LABEL: triangle:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000198; CHECK: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000199; CHECK: br_if 0, $1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000200; CHECK: .LBB4_2:
Dan Gohman4ba48162015-11-18 16:12:01 +0000201; CHECK: return ${{[0-9]+}}{{$}}
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000202; OPT-LABEL: triangle:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000203; OPT: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000204; OPT: br_if 0, $1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000205; OPT: .LBB4_2:
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000206; OPT: return ${{[0-9]+}}{{$}}
Dan Gohman950a13c2015-09-16 16:51:30 +0000207define i32 @triangle(i32* %p, i32 %a) {
208entry:
209 %c = icmp eq i32 %a, 0
210 store volatile i32 0, i32* %p
211 br i1 %c, label %true, label %exit
212true:
213 store volatile i32 1, i32* %p
214 br label %exit
215exit:
216 store volatile i32 2, i32* %p
217 ret i32 0
218}
219
Dan Gohmane51c0582015-10-06 00:27:55 +0000220; CHECK-LABEL: diamond:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000221; CHECK: block{{$}}
222; CHECK: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000223; CHECK: br_if 0, $1{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000224; CHECK: br 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000225; CHECK: .LBB5_2:
226; CHECK: .LBB5_3:
Dan Gohmanb6fd39a2016-01-19 16:59:23 +0000227; CHECK: i32.const $push{{[0-9]+}}=, 0{{$}}
228; CHECK-NEXT: return $pop{{[0-9]+}}{{$}}
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000229; OPT-LABEL: diamond:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000230; OPT: block{{$}}
231; OPT: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000232; OPT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000233; OPT: br 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000234; OPT: .LBB5_2:
235; OPT: .LBB5_3:
Dan Gohmanb6fd39a2016-01-19 16:59:23 +0000236; OPT: i32.const $push{{[0-9]+}}=, 0{{$}}
237; OPT-NEXT: return $pop{{[0-9]+}}{{$}}
Dan Gohman950a13c2015-09-16 16:51:30 +0000238define i32 @diamond(i32* %p, i32 %a) {
239entry:
240 %c = icmp eq i32 %a, 0
241 store volatile i32 0, i32* %p
242 br i1 %c, label %true, label %false
243true:
244 store volatile i32 1, i32* %p
245 br label %exit
246false:
247 store volatile i32 2, i32* %p
248 br label %exit
249exit:
250 store volatile i32 3, i32* %p
251 ret i32 0
252}
253
Dan Gohmane51c0582015-10-06 00:27:55 +0000254; CHECK-LABEL: single_block:
Dan Gohman950a13c2015-09-16 16:51:30 +0000255; CHECK-NOT: br
Dan Gohman81719f82015-11-25 16:55:01 +0000256; CHECK: return $pop{{[0-9]+}}{{$}}
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000257; OPT-LABEL: single_block:
258; OPT-NOT: br
259; OPT: return $pop{{[0-9]+}}{{$}}
Dan Gohman950a13c2015-09-16 16:51:30 +0000260define i32 @single_block(i32* %p) {
261entry:
262 store volatile i32 0, i32* %p
263 ret i32 0
264}
265
Dan Gohmane51c0582015-10-06 00:27:55 +0000266; CHECK-LABEL: minimal_loop:
Dan Gohman950a13c2015-09-16 16:51:30 +0000267; CHECK-NOT: br
Dan Gohmana4730cf2016-01-07 18:49:53 +0000268; CHECK: .LBB7_1:
Derek Schuff9d779522015-12-05 00:26:39 +0000269; CHECK: i32.store $discard=, 0($0), $pop{{[0-9]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000270; CHECK: br 0{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000271; CHECK: .LBB7_2:
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000272; OPT-LABEL: minimal_loop:
273; OPT-NOT: br
Dan Gohmana4730cf2016-01-07 18:49:53 +0000274; OPT: .LBB7_1:
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000275; OPT: i32.store $discard=, 0($0), $pop{{[0-9]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000276; OPT: br 0{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000277; OPT: .LBB7_2:
Dan Gohman950a13c2015-09-16 16:51:30 +0000278define i32 @minimal_loop(i32* %p) {
279entry:
280 store volatile i32 0, i32* %p
281 br label %loop
282loop:
283 store volatile i32 1, i32* %p
284 br label %loop
285}
286
Dan Gohmane51c0582015-10-06 00:27:55 +0000287; CHECK-LABEL: simple_loop:
Dan Gohman950a13c2015-09-16 16:51:30 +0000288; CHECK-NOT: br
Dan Gohmana4730cf2016-01-07 18:49:53 +0000289; CHECK: .LBB8_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000290; CHECK: loop{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000291; CHECK: br_if 0, $pop{{[0-9]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000292; CHECK-NEXT: end_loop{{$}}
Dan Gohmanb6fd39a2016-01-19 16:59:23 +0000293; CHECK: i32.const $push{{[0-9]+}}=, 0{{$}}
294; CHECK-NEXT: return $pop{{[0-9]+}}{{$}}
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000295; OPT-LABEL: simple_loop:
296; OPT-NOT: br
Dan Gohmana4730cf2016-01-07 18:49:53 +0000297; OPT: .LBB8_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000298; OPT: loop{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000299; OPT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000300; OPT-NEXT: end_loop{{$}}
Dan Gohmanb6fd39a2016-01-19 16:59:23 +0000301; OPT: i32.const $push{{[0-9]+}}=, 0{{$}}
302; OPT-NEXT: return $pop{{[0-9]+}}{{$}}
Dan Gohman950a13c2015-09-16 16:51:30 +0000303define i32 @simple_loop(i32* %p, i32 %a) {
304entry:
305 %c = icmp eq i32 %a, 0
306 store volatile i32 0, i32* %p
307 br label %loop
308loop:
309 store volatile i32 1, i32* %p
310 br i1 %c, label %loop, label %exit
311exit:
312 store volatile i32 2, i32* %p
313 ret i32 0
314}
315
Dan Gohmane51c0582015-10-06 00:27:55 +0000316; CHECK-LABEL: doubletriangle:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000317; CHECK: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000318; CHECK: br_if 0, $0{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000319; CHECK: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000320; CHECK: br_if 0, $1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000321; CHECK: .LBB9_3:
322; CHECK: .LBB9_4:
Dan Gohman4ba48162015-11-18 16:12:01 +0000323; CHECK: return ${{[0-9]+}}{{$}}
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000324; OPT-LABEL: doubletriangle:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000325; OPT: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000326; OPT: br_if 0, $0{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000327; OPT: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000328; OPT: br_if 0, $1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000329; OPT: .LBB9_3:
330; OPT: .LBB9_4:
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000331; OPT: return ${{[0-9]+}}{{$}}
Dan Gohman950a13c2015-09-16 16:51:30 +0000332define i32 @doubletriangle(i32 %a, i32 %b, i32* %p) {
333entry:
334 %c = icmp eq i32 %a, 0
335 %d = icmp eq i32 %b, 0
336 store volatile i32 0, i32* %p
337 br i1 %c, label %true, label %exit
338true:
339 store volatile i32 2, i32* %p
340 br i1 %d, label %tt, label %tf
341tt:
342 store volatile i32 3, i32* %p
343 br label %tf
344tf:
345 store volatile i32 4, i32* %p
346 br label %exit
347exit:
348 store volatile i32 5, i32* %p
349 ret i32 0
350}
351
Dan Gohmane51c0582015-10-06 00:27:55 +0000352; CHECK-LABEL: ifelse_earlyexits:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000353; CHECK: block{{$}}
354; CHECK: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000355; CHECK: br_if 0, $0{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000356; CHECK: br 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000357; CHECK: .LBB10_2:
Dan Gohman06b49582016-02-08 21:50:13 +0000358; CHECK: br_if 0, $1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000359; CHECK: .LBB10_4:
Dan Gohmanb6fd39a2016-01-19 16:59:23 +0000360; CHECK: i32.const $push{{[0-9]+}}=, 0{{$}}
361; CHECK-NEXT: return $pop{{[0-9]+}}{{$}}
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000362; OPT-LABEL: ifelse_earlyexits:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000363; OPT: block{{$}}
364; OPT: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000365; OPT: br_if 0, {{[^,]+}}{{$}}
366; OPT: br_if 1, $1{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000367; OPT: br 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000368; OPT: .LBB10_3:
369; OPT: .LBB10_4:
Dan Gohmanb6fd39a2016-01-19 16:59:23 +0000370; OPT: i32.const $push{{[0-9]+}}=, 0{{$}}
371; OPT-NEXT: return $pop{{[0-9]+}}{{$}}
Dan Gohman950a13c2015-09-16 16:51:30 +0000372define i32 @ifelse_earlyexits(i32 %a, i32 %b, i32* %p) {
373entry:
374 %c = icmp eq i32 %a, 0
375 %d = icmp eq i32 %b, 0
376 store volatile i32 0, i32* %p
377 br i1 %c, label %true, label %false
378true:
379 store volatile i32 1, i32* %p
380 br label %exit
381false:
382 store volatile i32 2, i32* %p
383 br i1 %d, label %ft, label %exit
384ft:
385 store volatile i32 3, i32* %p
386 br label %exit
387exit:
388 store volatile i32 4, i32* %p
389 ret i32 0
390}
Dan Gohmane3e4a5f2015-10-02 21:11:36 +0000391
Dan Gohman32807932015-11-23 16:19:56 +0000392; CHECK-LABEL: doublediamond_in_a_loop:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000393; CHECK: .LBB11_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000394; CHECK: loop{{$}}
395; CHECK: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000396; CHECK: br_if 0, $0{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000397; CHECK: br 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000398; CHECK: .LBB11_3:
Dan Gohman0cfb5f82016-05-10 04:24:02 +0000399; CHECK: end_block{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000400; CHECK: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000401; CHECK: br_if 0, $1{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000402; CHECK: br 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000403; CHECK: .LBB11_5:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000404; CHECK: br 0{{$}}
Dan Gohman0cfb5f82016-05-10 04:24:02 +0000405; CHECK: .LBB11_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000406; CHECK-NEXT: end_loop{{$}}
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000407; OPT-LABEL: doublediamond_in_a_loop:
Dan Gohman442bfce2016-02-16 16:22:41 +0000408; OPT: .LBB11_1:
409; OPT: loop{{$}}
410; OPT: block{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +0000411; OPT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman0cfb5f82016-05-10 04:24:02 +0000412; OPT: block{{$}}
413; OPT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +0000414; OPT: br 2{{$}}
415; OPT-NEXT: .LBB11_4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000416; OPT-NEXT: end_block{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +0000417; OPT: br 1{{$}}
418; OPT: .LBB11_5:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000419; OPT-NEXT: end_block{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +0000420; OPT: br 0{{$}}
Dan Gohman0cfb5f82016-05-10 04:24:02 +0000421; OPT: .LBB11_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000422; OPT-NEXT: end_loop{{$}}
Dan Gohman32807932015-11-23 16:19:56 +0000423define i32 @doublediamond_in_a_loop(i32 %a, i32 %b, i32* %p) {
424entry:
425 br label %header
426header:
427 %c = icmp eq i32 %a, 0
428 %d = icmp eq i32 %b, 0
429 store volatile i32 0, i32* %p
430 br i1 %c, label %true, label %false
431true:
432 store volatile i32 1, i32* %p
433 br label %exit
434false:
435 store volatile i32 2, i32* %p
436 br i1 %d, label %ft, label %ff
437ft:
438 store volatile i32 3, i32* %p
439 br label %exit
440ff:
441 store volatile i32 4, i32* %p
442 br label %exit
443exit:
444 store volatile i32 5, i32* %p
445 br label %header
446}
447
Dan Gohmane3e4a5f2015-10-02 21:11:36 +0000448; Test that nested loops are handled.
449
Dan Gohman8fe7e862015-12-14 22:51:54 +0000450; CHECK-LABEL: test3:
451; CHECK: loop
452; CHECK-NEXT: br_if
Dan Gohmana4730cf2016-01-07 18:49:53 +0000453; CHECK-NEXT: .LBB{{[0-9]+}}_{{[0-9]+}}:
Dan Gohman8fe7e862015-12-14 22:51:54 +0000454; CHECK-NEXT: loop
455; OPT-LABEL: test3:
Dan Gohman442bfce2016-02-16 16:22:41 +0000456; OPT: block
457; OPT: br_if
Dan Gohmand85ab7f2016-02-18 06:32:53 +0000458; OPT: .LBB{{[0-9]+}}_{{[0-9]+}}:
Dan Gohman442bfce2016-02-16 16:22:41 +0000459; OPT-NEXT: loop
460; OPT-NEXT: block
461; OPT-NEXT: block
Dan Gohman8fe7e862015-12-14 22:51:54 +0000462; OPT-NEXT: br_if
Dan Gohmana4730cf2016-01-07 18:49:53 +0000463; OPT-NEXT: .LBB{{[0-9]+}}_{{[0-9]+}}:
Dan Gohman8fe7e862015-12-14 22:51:54 +0000464; OPT-NEXT: loop
Dan Gohman442bfce2016-02-16 16:22:41 +0000465; OPT: br_if
466; OPT-NEXT: br
467; OPT-NEXT: .LBB{{[0-9]+}}_{{[0-9]+}}:
468; OPT-NEXT: end_loop
469; OPT-NEXT: end_block
470; OPT-NEXT: unreachable
471; OPT-NEXT: .LBB{{[0-9]+}}_{{[0-9]+}}:
472; OPT-NEXT: end_block
473; OPT: br
474; OPT-NEXT: .LBB{{[0-9]+}}_{{[0-9]+}}:
475; OPT-NEXT: end_loop
Dan Gohmane3e4a5f2015-10-02 21:11:36 +0000476declare void @bar()
Dan Gohmane3e4a5f2015-10-02 21:11:36 +0000477define void @test3(i32 %w) {
478entry:
479 br i1 undef, label %outer.ph, label %exit
480
481outer.ph:
482 br label %outer
483
484outer:
485 %tobool = icmp eq i32 undef, 0
486 br i1 %tobool, label %inner, label %unreachable
487
488unreachable:
489 unreachable
490
491inner:
492 %c = icmp eq i32 undef, %w
493 br i1 %c, label %if.end, label %inner
494
495exit:
496 ret void
497
498if.end:
499 call void @bar()
500 br label %outer
501}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000502
503; Test switch lowering and block placement.
504
505; CHECK-LABEL: test4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000506; CHECK-NEXT: .param i32{{$}}
507; CHECK: block{{$}}
508; CHECK-NEXT: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000509; CHECK: br_if 0, $pop{{[0-9]+}}{{$}}
Dan Gohmand85ab7f2016-02-18 06:32:53 +0000510; CHECK: br_if 1, $pop{{[0-9]+}}{{$}}
511; CHECK: br 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000512; CHECK-NEXT: .LBB13_3:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000513; CHECK-NEXT: end_block{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +0000514; CHECK-NEXT: block{{$}}
Dan Gohmand85ab7f2016-02-18 06:32:53 +0000515; CHECK: br_if 0, $pop{{[0-9]+}}{{$}}
516; CHECK: br_if 1, $pop{{[0-9]+}}{{$}}
517; CHECK-NEXT: .LBB13_5:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000518; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000519; CHECK-NEXT: return{{$}}
Dan Gohmand85ab7f2016-02-18 06:32:53 +0000520; CHECK-NEXT: .LBB13_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000521; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000522; CHECK-NEXT: return{{$}}
523; OPT-LABEL: test4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000524; OPT-NEXT: .param i32{{$}}
525; OPT: block{{$}}
526; OPT-NEXT: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000527; OPT: br_if 0, $pop{{[0-9]+}}{{$}}
Dan Gohmand85ab7f2016-02-18 06:32:53 +0000528; OPT: br_if 1, $pop{{[0-9]+}}{{$}}
529; OPT: br 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000530; OPT-NEXT: .LBB13_3:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000531; OPT-NEXT: end_block{{$}}
Dan Gohmand85ab7f2016-02-18 06:32:53 +0000532; OPT-NEXT: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000533; OPT: br_if 0, $pop{{[0-9]+}}{{$}}
Dan Gohmand85ab7f2016-02-18 06:32:53 +0000534; OPT: br_if 1, $pop{{[0-9]+}}{{$}}
535; OPT-NEXT: .LBB13_5:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000536; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000537; OPT-NEXT: return{{$}}
Dan Gohmand85ab7f2016-02-18 06:32:53 +0000538; OPT-NEXT: .LBB13_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000539; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000540; OPT-NEXT: return{{$}}
541define void @test4(i32 %t) {
542entry:
543 switch i32 %t, label %default [
544 i32 0, label %bb2
545 i32 2, label %bb2
546 i32 4, label %bb1
547 i32 622, label %bb0
548 ]
549
550bb0:
551 ret void
552
553bb1:
554 ret void
555
556bb2:
557 ret void
558
559default:
560 ret void
561}
562
563; Test a case where the BLOCK needs to be placed before the LOOP in the
564; same basic block.
565
566; CHECK-LABEL: test5:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000567; CHECK: .LBB14_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000568; CHECK-NEXT: block{{$}}
569; CHECK-NEXT: loop{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000570; CHECK: br_if 2, {{[^,]+}}{{$}}
571; CHECK: br_if 0, {{[^,]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000572; CHECK-NEXT: end_loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000573; CHECK: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000574; CHECK-NEXT: .LBB14_4:
Dan Gohman8fe7e862015-12-14 22:51:54 +0000575; CHECK: return{{$}}
576; OPT-LABEL: test5:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000577; OPT: .LBB14_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000578; OPT-NEXT: block{{$}}
579; OPT-NEXT: loop{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000580; OPT: br_if 2, {{[^,]+}}{{$}}
581; OPT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000582; OPT-NEXT: end_loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000583; OPT: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000584; OPT-NEXT: .LBB14_4:
Dan Gohman8fe7e862015-12-14 22:51:54 +0000585; OPT: return{{$}}
586define void @test5(i1 %p, i1 %q) {
587entry:
588 br label %header
589
590header:
591 store volatile i32 0, i32* null
592 br i1 %p, label %more, label %alt
593
594more:
595 store volatile i32 1, i32* null
596 br i1 %q, label %header, label %return
597
598alt:
599 store volatile i32 2, i32* null
600 ret void
601
602return:
603 store volatile i32 3, i32* null
604 ret void
605}
606
607; Test an interesting case of a loop with multiple exits, which
608; aren't to layout successors of the loop, and one of which is to a successors
609; which has another predecessor.
610
611; CHECK-LABEL: test6:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000612; CHECK: .LBB15_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000613; CHECK-NEXT: block{{$}}
614; CHECK-NEXT: block{{$}}
615; CHECK-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000616; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000617; CHECK: br_if 3, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000618; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000619; CHECK: br_if 2, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000620; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000621; CHECK: br_if 0, {{[^,]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000622; CHECK-NEXT: end_loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000623; CHECK-NOT: block
624; CHECK: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000625; CHECK-NEXT: .LBB15_5:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000626; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000627; CHECK-NOT: block
Dan Gohmana4730cf2016-01-07 18:49:53 +0000628; CHECK: .LBB15_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000629; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000630; CHECK-NOT: block
631; CHECK: return{{$}}
632; OPT-LABEL: test6:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000633; OPT: .LBB15_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000634; OPT-NEXT: block{{$}}
635; OPT-NEXT: block{{$}}
636; OPT-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000637; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000638; OPT: br_if 3, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000639; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000640; OPT: br_if 2, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000641; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000642; OPT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000643; OPT-NEXT: end_loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000644; OPT-NOT: block
645; OPT: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000646; OPT-NEXT: .LBB15_5:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000647; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000648; OPT-NOT: block
Dan Gohmana4730cf2016-01-07 18:49:53 +0000649; OPT: .LBB15_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000650; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000651; OPT-NOT: block
652; OPT: return{{$}}
653define void @test6(i1 %p, i1 %q) {
654entry:
655 br label %header
656
657header:
658 store volatile i32 0, i32* null
659 br i1 %p, label %more, label %second
660
661more:
662 store volatile i32 1, i32* null
663 br i1 %q, label %evenmore, label %first
664
665evenmore:
666 store volatile i32 1, i32* null
667 br i1 %q, label %header, label %return
668
669return:
670 store volatile i32 2, i32* null
671 ret void
672
673first:
674 store volatile i32 3, i32* null
675 br label %second
676
677second:
678 store volatile i32 4, i32* null
679 ret void
680}
681
682; Test a case where there are multiple backedges and multiple loop exits
683; that end in unreachable.
684
685; CHECK-LABEL: test7:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000686; CHECK: .LBB16_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000687; CHECK-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000688; CHECK-NOT: block
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000689; CHECK: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000690; CHECK: br_if 0, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000691; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000692; CHECK: br_if 1, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000693; CHECK-NOT: block
694; CHECK: unreachable
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000695; CHECK-NEXT: .LBB16_4:
696; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000697; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000698; CHECK: br_if 0, {{[^,]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000699; CHECK-NEXT: end_loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000700; CHECK-NOT: block
701; CHECK: unreachable
702; OPT-LABEL: test7:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000703; OPT: .LBB16_1:
Dan Gohman442bfce2016-02-16 16:22:41 +0000704; OPT-NEXT: block
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000705; OPT-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000706; OPT-NOT: block
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000707; OPT: block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000708; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000709; OPT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000710; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000711; OPT: br_if 1, {{[^,]+}}{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +0000712; OPT: br 3{{$}}
713; OPT-NEXT: .LBB16_3:
714; OPT-NEXT: end_block
Dan Gohman8fe7e862015-12-14 22:51:54 +0000715; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000716; OPT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +0000717; OPT-NEXT: end_loop
718; OPT-NOT: block
719; OPT: unreachable
720; OPT-NEXT: .LBB16_5:
721; OPT-NEXT: end_block
Dan Gohman8fe7e862015-12-14 22:51:54 +0000722; OPT-NOT: block
723; OPT: unreachable
724define void @test7(i1 %tobool2, i1 %tobool9) {
725entry:
726 store volatile i32 0, i32* null
727 br label %loop
728
729loop:
730 store volatile i32 1, i32* null
731 br i1 %tobool2, label %l1, label %l0
732
733l0:
734 store volatile i32 2, i32* null
735 br i1 %tobool9, label %loop, label %u0
736
737l1:
738 store volatile i32 3, i32* null
739 br i1 %tobool9, label %loop, label %u1
740
741u0:
742 store volatile i32 4, i32* null
743 unreachable
744
745u1:
746 store volatile i32 5, i32* null
747 unreachable
748}
749
750; Test an interesting case using nested loops and switches.
751
752; CHECK-LABEL: test8:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000753; CHECK: .LBB17_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000754; CHECK-NEXT: loop{{$}}
Dan Gohmane5d3c152016-01-20 05:55:09 +0000755; CHECK-NEXT: i32.const $push{{[^,]+}}, 0{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000756; CHECK-NEXT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman0cfb5f82016-05-10 04:24:02 +0000757; CHECK-NEXT: br 0{{$}}
758; CHECK-NEXT: .LBB17_2:
759; CHECK-NEXT: end_loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000760; OPT-LABEL: test8:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000761; OPT: .LBB17_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000762; OPT-NEXT: loop{{$}}
Dan Gohmane5d3c152016-01-20 05:55:09 +0000763; OPT-NEXT: i32.const $push{{[^,]+}}, 0{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000764; OPT-NEXT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman0cfb5f82016-05-10 04:24:02 +0000765; OPT-NEXT: br 0{{$}}
766; OPT-NEXT: .LBB17_2:
767; OPT-NEXT: end_loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000768define i32 @test8() {
769bb:
770 br label %bb1
771
772bb1:
773 br i1 undef, label %bb2, label %bb3
774
775bb2:
776 switch i8 undef, label %bb1 [
777 i8 44, label %bb2
778 ]
779
780bb3:
781 switch i8 undef, label %bb1 [
782 i8 44, label %bb2
783 ]
784}
785
786; Test an interesting case using nested loops that share a bottom block.
787
788; CHECK-LABEL: test9:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000789; CHECK: .LBB18_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000790; CHECK-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000791; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000792; CHECK: br_if 1, {{[^,]+}}{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000793; CHECK-NEXT: .LBB18_2:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000794; CHECK-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000795; CHECK-NOT: block
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000796; CHECK: block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000797; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000798; CHECK: br_if 0, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000799; CHECK-NOT: block
Dan Gohmand85ab7f2016-02-18 06:32:53 +0000800; CHECK: br_if 3, {{[^,]+}}{{$}}
801; CHECK-NEXT: br 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000802; CHECK-NEXT: .LBB18_4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000803; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000804; CHECK-NOT: block
Dan Gohmand85ab7f2016-02-18 06:32:53 +0000805; CHECK: br_if 2, {{[^,]+}}{{$}}
806; CHECK-NEXT: br 0{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000807; CHECK-NEXT: .LBB18_5:
Dan Gohman8fe7e862015-12-14 22:51:54 +0000808; CHECK-NOT: block
809; CHECK: return{{$}}
810; OPT-LABEL: test9:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000811; OPT: .LBB18_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000812; OPT-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000813; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000814; OPT: br_if 1, {{[^,]+}}{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000815; OPT-NEXT: .LBB18_2:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000816; OPT-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000817; OPT-NOT: block
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000818; OPT: block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000819; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000820; OPT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000821; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000822; OPT: br_if 1, {{[^,]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000823; OPT-NEXT: br 3{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000824; OPT-NEXT: .LBB18_4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000825; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000826; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000827; OPT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000828; OPT-NEXT: br 2{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000829; OPT-NEXT: .LBB18_5:
Dan Gohman8fe7e862015-12-14 22:51:54 +0000830; OPT-NOT: block
831; OPT: return{{$}}
832declare i1 @a()
833define void @test9() {
834entry:
835 store volatile i32 0, i32* null
836 br label %header
837
838header:
839 store volatile i32 1, i32* null
840 %call4 = call i1 @a()
841 br i1 %call4, label %header2, label %end
842
843header2:
844 store volatile i32 2, i32* null
845 %call = call i1 @a()
846 br i1 %call, label %if.then, label %if.else
847
848if.then:
849 store volatile i32 3, i32* null
850 %call3 = call i1 @a()
851 br i1 %call3, label %header2, label %header
852
853if.else:
854 store volatile i32 4, i32* null
855 %call2 = call i1 @a()
856 br i1 %call2, label %header2, label %header
857
858end:
859 store volatile i32 5, i32* null
860 ret void
861}
862
863; Test an interesting case involving nested loops sharing a loop bottom,
864; and loop exits to a block with unreachable.
865
866; CHECK-LABEL: test10:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000867; CHECK: .LBB19_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000868; CHECK-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000869; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000870; CHECK: br_if 0, {{[^,]+}}{{$}}
JF Bastienc6ba5ea2016-04-05 17:01:52 +0000871; CHECK: .LBB19_3:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000872; CHECK-NEXT: block{{$}}
873; CHECK-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000874; CHECK-NOT: block
JF Bastienc6ba5ea2016-04-05 17:01:52 +0000875; CHECK: .LBB19_4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000876; CHECK-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000877; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000878; CHECK: br_if 5, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000879; CHECK-NOT: block
Dan Gohman14026062016-03-08 03:18:12 +0000880; CHECK: br_table {{[^,]+}}, 0, 1, 5, 2, 4, 0{{$}}
JF Bastienc6ba5ea2016-04-05 17:01:52 +0000881; CHECK-NEXT: .LBB19_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000882; CHECK-NEXT: end_loop{{$}}
883; CHECK-NEXT: end_loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000884; CHECK-NEXT: return{{$}}
JF Bastienc6ba5ea2016-04-05 17:01:52 +0000885; CHECK-NEXT: .LBB19_7:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000886; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000887; CHECK-NOT: block
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000888; CHECK: br 0{{$}}
JF Bastienc6ba5ea2016-04-05 17:01:52 +0000889; CHECK-NEXT: .LBB19_8:
Dan Gohman8fe7e862015-12-14 22:51:54 +0000890; OPT-LABEL: test10:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000891; OPT: .LBB19_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000892; OPT-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000893; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000894; OPT: br_if 0, {{[^,]+}}{{$}}
JF Bastienc6ba5ea2016-04-05 17:01:52 +0000895; OPT: .LBB19_3:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000896; OPT-NEXT: block{{$}}
897; OPT-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000898; OPT-NOT: block
JF Bastienc6ba5ea2016-04-05 17:01:52 +0000899; OPT: .LBB19_4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000900; OPT-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000901; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000902; OPT: br_if 5, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000903; OPT-NOT: block
Dan Gohman14026062016-03-08 03:18:12 +0000904; OPT: br_table {{[^,]+}}, 0, 1, 5, 2, 4, 0{{$}}
JF Bastienc6ba5ea2016-04-05 17:01:52 +0000905; OPT-NEXT: .LBB19_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000906; OPT-NEXT: end_loop{{$}}
907; OPT-NEXT: end_loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000908; OPT-NEXT: return{{$}}
JF Bastienc6ba5ea2016-04-05 17:01:52 +0000909; OPT-NEXT: .LBB19_7:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000910; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000911; OPT-NOT: block
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000912; OPT: br 0{{$}}
JF Bastienc6ba5ea2016-04-05 17:01:52 +0000913; OPT-NEXT: .LBB19_8:
Dan Gohman8fe7e862015-12-14 22:51:54 +0000914define void @test10() {
915bb0:
916 br label %bb1
917
918bb1:
919 %tmp = phi i32 [ 2, %bb0 ], [ 3, %bb3 ]
920 %tmp3 = phi i32 [ undef, %bb0 ], [ %tmp11, %bb3 ]
921 %tmp4 = icmp eq i32 %tmp3, 0
922 br i1 %tmp4, label %bb4, label %bb2
923
924bb2:
925 br label %bb3
926
927bb3:
928 %tmp11 = phi i32 [ 1, %bb5 ], [ 0, %bb2 ]
929 br label %bb1
930
931bb4:
932 %tmp6 = phi i32 [ %tmp9, %bb5 ], [ 4, %bb1 ]
933 %tmp7 = phi i32 [ %tmp6, %bb5 ], [ %tmp, %bb1 ]
934 br label %bb5
935
936bb5:
937 %tmp9 = phi i32 [ %tmp6, %bb5 ], [ %tmp7, %bb4 ]
938 switch i32 %tmp9, label %bb2 [
939 i32 0, label %bb5
940 i32 1, label %bb6
941 i32 3, label %bb4
942 i32 4, label %bb3
943 ]
944
945bb6:
946 ret void
947}
948
949; Test a CFG DAG with interesting merging.
950
951; CHECK-LABEL: test11:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000952; CHECK: block{{$}}
953; CHECK-NEXT: block{{$}}
954; CHECK-NEXT: block{{$}}
955; CHECK-NEXT: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000956; CHECK: br_if 0, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000957; CHECK-NOT: block
Dan Gohmaned0f1132016-01-30 05:01:06 +0000958; CHECK: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000959; CHECK-NEXT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000960; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000961; CHECK: br_if 2, {{[^,]+}}{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000962; CHECK-NEXT: .LBB20_3:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000963; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000964; CHECK-NOT: block
965; CHECK: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000966; CHECK-NEXT: .LBB20_4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000967; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000968; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000969; CHECK: br_if 1, {{[^,]+}}{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +0000970; CHECK-NOT: block
971; CHECK: br_if 2, {{[^,]+}}{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000972; CHECK-NEXT: .LBB20_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000973; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000974; CHECK-NOT: block
975; CHECK: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000976; CHECK-NEXT: .LBB20_7:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000977; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000978; CHECK-NOT: block
979; CHECK: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000980; CHECK-NEXT: .LBB20_8:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000981; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000982; CHECK-NOT: block
983; CHECK: return{{$}}
984; OPT-LABEL: test11:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000985; OPT: block{{$}}
986; OPT-NEXT: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000987; OPT: br_if 0, $pop{{[0-9]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000988; OPT-NOT: block
Dan Gohmaned0f1132016-01-30 05:01:06 +0000989; OPT: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000990; OPT-NEXT: br_if 0, $0{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000991; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000992; OPT: br_if 2, {{[^,]+}}{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000993; OPT-NEXT: .LBB20_3:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000994; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000995; OPT-NOT: block
996; OPT: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000997; OPT-NEXT: .LBB20_4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000998; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000999; OPT-NOT: block
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001000; OPT: block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001001; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +00001002; OPT: br_if 0, $pop{{[0-9]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001003; OPT-NOT: block
1004; OPT: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +00001005; OPT-NEXT: .LBB20_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001006; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001007; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +00001008; OPT: br_if 0, $pop{{[0-9]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001009; OPT-NOT: block
1010; OPT: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +00001011; OPT-NEXT: .LBB20_8:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001012; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001013; OPT-NOT: block
1014; OPT: return{{$}}
1015define void @test11() {
1016bb0:
1017 store volatile i32 0, i32* null
1018 br i1 undef, label %bb1, label %bb4
1019bb1:
1020 store volatile i32 1, i32* null
1021 br i1 undef, label %bb3, label %bb2
1022bb2:
1023 store volatile i32 2, i32* null
1024 br i1 undef, label %bb3, label %bb7
1025bb3:
1026 store volatile i32 3, i32* null
1027 ret void
1028bb4:
1029 store volatile i32 4, i32* null
1030 br i1 undef, label %bb8, label %bb5
1031bb5:
1032 store volatile i32 5, i32* null
1033 br i1 undef, label %bb6, label %bb7
1034bb6:
1035 store volatile i32 6, i32* null
1036 ret void
1037bb7:
1038 store volatile i32 7, i32* null
1039 ret void
1040bb8:
1041 store volatile i32 8, i32* null
1042 ret void
1043}
1044
1045; CHECK-LABEL: test12:
Dan Gohmana4730cf2016-01-07 18:49:53 +00001046; CHECK: .LBB21_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001047; CHECK-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001048; CHECK-NOT: block
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001049; CHECK: block{{$}}
1050; CHECK-NEXT: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +00001051; CHECK: br_if 0, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001052; CHECK-NOT: block
Dan Gohman442bfce2016-02-16 16:22:41 +00001053; CHECK: br_if 1, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001054; CHECK-NOT: block
Dan Gohman442bfce2016-02-16 16:22:41 +00001055; CHECK: br_if 1, {{[^,]+}}{{$}}
1056; CHECK-NEXT: br 3{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +00001057; CHECK-NEXT: .LBB21_4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001058; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001059; CHECK-NOT: block
Dan Gohman442bfce2016-02-16 16:22:41 +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 2, {{[^,]+}}{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +00001063; CHECK-NEXT: .LBB21_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001064; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001065; CHECK-NOT: block
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001066; CHECK: br 0{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +00001067; CHECK-NEXT: .LBB21_7:
1068; CHECK-NEXT: end_loop{{$}}
1069; CHECK-NEXT: return{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001070; OPT-LABEL: test12:
Dan Gohmana4730cf2016-01-07 18:49:53 +00001071; OPT: .LBB21_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001072; OPT-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001073; OPT-NOT: block
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001074; OPT: block{{$}}
1075; OPT-NEXT: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +00001076; OPT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001077; OPT-NOT: block
Dan Gohman442bfce2016-02-16 16:22:41 +00001078; OPT: br_if 1, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001079; OPT-NOT: block
Dan Gohman442bfce2016-02-16 16:22:41 +00001080; OPT: br_if 1, {{[^,]+}}{{$}}
1081; OPT-NEXT: br 3{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +00001082; OPT-NEXT: .LBB21_4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001083; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001084; OPT-NOT: block
Dan Gohman442bfce2016-02-16 16:22:41 +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 2, {{[^,]+}}{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +00001088; OPT-NEXT: .LBB21_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001089; OPT-NEXT: end_block{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001090; OPT: br 0{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +00001091; OPT-NEXT: .LBB21_7:
1092; OPT-NEXT: end_loop{{$}}
1093; OPT-NEXT: return{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001094define void @test12(i8* %arg) {
1095bb:
1096 br label %bb1
1097
1098bb1:
1099 %tmp = phi i32 [ 0, %bb ], [ %tmp5, %bb4 ]
1100 %tmp2 = getelementptr i8, i8* %arg, i32 %tmp
1101 %tmp3 = load i8, i8* %tmp2
1102 switch i8 %tmp3, label %bb7 [
1103 i8 42, label %bb4
1104 i8 76, label %bb4
1105 i8 108, label %bb4
1106 i8 104, label %bb4
1107 ]
1108
1109bb4:
1110 %tmp5 = add i32 %tmp, 1
1111 br label %bb1
1112
1113bb7:
1114 ret void
1115}
Dan Gohmanb3aa1ec2015-12-16 19:06:41 +00001116
1117; A block can be "branched to" from another even if it is also reachable via
1118; fallthrough from the other. This would normally be optimized away, so use
1119; optnone to disable optimizations to test this case.
1120
1121; CHECK-LABEL: test13:
Dan Gohmanb6fd39a2016-01-19 16:59:23 +00001122; CHECK-NEXT: .local i32{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +00001123; CHECK-NEXT: block{{$}}
1124; CHECK-NEXT: block{{$}}
1125; CHECK: br_if 0, $pop0{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001126; CHECK: block{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +00001127; CHECK: br_if 0, $pop3{{$}}
1128; CHECK: .LBB22_3:
1129; CHECK-NEXT: end_block{{$}}
1130; CHECK: br_if 1, $pop{{[0-9]+}}{{$}}
1131; CHECK-NEXT: br 1{{$}}
1132; CHECK-NEXT: .LBB22_4:
1133; CHECK-NEXT: end_block{{$}}
Dan Gohmanb3aa1ec2015-12-16 19:06:41 +00001134; CHECK-NEXT: return{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +00001135; CHECK-NEXT: .LBB22_5:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001136; CHECK-NEXT: end_block{{$}}
Dan Gohmanb3aa1ec2015-12-16 19:06:41 +00001137; CHECK-NEXT: unreachable{{$}}
1138; OPT-LABEL: test13:
Dan Gohmanb6fd39a2016-01-19 16:59:23 +00001139; OPT-NEXT: .local i32{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +00001140; OPT-NEXT: block{{$}}
1141; OPT-NEXT: block{{$}}
1142; OPT: br_if 0, $pop0{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001143; OPT: block{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +00001144; OPT: br_if 0, $pop3{{$}}
1145; OPT: .LBB22_3:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001146; OPT-NEXT: end_block{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +00001147; OPT: br_if 1, $pop{{[0-9]+}}{{$}}
1148; OPT-NEXT: br 1{{$}}
1149; OPT-NEXT: .LBB22_4:
1150; OPT-NEXT: end_block
1151; OPT-NEXT: return
1152; OPT-NEXT: .LBB22_5:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001153; OPT-NEXT: end_block{{$}}
Dan Gohmanb3aa1ec2015-12-16 19:06:41 +00001154; OPT-NEXT: unreachable{{$}}
1155define void @test13() noinline optnone {
1156bb:
1157 br i1 undef, label %bb5, label %bb2
1158bb1:
1159 unreachable
1160bb2:
1161 br i1 undef, label %bb3, label %bb4
1162bb3:
1163 br label %bb4
1164bb4:
1165 %tmp = phi i1 [ false, %bb2 ], [ false, %bb3 ]
1166 br i1 %tmp, label %bb1, label %bb1
1167bb5:
1168 ret void
1169}
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001170
1171; Test a case with a single-block loop that has another loop
1172; as a successor. The end_loop for the first loop should go
1173; before the loop for the second.
1174
1175; CHECK-LABEL: test14:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001176; CHECK-NEXT: .LBB23_1:{{$}}
1177; CHECK-NEXT: loop{{$}}
Dan Gohmanb6fd39a2016-01-19 16:59:23 +00001178; CHECK-NEXT: i32.const $push0=, 0{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +00001179; CHECK-NEXT: br_if 0, $pop0{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001180; CHECK-NEXT: end_loop{{$}}
Dan Gohman0cfb5f82016-05-10 04:24:02 +00001181; CHECK-NEXT: .LBB23_3:{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001182; CHECK-NEXT: loop{{$}}
Dan Gohmanb6fd39a2016-01-19 16:59:23 +00001183; CHECK-NEXT: i32.const $push1=, 0{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +00001184; CHECK-NEXT: br_if 0, $pop1{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001185; CHECK-NEXT: end_loop{{$}}
1186; CHECK-NEXT: return{{$}}
1187define void @test14() {
1188bb:
1189 br label %bb1
1190
1191bb1:
1192 %tmp = bitcast i1 undef to i1
1193 br i1 %tmp, label %bb3, label %bb1
1194
1195bb3:
1196 br label %bb4
1197
1198bb4:
1199 br i1 undef, label %bb7, label %bb48
1200
1201bb7:
1202 br i1 undef, label %bb12, label %bb12
1203
1204bb12:
1205 br i1 undef, label %bb17, label %bb17
1206
1207bb17:
1208 br i1 undef, label %bb22, label %bb22
1209
1210bb22:
1211 br i1 undef, label %bb27, label %bb27
1212
1213bb27:
1214 br i1 undef, label %bb30, label %bb30
1215
1216bb30:
1217 br i1 undef, label %bb35, label %bb35
1218
1219bb35:
1220 br i1 undef, label %bb38, label %bb38
1221
1222bb38:
1223 br i1 undef, label %bb48, label %bb48
1224
1225bb48:
1226 %tmp49 = bitcast i1 undef to i1
1227 br i1 %tmp49, label %bb3, label %bb50
1228
1229bb50:
1230 ret void
1231}
Dan Gohmana187ab22016-02-12 21:19:25 +00001232
1233; Test that a block boundary which ends one block, begins another block, and
1234; also begins a loop, has the markers placed in the correct order.
1235
1236; CHECK-LABEL: test15:
1237; CHECK: block
Dan Gohmana187ab22016-02-12 21:19:25 +00001238; CHECK-NEXT: block
Dan Gohman442bfce2016-02-16 16:22:41 +00001239; CHECK: br_if 0, $pop{{.*}}{{$}}
Dan Gohmand85ab7f2016-02-18 06:32:53 +00001240; CHECK: .LBB24_2:
Dan Gohman442bfce2016-02-16 16:22:41 +00001241; CHECK-NEXT: block{{$}}
1242; CHECK-NEXT: loop{{$}}
1243; CHECK: br_if 1, $pop{{.*}}{{$}}
Dan Gohmand85ab7f2016-02-18 06:32:53 +00001244; CHECK: br_if 0, ${{.*}}{{$}}
1245; CHECK-NEXT: br 2{{$}}
1246; CHECK-NEXT: .LBB24_4:
Dan Gohman442bfce2016-02-16 16:22:41 +00001247; CHECK-NEXT: end_loop{{$}}
Dan Gohmand85ab7f2016-02-18 06:32:53 +00001248; CHECK: .LBB24_5:
Dan Gohman442bfce2016-02-16 16:22:41 +00001249; CHECK-NEXT: end_block{{$}}
1250; CHECK: br_if 1, $pop{{.*}}{{$}}
1251; CHECK: return{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +00001252; CHECK: .LBB24_7:
1253; CHECK-NEXT: end_block{{$}}
Dan Gohmand85ab7f2016-02-18 06:32:53 +00001254; CHECK: .LBB24_8:
1255; CHECK-NEXT: end_block{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +00001256; CHECK-NEXT: return{{$}}
Dan Gohmana187ab22016-02-12 21:19:25 +00001257; OPT-LABEL: test15:
1258; OPT: block
Dan Gohmand85ab7f2016-02-18 06:32:53 +00001259; OPT: block
Dan Gohmana187ab22016-02-12 21:19:25 +00001260; OPT-NEXT: i32.const $push
1261; OPT-NEXT: i32.const $push
1262; OPT-NEXT: i32.eq $push{{.*}}=, $pop{{.*}}, $pop{{.*}}{{$}}
1263; OPT-NEXT: br_if 0, $pop{{.*}}{{$}}
1264; OPT-NEXT: call test15_callee1@FUNCTION{{$}}
Dan Gohmand85ab7f2016-02-18 06:32:53 +00001265; OPT-NEXT: br 1{{$}}
Dan Gohmana187ab22016-02-12 21:19:25 +00001266; OPT-NEXT: .LBB24_2:
1267; OPT-NEXT: end_block
Dan Gohmand85ab7f2016-02-18 06:32:53 +00001268; OPT-NEXT: i32.const
1269; OPT-NEXT: .LBB24_3:
Dan Gohmana187ab22016-02-12 21:19:25 +00001270; OPT-NEXT: block
1271; OPT-NEXT: loop
1272%0 = type { i8, i32 }
1273declare void @test15_callee0()
1274declare void @test15_callee1()
1275define void @test15() {
1276bb:
1277 %tmp1 = icmp eq i8 1, 0
1278 br i1 %tmp1, label %bb2, label %bb14
1279
1280bb2:
1281 %tmp3 = phi %0** [ %tmp6, %bb5 ], [ null, %bb ]
1282 %tmp4 = icmp eq i32 0, 11
1283 br i1 %tmp4, label %bb5, label %bb8
1284
1285bb5:
1286 %tmp = bitcast i8* null to %0**
1287 %tmp6 = getelementptr %0*, %0** %tmp3, i32 1
1288 %tmp7 = icmp eq %0** %tmp6, null
1289 br i1 %tmp7, label %bb10, label %bb2
1290
1291bb8:
1292 %tmp9 = icmp eq %0** null, undef
1293 br label %bb10
1294
1295bb10:
1296 %tmp11 = phi %0** [ null, %bb8 ], [ %tmp, %bb5 ]
1297 %tmp12 = icmp eq %0** null, %tmp11
1298 br i1 %tmp12, label %bb15, label %bb13
1299
1300bb13:
1301 call void @test15_callee0()
1302 ret void
1303
1304bb14:
1305 call void @test15_callee1()
1306 ret void
1307
1308bb15:
1309 ret void
1310}