blob: 58d099414adcc61800cd8c95f8df71eade61c58d [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 Gohmana4730cf2016-01-07 18:49:53 +0000107; CHECK: .LBB2_1:
Dan Gohman06b49582016-02-08 21:50:13 +0000108; CHECK: br_if 0, ${{[0-9]+}}{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000109; CHECK: .LBB2_2:
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 Gohmana4730cf2016-01-07 18:49:53 +0000115; OPT: .LBB2_1:
Dan Gohman06b49582016-02-08 21:50:13 +0000116; OPT: br_if 0, ${{[0-9]+}}{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000117; OPT: .LBB2_2:
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{{$}}
396; CHECK: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000397; CHECK: br_if 0, $0{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000398; CHECK: br 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000399; CHECK: .LBB11_3:
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:
404; CHECK: .LBB11_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000405; CHECK: br 0{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000406; CHECK: .LBB11_7:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000407; CHECK-NEXT: end_loop{{$}}
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000408; OPT-LABEL: doublediamond_in_a_loop:
Dan Gohman442bfce2016-02-16 16:22:41 +0000409; OPT: .LBB11_1:
410; OPT: loop{{$}}
411; OPT: block{{$}}
412; OPT-NEXT: block{{$}}
413; OPT-NEXT: block{{$}}
414; OPT: br_if 0, {{[^,]+}}{{$}}
415; OPT: br_if 1, {{[^,]+}}{{$}}
416; OPT: br 2{{$}}
417; OPT-NEXT: .LBB11_4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000418; OPT-NEXT: end_block{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +0000419; OPT: br 1{{$}}
420; OPT: .LBB11_5:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000421; OPT-NEXT: end_block{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +0000422; OPT: .LBB11_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000423; OPT-NEXT: end_block{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +0000424; OPT: br 0{{$}}
425; OPT: .LBB11_7:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000426; OPT-NEXT: end_loop{{$}}
Dan Gohman32807932015-11-23 16:19:56 +0000427define i32 @doublediamond_in_a_loop(i32 %a, i32 %b, i32* %p) {
428entry:
429 br label %header
430header:
431 %c = icmp eq i32 %a, 0
432 %d = icmp eq i32 %b, 0
433 store volatile i32 0, i32* %p
434 br i1 %c, label %true, label %false
435true:
436 store volatile i32 1, i32* %p
437 br label %exit
438false:
439 store volatile i32 2, i32* %p
440 br i1 %d, label %ft, label %ff
441ft:
442 store volatile i32 3, i32* %p
443 br label %exit
444ff:
445 store volatile i32 4, i32* %p
446 br label %exit
447exit:
448 store volatile i32 5, i32* %p
449 br label %header
450}
451
Dan Gohmane3e4a5f2015-10-02 21:11:36 +0000452; Test that nested loops are handled.
453
Dan Gohman8fe7e862015-12-14 22:51:54 +0000454; CHECK-LABEL: test3:
455; CHECK: loop
456; CHECK-NEXT: br_if
Dan Gohmana4730cf2016-01-07 18:49:53 +0000457; CHECK-NEXT: .LBB{{[0-9]+}}_{{[0-9]+}}:
Dan Gohman8fe7e862015-12-14 22:51:54 +0000458; CHECK-NEXT: loop
459; OPT-LABEL: test3:
Dan Gohman442bfce2016-02-16 16:22:41 +0000460; OPT: block
461; OPT: br_if
462; OPT-NEXT: return
463; OPT-NEXT: .LBB{{[0-9]+}}_{{[0-9]+}}:
464; OPT-NEXT: end_block
465; OPT-NEXT: loop
466; OPT-NEXT: block
467; OPT-NEXT: block
Dan Gohman8fe7e862015-12-14 22:51:54 +0000468; OPT-NEXT: br_if
Dan Gohmana4730cf2016-01-07 18:49:53 +0000469; OPT-NEXT: .LBB{{[0-9]+}}_{{[0-9]+}}:
Dan Gohman8fe7e862015-12-14 22:51:54 +0000470; OPT-NEXT: loop
Dan Gohman442bfce2016-02-16 16:22:41 +0000471; OPT: br_if
472; OPT-NEXT: br
473; OPT-NEXT: .LBB{{[0-9]+}}_{{[0-9]+}}:
474; OPT-NEXT: end_loop
475; OPT-NEXT: end_block
476; OPT-NEXT: unreachable
477; OPT-NEXT: .LBB{{[0-9]+}}_{{[0-9]+}}:
478; OPT-NEXT: end_block
479; OPT: br
480; OPT-NEXT: .LBB{{[0-9]+}}_{{[0-9]+}}:
481; OPT-NEXT: end_loop
Dan Gohmane3e4a5f2015-10-02 21:11:36 +0000482declare void @bar()
Dan Gohmane3e4a5f2015-10-02 21:11:36 +0000483define void @test3(i32 %w) {
484entry:
485 br i1 undef, label %outer.ph, label %exit
486
487outer.ph:
488 br label %outer
489
490outer:
491 %tobool = icmp eq i32 undef, 0
492 br i1 %tobool, label %inner, label %unreachable
493
494unreachable:
495 unreachable
496
497inner:
498 %c = icmp eq i32 undef, %w
499 br i1 %c, label %if.end, label %inner
500
501exit:
502 ret void
503
504if.end:
505 call void @bar()
506 br label %outer
507}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000508
509; Test switch lowering and block placement.
510
511; CHECK-LABEL: test4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000512; CHECK-NEXT: .param i32{{$}}
513; CHECK: block{{$}}
514; CHECK-NEXT: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000515; CHECK: br_if 0, $pop{{[0-9]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000516; CHECK-NEXT: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000517; CHECK: br_if 0, $pop{{[0-9]+}}{{$}}
518; CHECK: br_if 2, $pop{{[0-9]+}}{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000519; CHECK-NEXT: .LBB13_3:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000520; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000521; CHECK-NEXT: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000522; CHECK-NEXT: .LBB13_4:
Dan Gohman442bfce2016-02-16 16:22:41 +0000523; CHECK-NEXT: end_block{{$}}
524; CHECK-NEXT: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000525; CHECK: br_if 0, $pop{{[0-9]+}}{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +0000526; CHECK: br_if 1, $pop{{[0-9]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000527; CHECK-NEXT: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000528; CHECK-NEXT: .LBB13_7:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000529; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000530; CHECK-NEXT: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000531; CHECK-NEXT: .LBB13_8:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000532; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000533; CHECK-NEXT: return{{$}}
534; OPT-LABEL: test4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000535; OPT-NEXT: .param i32{{$}}
536; OPT: block{{$}}
537; OPT-NEXT: block{{$}}
538; OPT-NEXT: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000539; OPT: br_if 0, $pop{{[0-9]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000540; OPT-NEXT: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000541; OPT: br_if 0, $pop{{[0-9]+}}{{$}}
542; OPT: br_if 2, $pop{{[0-9]+}}{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000543; OPT-NEXT: .LBB13_3:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000544; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000545; OPT-NEXT: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000546; OPT-NEXT: .LBB13_4:
Dan Gohman06b49582016-02-08 21:50:13 +0000547; OPT: br_if 1, $pop{{[0-9]+}}{{$}}
548; OPT: br_if 0, $pop{{[0-9]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000549; OPT-NEXT: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000550; OPT-NEXT: .LBB13_7:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000551; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000552; OPT-NEXT: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000553; OPT-NEXT: .LBB13_8:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000554; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000555; OPT-NEXT: return{{$}}
556define void @test4(i32 %t) {
557entry:
558 switch i32 %t, label %default [
559 i32 0, label %bb2
560 i32 2, label %bb2
561 i32 4, label %bb1
562 i32 622, label %bb0
563 ]
564
565bb0:
566 ret void
567
568bb1:
569 ret void
570
571bb2:
572 ret void
573
574default:
575 ret void
576}
577
578; Test a case where the BLOCK needs to be placed before the LOOP in the
579; same basic block.
580
581; CHECK-LABEL: test5:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000582; CHECK: .LBB14_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000583; CHECK-NEXT: block{{$}}
584; CHECK-NEXT: loop{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000585; CHECK: br_if 2, {{[^,]+}}{{$}}
586; CHECK: br_if 0, {{[^,]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000587; CHECK-NEXT: end_loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000588; CHECK: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000589; CHECK-NEXT: .LBB14_4:
Dan Gohman8fe7e862015-12-14 22:51:54 +0000590; CHECK: return{{$}}
591; OPT-LABEL: test5:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000592; OPT: .LBB14_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000593; OPT-NEXT: block{{$}}
594; OPT-NEXT: loop{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000595; OPT: br_if 2, {{[^,]+}}{{$}}
596; OPT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000597; OPT-NEXT: end_loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000598; OPT: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000599; OPT-NEXT: .LBB14_4:
Dan Gohman8fe7e862015-12-14 22:51:54 +0000600; OPT: return{{$}}
601define void @test5(i1 %p, i1 %q) {
602entry:
603 br label %header
604
605header:
606 store volatile i32 0, i32* null
607 br i1 %p, label %more, label %alt
608
609more:
610 store volatile i32 1, i32* null
611 br i1 %q, label %header, label %return
612
613alt:
614 store volatile i32 2, i32* null
615 ret void
616
617return:
618 store volatile i32 3, i32* null
619 ret void
620}
621
622; Test an interesting case of a loop with multiple exits, which
623; aren't to layout successors of the loop, and one of which is to a successors
624; which has another predecessor.
625
626; CHECK-LABEL: test6:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000627; CHECK: .LBB15_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000628; CHECK-NEXT: block{{$}}
629; CHECK-NEXT: block{{$}}
630; CHECK-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000631; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000632; CHECK: br_if 3, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000633; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000634; CHECK: br_if 2, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000635; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000636; CHECK: br_if 0, {{[^,]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000637; CHECK-NEXT: end_loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000638; CHECK-NOT: block
639; CHECK: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000640; CHECK-NEXT: .LBB15_5:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000641; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000642; CHECK-NOT: block
Dan Gohmana4730cf2016-01-07 18:49:53 +0000643; CHECK: .LBB15_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000644; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000645; CHECK-NOT: block
646; CHECK: return{{$}}
647; OPT-LABEL: test6:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000648; OPT: .LBB15_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000649; OPT-NEXT: block{{$}}
650; OPT-NEXT: block{{$}}
651; OPT-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000652; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000653; OPT: br_if 3, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000654; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000655; OPT: br_if 2, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000656; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000657; OPT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000658; OPT-NEXT: end_loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000659; OPT-NOT: block
660; OPT: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000661; OPT-NEXT: .LBB15_5:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000662; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000663; OPT-NOT: block
Dan Gohmana4730cf2016-01-07 18:49:53 +0000664; OPT: .LBB15_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000665; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000666; OPT-NOT: block
667; OPT: return{{$}}
668define void @test6(i1 %p, i1 %q) {
669entry:
670 br label %header
671
672header:
673 store volatile i32 0, i32* null
674 br i1 %p, label %more, label %second
675
676more:
677 store volatile i32 1, i32* null
678 br i1 %q, label %evenmore, label %first
679
680evenmore:
681 store volatile i32 1, i32* null
682 br i1 %q, label %header, label %return
683
684return:
685 store volatile i32 2, i32* null
686 ret void
687
688first:
689 store volatile i32 3, i32* null
690 br label %second
691
692second:
693 store volatile i32 4, i32* null
694 ret void
695}
696
697; Test a case where there are multiple backedges and multiple loop exits
698; that end in unreachable.
699
700; CHECK-LABEL: test7:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000701; CHECK: .LBB16_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000702; CHECK-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000703; CHECK-NOT: block
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000704; CHECK: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000705; CHECK: br_if 0, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000706; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000707; CHECK: br_if 1, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000708; CHECK-NOT: block
709; CHECK: unreachable
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000710; CHECK-NEXT: .LBB16_4:
711; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000712; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000713; CHECK: br_if 0, {{[^,]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000714; CHECK-NEXT: end_loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000715; CHECK-NOT: block
716; CHECK: unreachable
717; OPT-LABEL: test7:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000718; OPT: .LBB16_1:
Dan Gohman442bfce2016-02-16 16:22:41 +0000719; OPT-NEXT: block
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000720; OPT-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000721; OPT-NOT: block
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000722; OPT: block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000723; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000724; OPT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000725; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000726; OPT: br_if 1, {{[^,]+}}{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +0000727; OPT: br 3{{$}}
728; OPT-NEXT: .LBB16_3:
729; OPT-NEXT: end_block
Dan Gohman8fe7e862015-12-14 22:51:54 +0000730; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000731; OPT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +0000732; OPT-NEXT: end_loop
733; OPT-NOT: block
734; OPT: unreachable
735; OPT-NEXT: .LBB16_5:
736; OPT-NEXT: end_block
Dan Gohman8fe7e862015-12-14 22:51:54 +0000737; OPT-NOT: block
738; OPT: unreachable
739define void @test7(i1 %tobool2, i1 %tobool9) {
740entry:
741 store volatile i32 0, i32* null
742 br label %loop
743
744loop:
745 store volatile i32 1, i32* null
746 br i1 %tobool2, label %l1, label %l0
747
748l0:
749 store volatile i32 2, i32* null
750 br i1 %tobool9, label %loop, label %u0
751
752l1:
753 store volatile i32 3, i32* null
754 br i1 %tobool9, label %loop, label %u1
755
756u0:
757 store volatile i32 4, i32* null
758 unreachable
759
760u1:
761 store volatile i32 5, i32* null
762 unreachable
763}
764
765; Test an interesting case using nested loops and switches.
766
767; CHECK-LABEL: test8:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000768; CHECK: .LBB17_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000769; CHECK-NEXT: loop{{$}}
770; CHECK-NEXT: block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000771; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000772; CHECK: br_if 0, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000773; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000774; CHECK: br_if 1, {{[^,]+}}{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000775; CHECK-NEXT: .LBB17_3:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000776; CHECK-NEXT: end_block{{$}}
777; CHECK-NEXT: loop{{$}}
Dan Gohmane5d3c152016-01-20 05:55:09 +0000778; CHECK-NEXT: i32.const $push{{[^,]+}}, 0{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000779; CHECK-NEXT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000780; CHECK-NEXT: br 2{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000781; CHECK-NEXT: .LBB17_4:
Dan Gohman8fe7e862015-12-14 22:51:54 +0000782; OPT-LABEL: test8:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000783; OPT: .LBB17_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000784; OPT-NEXT: loop{{$}}
785; OPT-NEXT: block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000786; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000787; OPT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000788; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000789; OPT: br_if 1, {{[^,]+}}{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000790; OPT-NEXT: .LBB17_3:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000791; OPT-NEXT: end_block{{$}}
792; OPT-NEXT: loop{{$}}
Dan Gohmane5d3c152016-01-20 05:55:09 +0000793; OPT-NEXT: i32.const $push{{[^,]+}}, 0{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000794; OPT-NEXT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000795; OPT-NEXT: br 2{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000796; OPT-NEXT: .LBB17_4:
Dan Gohman8fe7e862015-12-14 22:51:54 +0000797define i32 @test8() {
798bb:
799 br label %bb1
800
801bb1:
802 br i1 undef, label %bb2, label %bb3
803
804bb2:
805 switch i8 undef, label %bb1 [
806 i8 44, label %bb2
807 ]
808
809bb3:
810 switch i8 undef, label %bb1 [
811 i8 44, label %bb2
812 ]
813}
814
815; Test an interesting case using nested loops that share a bottom block.
816
817; CHECK-LABEL: test9:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000818; CHECK: .LBB18_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000819; CHECK-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000820; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000821; CHECK: br_if 1, {{[^,]+}}{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000822; CHECK-NEXT: .LBB18_2:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000823; CHECK-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000824; CHECK-NOT: block
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000825; CHECK: block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000826; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000827; CHECK: br_if 0, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000828; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000829; CHECK: br_if 1, {{[^,]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000830; CHECK-NEXT: br 3{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000831; CHECK-NEXT: .LBB18_4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000832; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000833; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000834; CHECK: br_if 0, {{[^,]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000835; CHECK-NEXT: br 2{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000836; CHECK-NEXT: .LBB18_5:
Dan Gohman8fe7e862015-12-14 22:51:54 +0000837; CHECK-NOT: block
838; CHECK: return{{$}}
839; OPT-LABEL: test9:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000840; OPT: .LBB18_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000841; OPT-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000842; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000843; OPT: br_if 1, {{[^,]+}}{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000844; OPT-NEXT: .LBB18_2:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000845; OPT-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000846; OPT-NOT: block
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000847; OPT: block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000848; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000849; OPT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000850; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000851; OPT: br_if 1, {{[^,]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000852; OPT-NEXT: br 3{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000853; OPT-NEXT: .LBB18_4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000854; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000855; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000856; OPT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000857; OPT-NEXT: br 2{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000858; OPT-NEXT: .LBB18_5:
Dan Gohman8fe7e862015-12-14 22:51:54 +0000859; OPT-NOT: block
860; OPT: return{{$}}
861declare i1 @a()
862define void @test9() {
863entry:
864 store volatile i32 0, i32* null
865 br label %header
866
867header:
868 store volatile i32 1, i32* null
869 %call4 = call i1 @a()
870 br i1 %call4, label %header2, label %end
871
872header2:
873 store volatile i32 2, i32* null
874 %call = call i1 @a()
875 br i1 %call, label %if.then, label %if.else
876
877if.then:
878 store volatile i32 3, i32* null
879 %call3 = call i1 @a()
880 br i1 %call3, label %header2, label %header
881
882if.else:
883 store volatile i32 4, i32* null
884 %call2 = call i1 @a()
885 br i1 %call2, label %header2, label %header
886
887end:
888 store volatile i32 5, i32* null
889 ret void
890}
891
892; Test an interesting case involving nested loops sharing a loop bottom,
893; and loop exits to a block with unreachable.
894
895; CHECK-LABEL: test10:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000896; CHECK: .LBB19_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000897; CHECK-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000898; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000899; CHECK: br_if 0, {{[^,]+}}{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000900; CHECK-NEXT: .LBB19_2:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000901; CHECK-NEXT: block{{$}}
902; CHECK-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000903; CHECK-NOT: block
Dan Gohmana4730cf2016-01-07 18:49:53 +0000904; CHECK: .LBB19_3:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000905; CHECK-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000906; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000907; CHECK: br_if 5, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000908; CHECK-NOT: block
Dan Gohmane5d3c152016-01-20 05:55:09 +0000909; CHECK: tableswitch {{[^,]+}}, 0, 0, 1, 5, 2, 4{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000910; CHECK-NEXT: .LBB19_5:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000911; CHECK-NEXT: end_loop{{$}}
912; CHECK-NEXT: end_loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000913; CHECK-NEXT: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000914; CHECK-NEXT: .LBB19_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000915; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000916; CHECK-NOT: block
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000917; CHECK: br 0{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000918; CHECK-NEXT: .LBB19_7:
Dan Gohman8fe7e862015-12-14 22:51:54 +0000919; OPT-LABEL: test10:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000920; OPT: .LBB19_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000921; OPT-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000922; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000923; OPT: br_if 0, {{[^,]+}}{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000924; OPT-NEXT: .LBB19_2:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000925; OPT-NEXT: block{{$}}
926; OPT-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000927; OPT-NOT: block
Dan Gohmana4730cf2016-01-07 18:49:53 +0000928; OPT: .LBB19_3:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000929; OPT-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000930; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000931; OPT: br_if 5, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000932; OPT-NOT: block
Dan Gohmane5d3c152016-01-20 05:55:09 +0000933; OPT: tableswitch {{[^,]+}}, 0, 0, 1, 5, 2, 4{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000934; OPT-NEXT: .LBB19_5:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000935; OPT-NEXT: end_loop{{$}}
936; OPT-NEXT: end_loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000937; OPT-NEXT: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000938; OPT-NEXT: .LBB19_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000939; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000940; OPT-NOT: block
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000941; OPT: br 0{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000942; OPT-NEXT: .LBB19_7:
Dan Gohman8fe7e862015-12-14 22:51:54 +0000943define void @test10() {
944bb0:
945 br label %bb1
946
947bb1:
948 %tmp = phi i32 [ 2, %bb0 ], [ 3, %bb3 ]
949 %tmp3 = phi i32 [ undef, %bb0 ], [ %tmp11, %bb3 ]
950 %tmp4 = icmp eq i32 %tmp3, 0
951 br i1 %tmp4, label %bb4, label %bb2
952
953bb2:
954 br label %bb3
955
956bb3:
957 %tmp11 = phi i32 [ 1, %bb5 ], [ 0, %bb2 ]
958 br label %bb1
959
960bb4:
961 %tmp6 = phi i32 [ %tmp9, %bb5 ], [ 4, %bb1 ]
962 %tmp7 = phi i32 [ %tmp6, %bb5 ], [ %tmp, %bb1 ]
963 br label %bb5
964
965bb5:
966 %tmp9 = phi i32 [ %tmp6, %bb5 ], [ %tmp7, %bb4 ]
967 switch i32 %tmp9, label %bb2 [
968 i32 0, label %bb5
969 i32 1, label %bb6
970 i32 3, label %bb4
971 i32 4, label %bb3
972 ]
973
974bb6:
975 ret void
976}
977
978; Test a CFG DAG with interesting merging.
979
980; CHECK-LABEL: test11:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000981; CHECK: block{{$}}
982; CHECK-NEXT: block{{$}}
983; CHECK-NEXT: block{{$}}
984; CHECK-NEXT: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000985; CHECK: br_if 0, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000986; CHECK-NOT: block
Dan Gohmaned0f1132016-01-30 05:01:06 +0000987; CHECK: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000988; CHECK-NEXT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000989; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000990; CHECK: br_if 2, {{[^,]+}}{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000991; CHECK-NEXT: .LBB20_3:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000992; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000993; CHECK-NOT: block
994; CHECK: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000995; CHECK-NEXT: .LBB20_4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000996; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000997; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000998; CHECK: br_if 1, {{[^,]+}}{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +0000999; CHECK-NOT: block
1000; CHECK: br_if 2, {{[^,]+}}{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +00001001; CHECK-NEXT: .LBB20_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001002; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001003; CHECK-NOT: block
1004; CHECK: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +00001005; CHECK-NEXT: .LBB20_7:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001006; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001007; CHECK-NOT: block
1008; CHECK: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +00001009; CHECK-NEXT: .LBB20_8:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001010; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001011; CHECK-NOT: block
1012; CHECK: return{{$}}
1013; OPT-LABEL: test11:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001014; OPT: block{{$}}
1015; OPT-NEXT: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +00001016; OPT: br_if 0, $pop{{[0-9]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001017; OPT-NOT: block
Dan Gohmaned0f1132016-01-30 05:01:06 +00001018; OPT: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +00001019; OPT-NEXT: br_if 0, $0{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001020; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +00001021; OPT: br_if 2, {{[^,]+}}{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +00001022; OPT-NEXT: .LBB20_3:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001023; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001024; OPT-NOT: block
1025; OPT: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +00001026; OPT-NEXT: .LBB20_4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001027; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001028; OPT-NOT: block
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001029; OPT: block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001030; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +00001031; OPT: br_if 0, $pop{{[0-9]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001032; OPT-NOT: block
1033; OPT: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +00001034; OPT-NEXT: .LBB20_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001035; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001036; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +00001037; OPT: br_if 0, $pop{{[0-9]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001038; OPT-NOT: block
1039; OPT: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +00001040; OPT-NEXT: .LBB20_8:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001041; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001042; OPT-NOT: block
1043; OPT: return{{$}}
1044define void @test11() {
1045bb0:
1046 store volatile i32 0, i32* null
1047 br i1 undef, label %bb1, label %bb4
1048bb1:
1049 store volatile i32 1, i32* null
1050 br i1 undef, label %bb3, label %bb2
1051bb2:
1052 store volatile i32 2, i32* null
1053 br i1 undef, label %bb3, label %bb7
1054bb3:
1055 store volatile i32 3, i32* null
1056 ret void
1057bb4:
1058 store volatile i32 4, i32* null
1059 br i1 undef, label %bb8, label %bb5
1060bb5:
1061 store volatile i32 5, i32* null
1062 br i1 undef, label %bb6, label %bb7
1063bb6:
1064 store volatile i32 6, i32* null
1065 ret void
1066bb7:
1067 store volatile i32 7, i32* null
1068 ret void
1069bb8:
1070 store volatile i32 8, i32* null
1071 ret void
1072}
1073
1074; CHECK-LABEL: test12:
Dan Gohmana4730cf2016-01-07 18:49:53 +00001075; CHECK: .LBB21_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001076; CHECK-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001077; CHECK-NOT: block
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001078; CHECK: block{{$}}
1079; CHECK-NEXT: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +00001080; CHECK: br_if 0, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001081; CHECK-NOT: block
Dan Gohman442bfce2016-02-16 16:22:41 +00001082; CHECK: br_if 1, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001083; CHECK-NOT: block
Dan Gohman442bfce2016-02-16 16:22:41 +00001084; CHECK: br_if 1, {{[^,]+}}{{$}}
1085; CHECK-NEXT: br 3{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +00001086; CHECK-NEXT: .LBB21_4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001087; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001088; CHECK-NOT: block
Dan Gohman442bfce2016-02-16 16:22:41 +00001089; CHECK: br_if 0, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001090; CHECK-NOT: block
Dan Gohman442bfce2016-02-16 16:22:41 +00001091; CHECK: br_if 2, {{[^,]+}}{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +00001092; CHECK-NEXT: .LBB21_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001093; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001094; CHECK-NOT: block
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001095; CHECK: br 0{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +00001096; CHECK-NEXT: .LBB21_7:
1097; CHECK-NEXT: end_loop{{$}}
1098; CHECK-NEXT: return{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001099; OPT-LABEL: test12:
Dan Gohmana4730cf2016-01-07 18:49:53 +00001100; OPT: .LBB21_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001101; OPT-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001102; OPT-NOT: block
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001103; OPT: block{{$}}
1104; OPT-NEXT: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +00001105; OPT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001106; OPT-NOT: block
Dan Gohman442bfce2016-02-16 16:22:41 +00001107; OPT: br_if 1, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001108; OPT-NOT: block
Dan Gohman442bfce2016-02-16 16:22:41 +00001109; OPT: br_if 1, {{[^,]+}}{{$}}
1110; OPT-NEXT: br 3{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +00001111; OPT-NEXT: .LBB21_4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001112; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001113; OPT-NOT: block
Dan Gohman442bfce2016-02-16 16:22:41 +00001114; OPT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001115; OPT-NOT: block
Dan Gohman442bfce2016-02-16 16:22:41 +00001116; OPT: br_if 2, {{[^,]+}}{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +00001117; OPT-NEXT: .LBB21_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001118; OPT-NEXT: end_block{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001119; OPT: br 0{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +00001120; OPT-NEXT: .LBB21_7:
1121; OPT-NEXT: end_loop{{$}}
1122; OPT-NEXT: return{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001123define void @test12(i8* %arg) {
1124bb:
1125 br label %bb1
1126
1127bb1:
1128 %tmp = phi i32 [ 0, %bb ], [ %tmp5, %bb4 ]
1129 %tmp2 = getelementptr i8, i8* %arg, i32 %tmp
1130 %tmp3 = load i8, i8* %tmp2
1131 switch i8 %tmp3, label %bb7 [
1132 i8 42, label %bb4
1133 i8 76, label %bb4
1134 i8 108, label %bb4
1135 i8 104, label %bb4
1136 ]
1137
1138bb4:
1139 %tmp5 = add i32 %tmp, 1
1140 br label %bb1
1141
1142bb7:
1143 ret void
1144}
Dan Gohmanb3aa1ec2015-12-16 19:06:41 +00001145
1146; A block can be "branched to" from another even if it is also reachable via
1147; fallthrough from the other. This would normally be optimized away, so use
1148; optnone to disable optimizations to test this case.
1149
1150; CHECK-LABEL: test13:
Dan Gohmanb6fd39a2016-01-19 16:59:23 +00001151; CHECK-NEXT: .local i32{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +00001152; CHECK-NEXT: block{{$}}
1153; CHECK-NEXT: block{{$}}
1154; CHECK: br_if 0, $pop0{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001155; CHECK: block{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +00001156; CHECK: br_if 0, $pop3{{$}}
1157; CHECK: .LBB22_3:
1158; CHECK-NEXT: end_block{{$}}
1159; CHECK: br_if 1, $pop{{[0-9]+}}{{$}}
1160; CHECK-NEXT: br 1{{$}}
1161; CHECK-NEXT: .LBB22_4:
1162; CHECK-NEXT: end_block{{$}}
Dan Gohmanb3aa1ec2015-12-16 19:06:41 +00001163; CHECK-NEXT: return{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +00001164; CHECK-NEXT: .LBB22_5:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001165; CHECK-NEXT: end_block{{$}}
Dan Gohmanb3aa1ec2015-12-16 19:06:41 +00001166; CHECK-NEXT: unreachable{{$}}
1167; OPT-LABEL: test13:
Dan Gohmanb6fd39a2016-01-19 16:59:23 +00001168; OPT-NEXT: .local i32{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +00001169; OPT-NEXT: block{{$}}
1170; OPT-NEXT: block{{$}}
1171; OPT: br_if 0, $pop0{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001172; OPT: block{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +00001173; OPT: br_if 0, $pop3{{$}}
1174; OPT: .LBB22_3:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001175; OPT-NEXT: end_block{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +00001176; OPT: br_if 1, $pop{{[0-9]+}}{{$}}
1177; OPT-NEXT: br 1{{$}}
1178; OPT-NEXT: .LBB22_4:
1179; OPT-NEXT: end_block
1180; OPT-NEXT: return
1181; OPT-NEXT: .LBB22_5:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001182; OPT-NEXT: end_block{{$}}
Dan Gohmanb3aa1ec2015-12-16 19:06:41 +00001183; OPT-NEXT: unreachable{{$}}
1184define void @test13() noinline optnone {
1185bb:
1186 br i1 undef, label %bb5, label %bb2
1187bb1:
1188 unreachable
1189bb2:
1190 br i1 undef, label %bb3, label %bb4
1191bb3:
1192 br label %bb4
1193bb4:
1194 %tmp = phi i1 [ false, %bb2 ], [ false, %bb3 ]
1195 br i1 %tmp, label %bb1, label %bb1
1196bb5:
1197 ret void
1198}
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001199
1200; Test a case with a single-block loop that has another loop
1201; as a successor. The end_loop for the first loop should go
1202; before the loop for the second.
1203
1204; CHECK-LABEL: test14:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001205; CHECK-NEXT: .LBB23_1:{{$}}
1206; CHECK-NEXT: loop{{$}}
Dan Gohmanb6fd39a2016-01-19 16:59:23 +00001207; CHECK-NEXT: i32.const $push0=, 0{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +00001208; CHECK-NEXT: br_if 0, $pop0{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001209; CHECK-NEXT: .LBB23_2:{{$}}
1210; CHECK-NEXT: end_loop{{$}}
1211; CHECK-NEXT: loop{{$}}
Dan Gohman899cb5a2016-01-25 16:48:44 +00001212; CHECK-NEXT: i32.const $discard=, 0{{$}}
Dan Gohmanb6fd39a2016-01-19 16:59:23 +00001213; CHECK-NEXT: i32.const $push1=, 0{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +00001214; CHECK-NEXT: br_if 0, $pop1{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001215; CHECK-NEXT: end_loop{{$}}
1216; CHECK-NEXT: return{{$}}
1217define void @test14() {
1218bb:
1219 br label %bb1
1220
1221bb1:
1222 %tmp = bitcast i1 undef to i1
1223 br i1 %tmp, label %bb3, label %bb1
1224
1225bb3:
1226 br label %bb4
1227
1228bb4:
1229 br i1 undef, label %bb7, label %bb48
1230
1231bb7:
1232 br i1 undef, label %bb12, label %bb12
1233
1234bb12:
1235 br i1 undef, label %bb17, label %bb17
1236
1237bb17:
1238 br i1 undef, label %bb22, label %bb22
1239
1240bb22:
1241 br i1 undef, label %bb27, label %bb27
1242
1243bb27:
1244 br i1 undef, label %bb30, label %bb30
1245
1246bb30:
1247 br i1 undef, label %bb35, label %bb35
1248
1249bb35:
1250 br i1 undef, label %bb38, label %bb38
1251
1252bb38:
1253 br i1 undef, label %bb48, label %bb48
1254
1255bb48:
1256 %tmp49 = bitcast i1 undef to i1
1257 br i1 %tmp49, label %bb3, label %bb50
1258
1259bb50:
1260 ret void
1261}
Dan Gohmana187ab22016-02-12 21:19:25 +00001262
1263; Test that a block boundary which ends one block, begins another block, and
1264; also begins a loop, has the markers placed in the correct order.
1265
1266; CHECK-LABEL: test15:
1267; CHECK: block
Dan Gohmana187ab22016-02-12 21:19:25 +00001268; CHECK-NEXT: block
Dan Gohman442bfce2016-02-16 16:22:41 +00001269; CHECK: br_if 0, $pop{{.*}}{{$}}
1270; CHECK-NEXT: .LBB24_1:
1271; CHECK-NEXT: block{{$}}
1272; CHECK-NEXT: loop{{$}}
1273; CHECK: br_if 1, $pop{{.*}}{{$}}
1274; CHECK: br_if 2, $pop{{.*}}{{$}}
1275; CHECK-NEXT: br 0{{$}}
1276; CHECK-NEXT: .LBB24_3:
1277; CHECK-NEXT: end_loop{{$}}
1278; CHECK: .LBB24_4:
1279; CHECK-NEXT: end_block{{$}}
1280; CHECK: br_if 1, $pop{{.*}}{{$}}
1281; CHECK: return{{$}}
1282; CHECK: .LBB24_6:
1283; CHECK-NEXT: end_block{{$}}
1284; CHECK: return{{$}}
1285; CHECK: .LBB24_7:
1286; CHECK-NEXT: end_block{{$}}
1287; CHECK-NEXT: return{{$}}
Dan Gohmana187ab22016-02-12 21:19:25 +00001288; OPT-LABEL: test15:
1289; OPT: block
1290; OPT-NEXT: i32.const $push
1291; OPT-NEXT: i32.const $push
1292; OPT-NEXT: i32.eq $push{{.*}}=, $pop{{.*}}, $pop{{.*}}{{$}}
1293; OPT-NEXT: br_if 0, $pop{{.*}}{{$}}
1294; OPT-NEXT: call test15_callee1@FUNCTION{{$}}
1295; OPT-NEXT: return{{$}}
1296; OPT-NEXT: .LBB24_2:
1297; OPT-NEXT: end_block
1298; OPT-NEXT: block
1299; OPT-NEXT: loop
1300%0 = type { i8, i32 }
1301declare void @test15_callee0()
1302declare void @test15_callee1()
1303define void @test15() {
1304bb:
1305 %tmp1 = icmp eq i8 1, 0
1306 br i1 %tmp1, label %bb2, label %bb14
1307
1308bb2:
1309 %tmp3 = phi %0** [ %tmp6, %bb5 ], [ null, %bb ]
1310 %tmp4 = icmp eq i32 0, 11
1311 br i1 %tmp4, label %bb5, label %bb8
1312
1313bb5:
1314 %tmp = bitcast i8* null to %0**
1315 %tmp6 = getelementptr %0*, %0** %tmp3, i32 1
1316 %tmp7 = icmp eq %0** %tmp6, null
1317 br i1 %tmp7, label %bb10, label %bb2
1318
1319bb8:
1320 %tmp9 = icmp eq %0** null, undef
1321 br label %bb10
1322
1323bb10:
1324 %tmp11 = phi %0** [ null, %bb8 ], [ %tmp, %bb5 ]
1325 %tmp12 = icmp eq %0** null, %tmp11
1326 br i1 %tmp12, label %bb15, label %bb13
1327
1328bb13:
1329 call void @test15_callee0()
1330 ret void
1331
1332bb14:
1333 call void @test15_callee1()
1334 ret void
1335
1336bb15:
1337 ret void
1338}