blob: 3b42df190266fe3db6fb4ffa05db0841b1f5c71d [file] [log] [blame]
Jun Bum Lim90b6b502016-12-16 20:38:39 +00001; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -disable-block-placement -verify-machineinstrs -fast-isel=false -machine-sink-split-probability-threshold=0 -cgp-freq-ratio-to-skip-merge=1000 | FileCheck %s
2; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -tail-dup-placement=0 -verify-machineinstrs -fast-isel=false -machine-sink-split-probability-threshold=0 -cgp-freq-ratio-to-skip-merge=1000 | FileCheck -check-prefix=OPT %s
Dan Gohman950a13c2015-09-16 16:51:30 +00003
4; Test the CFG stackifier pass.
5
Dan Gohman2e644382016-05-10 17:39:48 +00006; Explicitly disable fast-isel, since it gets implicitly enabled in the
7; optnone test.
8
Dan Gohman0c6f5ac2016-01-07 03:19:23 +00009target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
Dan Gohman950a13c2015-09-16 16:51:30 +000010target triple = "wasm32-unknown-unknown"
11
12declare void @something()
13
14; Test that loops are made contiguous, even in the presence of split backedges.
15
Dan Gohmane51c0582015-10-06 00:27:55 +000016; CHECK-LABEL: test0:
17; CHECK: loop
Dan Gohman442bfce2016-02-16 16:22:41 +000018; CHECK-NEXT: block
Dan Gohman12de0b92016-05-17 20:19:47 +000019; CHECK: i32.lt_s
Dan Gohman8fe7e862015-12-14 22:51:54 +000020; CHECK-NEXT: br_if
Dan Gohman442bfce2016-02-16 16:22:41 +000021; CHECK-NEXT: return
22; CHECK-NEXT: .LBB0_3:
23; CHECK-NEXT: end_block
Reid Klecknerbb865232016-08-15 18:51:42 +000024; CHECK-NEXT: i32.const
25; CHECK-NEXT: i32.add
Dan Gohman442bfce2016-02-16 16:22:41 +000026; CHECK-NEXT: call
27; CHECK-NEXT: br
28; CHECK-NEXT: .LBB0_4:
29; CHECK-NEXT: end_loop
Dan Gohmanf0b165a2015-12-05 03:03:35 +000030; OPT-LABEL: test0:
31; OPT: loop
Dan Gohman12de0b92016-05-17 20:19:47 +000032; OPT: i32.ge_s
Dan Gohman8fe7e862015-12-14 22:51:54 +000033; OPT-NEXT: br_if
Reid Klecknerbb865232016-08-15 18:51:42 +000034; OPT-NEXT: i32.const
35; OPT-NEXT: i32.add
Dan Gohmanf0b165a2015-12-05 03:03:35 +000036; OPT-NOT: br
37; OPT: call
Dan Gohman1d68e80f2016-01-12 19:14:46 +000038; OPT: br 0{{$}}
Dan Gohmanf0b165a2015-12-05 03:03:35 +000039; OPT: return{{$}}
Dan Gohman950a13c2015-09-16 16:51:30 +000040define void @test0(i32 %n) {
41entry:
42 br label %header
43
44header:
45 %i = phi i32 [ 0, %entry ], [ %i.next, %back ]
46 %i.next = add i32 %i, 1
47
48 %c = icmp slt i32 %i.next, %n
49 br i1 %c, label %back, label %exit
50
51exit:
52 ret void
53
54back:
55 call void @something()
56 br label %header
57}
58
59; Same as test0, but the branch condition is reversed.
60
Dan Gohmane51c0582015-10-06 00:27:55 +000061; CHECK-LABEL: test1:
62; CHECK: loop
Dan Gohman442bfce2016-02-16 16:22:41 +000063; CHECK-NEXT: block
Dan Gohman12de0b92016-05-17 20:19:47 +000064; CHECK: i32.lt_s
Dan Gohman8fe7e862015-12-14 22:51:54 +000065; CHECK-NEXT: br_if
Dan Gohman442bfce2016-02-16 16:22:41 +000066; CHECK-NEXT: return
67; CHECK-NEXT: .LBB1_3:
68; CHECK-NEXT: end_block
Reid Klecknerbb865232016-08-15 18:51:42 +000069; CHECK-NEXT: i32.const
70; CHECK-NEXT: i32.add
Dan Gohman442bfce2016-02-16 16:22:41 +000071; CHECK-NEXT: call
72; CHECK-NEXT: br
73; CHECK-NEXT: .LBB1_4:
74; CHECK-NEXT: end_loop
Dan Gohmanf0b165a2015-12-05 03:03:35 +000075; OPT-LABEL: test1:
76; OPT: loop
Dan Gohman12de0b92016-05-17 20:19:47 +000077; OPT: i32.ge_s
Dan Gohman8fe7e862015-12-14 22:51:54 +000078; OPT-NEXT: br_if
Reid Klecknerbb865232016-08-15 18:51:42 +000079; OPT-NEXT: i32.const
80; OPT-NEXT: i32.add
Dan Gohmanf0b165a2015-12-05 03:03:35 +000081; OPT-NOT: br
82; OPT: call
Dan Gohman1d68e80f2016-01-12 19:14:46 +000083; OPT: br 0{{$}}
Dan Gohmanf0b165a2015-12-05 03:03:35 +000084; OPT: return{{$}}
Dan Gohman950a13c2015-09-16 16:51:30 +000085define void @test1(i32 %n) {
86entry:
87 br label %header
88
89header:
90 %i = phi i32 [ 0, %entry ], [ %i.next, %back ]
91 %i.next = add i32 %i, 1
92
93 %c = icmp sge i32 %i.next, %n
94 br i1 %c, label %exit, label %back
95
96exit:
97 ret void
98
99back:
100 call void @something()
101 br label %header
102}
103
104; Test that a simple loop is handled as expected.
105
Dan Gohmane51c0582015-10-06 00:27:55 +0000106; CHECK-LABEL: test2:
Dan Gohman8f59cf72016-01-06 18:29:35 +0000107; CHECK-NOT: local
Dan Gohman2726b882016-10-06 22:29:32 +0000108; CHECK: block {{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000109; CHECK: br_if 0, {{[^,]+}}{{$}}
Dan Gohman0cfb5f82016-05-10 04:24:02 +0000110; CHECK: .LBB2_{{[0-9]+}}:
Dan Gohman12de0b92016-05-17 20:19:47 +0000111; CHECK: loop
112; CHECK: br_if 0, $pop{{[0-9]+}}{{$}}
Dan Gohman0cfb5f82016-05-10 04:24:02 +0000113; CHECK: .LBB2_{{[0-9]+}}:
Dan Gohman12de0b92016-05-17 20:19:47 +0000114; CHECK: end_loop
115; CHECK: end_block
Dan Gohmane51c0582015-10-06 00:27:55 +0000116; CHECK: return{{$}}
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000117; OPT-LABEL: test2:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000118; OPT-NOT: local
Dan Gohman2726b882016-10-06 22:29:32 +0000119; OPT: block {{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000120; OPT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman0cfb5f82016-05-10 04:24:02 +0000121; OPT: .LBB2_{{[0-9]+}}:
Dan Gohman12de0b92016-05-17 20:19:47 +0000122; OPT: loop
123; OPT: br_if 0, $pop{{[0-9]+}}{{$}}
Dan Gohman0cfb5f82016-05-10 04:24:02 +0000124; OPT: .LBB2_{{[0-9]+}}:
Dan Gohman12de0b92016-05-17 20:19:47 +0000125; OPT: end_loop
126; OPT: end_block
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000127; OPT: return{{$}}
Dan Gohman950a13c2015-09-16 16:51:30 +0000128define void @test2(double* nocapture %p, i32 %n) {
129entry:
130 %cmp.4 = icmp sgt i32 %n, 0
131 br i1 %cmp.4, label %for.body.preheader, label %for.end
132
133for.body.preheader:
134 br label %for.body
135
136for.body:
137 %i.05 = phi i32 [ %inc, %for.body ], [ 0, %for.body.preheader ]
138 %arrayidx = getelementptr inbounds double, double* %p, i32 %i.05
139 %0 = load double, double* %arrayidx, align 8
140 %mul = fmul double %0, 3.200000e+00
141 store double %mul, double* %arrayidx, align 8
142 %inc = add nuw nsw i32 %i.05, 1
143 %exitcond = icmp eq i32 %inc, %n
144 br i1 %exitcond, label %for.end.loopexit, label %for.body
145
146for.end.loopexit:
147 br label %for.end
148
149for.end:
150 ret void
151}
152
Dan Gohmane51c0582015-10-06 00:27:55 +0000153; CHECK-LABEL: doublediamond:
Dan Gohman2726b882016-10-06 22:29:32 +0000154; CHECK: block {{$}}
155; CHECK-NEXT: block {{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000156; CHECK: br_if 0, ${{[^,]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000157; CHECK: br 1{{$}}
158; CHECK: .LBB3_2:
159; CHECK-NEXT: end_block{{$}}
Dan Gohman2726b882016-10-06 22:29:32 +0000160; CHECK: block {{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000161; CHECK: br_if 0, ${{[^,]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000162; CHECK: br 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000163; CHECK: .LBB3_4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000164; CHECK-NEXT: end_block{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000165; CHECK: .LBB3_5:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000166; CHECK-NEXT: end_block{{$}}
Dan Gohmanb6fd39a2016-01-19 16:59:23 +0000167; CHECK: i32.const $push{{[0-9]+}}=, 0{{$}}
168; CHECK-NEXT: return $pop{{[0-9]+}}{{$}}
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000169; OPT-LABEL: doublediamond:
Dan Gohman2726b882016-10-06 22:29:32 +0000170; OPT: block {{$}}
171; OPT-NEXT: block {{$}}
172; OPT-NEXT: block {{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +0000173; OPT: br_if 0, ${{[^,]+}}{{$}}
174; OPT: br_if 1, ${{[^,]+}}{{$}}
175; OPT: br 2{{$}}
176; OPT-NEXT: .LBB3_3:
177; OPT-NEXT: end_block
178; OPT: br 1{{$}}
179; OPT-NEXT: .LBB3_4:
180; OPT: .LBB3_5:
181; OPT-NEXT: end_block
182; OPT: return $pop{{[0-9]+}}{{$}}
Dan Gohman950a13c2015-09-16 16:51:30 +0000183define i32 @doublediamond(i32 %a, i32 %b, i32* %p) {
184entry:
185 %c = icmp eq i32 %a, 0
186 %d = icmp eq i32 %b, 0
187 store volatile i32 0, i32* %p
188 br i1 %c, label %true, label %false
189true:
190 store volatile i32 1, i32* %p
191 br label %exit
192false:
193 store volatile i32 2, i32* %p
194 br i1 %d, label %ft, label %ff
195ft:
196 store volatile i32 3, i32* %p
197 br label %exit
198ff:
199 store volatile i32 4, i32* %p
200 br label %exit
201exit:
202 store volatile i32 5, i32* %p
203 ret i32 0
204}
205
Dan Gohmane51c0582015-10-06 00:27:55 +0000206; CHECK-LABEL: triangle:
Dan Gohman2726b882016-10-06 22:29:32 +0000207; CHECK: block {{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000208; CHECK: br_if 0, $1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000209; CHECK: .LBB4_2:
Dan Gohmanc9623db2016-08-18 17:51:27 +0000210; CHECK: return
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000211; OPT-LABEL: triangle:
Dan Gohman2726b882016-10-06 22:29:32 +0000212; OPT: block {{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000213; OPT: br_if 0, $1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000214; OPT: .LBB4_2:
Dan Gohmanc9623db2016-08-18 17:51:27 +0000215; OPT: return
Dan Gohman950a13c2015-09-16 16:51:30 +0000216define i32 @triangle(i32* %p, i32 %a) {
217entry:
218 %c = icmp eq i32 %a, 0
219 store volatile i32 0, i32* %p
220 br i1 %c, label %true, label %exit
221true:
222 store volatile i32 1, i32* %p
223 br label %exit
224exit:
225 store volatile i32 2, i32* %p
226 ret i32 0
227}
228
Dan Gohmane51c0582015-10-06 00:27:55 +0000229; CHECK-LABEL: diamond:
Dan Gohman2726b882016-10-06 22:29:32 +0000230; CHECK: block {{$}}
231; CHECK: block {{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000232; CHECK: br_if 0, $1{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000233; CHECK: br 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000234; CHECK: .LBB5_2:
235; CHECK: .LBB5_3:
Dan Gohmanb6fd39a2016-01-19 16:59:23 +0000236; CHECK: i32.const $push{{[0-9]+}}=, 0{{$}}
237; CHECK-NEXT: return $pop{{[0-9]+}}{{$}}
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000238; OPT-LABEL: diamond:
Dan Gohman2726b882016-10-06 22:29:32 +0000239; OPT: block {{$}}
240; OPT: block {{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000241; OPT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000242; OPT: br 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000243; OPT: .LBB5_2:
244; OPT: .LBB5_3:
Dan Gohmanb6fd39a2016-01-19 16:59:23 +0000245; OPT: i32.const $push{{[0-9]+}}=, 0{{$}}
246; OPT-NEXT: return $pop{{[0-9]+}}{{$}}
Dan Gohman950a13c2015-09-16 16:51:30 +0000247define i32 @diamond(i32* %p, i32 %a) {
248entry:
249 %c = icmp eq i32 %a, 0
250 store volatile i32 0, i32* %p
251 br i1 %c, label %true, label %false
252true:
253 store volatile i32 1, i32* %p
254 br label %exit
255false:
256 store volatile i32 2, i32* %p
257 br label %exit
258exit:
259 store volatile i32 3, i32* %p
260 ret i32 0
261}
262
Dan Gohmane51c0582015-10-06 00:27:55 +0000263; CHECK-LABEL: single_block:
Dan Gohman950a13c2015-09-16 16:51:30 +0000264; CHECK-NOT: br
Dan Gohman81719f82015-11-25 16:55:01 +0000265; CHECK: return $pop{{[0-9]+}}{{$}}
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000266; OPT-LABEL: single_block:
267; OPT-NOT: br
268; OPT: return $pop{{[0-9]+}}{{$}}
Dan Gohman950a13c2015-09-16 16:51:30 +0000269define i32 @single_block(i32* %p) {
270entry:
271 store volatile i32 0, i32* %p
272 ret i32 0
273}
274
Dan Gohmane51c0582015-10-06 00:27:55 +0000275; CHECK-LABEL: minimal_loop:
Dan Gohman950a13c2015-09-16 16:51:30 +0000276; CHECK-NOT: br
Dan Gohmana4730cf2016-01-07 18:49:53 +0000277; CHECK: .LBB7_1:
Dan Gohman2726b882016-10-06 22:29:32 +0000278; CHECK: loop i32
Dan Gohman7f1bdb22016-10-06 22:08:28 +0000279; CHECK: i32.store 0($0), $pop{{[0-9]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000280; CHECK: br 0{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000281; CHECK: .LBB7_2:
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000282; OPT-LABEL: minimal_loop:
283; OPT-NOT: br
Dan Gohmana4730cf2016-01-07 18:49:53 +0000284; OPT: .LBB7_1:
Dan Gohman2726b882016-10-06 22:29:32 +0000285; OPT: loop i32
Dan Gohman7f1bdb22016-10-06 22:08:28 +0000286; OPT: i32.store 0($0), $pop{{[0-9]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000287; OPT: br 0{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000288; OPT: .LBB7_2:
Dan Gohman2726b882016-10-06 22:29:32 +0000289define i32 @minimal_loop(i32* %p) {
Dan Gohman950a13c2015-09-16 16:51:30 +0000290entry:
291 store volatile i32 0, i32* %p
292 br label %loop
293loop:
294 store volatile i32 1, i32* %p
295 br label %loop
296}
297
Dan Gohmane51c0582015-10-06 00:27:55 +0000298; CHECK-LABEL: simple_loop:
Dan Gohman950a13c2015-09-16 16:51:30 +0000299; CHECK-NOT: br
Dan Gohmana4730cf2016-01-07 18:49:53 +0000300; CHECK: .LBB8_1:
Dan Gohman2726b882016-10-06 22:29:32 +0000301; CHECK: loop {{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000302; CHECK: br_if 0, $pop{{[0-9]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000303; CHECK-NEXT: end_loop{{$}}
Dan Gohmanb6fd39a2016-01-19 16:59:23 +0000304; CHECK: i32.const $push{{[0-9]+}}=, 0{{$}}
305; CHECK-NEXT: return $pop{{[0-9]+}}{{$}}
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000306; OPT-LABEL: simple_loop:
307; OPT-NOT: br
Dan Gohmana4730cf2016-01-07 18:49:53 +0000308; OPT: .LBB8_1:
Dan Gohman2726b882016-10-06 22:29:32 +0000309; OPT: loop {{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000310; OPT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000311; OPT-NEXT: end_loop{{$}}
Dan Gohmanb6fd39a2016-01-19 16:59:23 +0000312; OPT: i32.const $push{{[0-9]+}}=, 0{{$}}
313; OPT-NEXT: return $pop{{[0-9]+}}{{$}}
Dan Gohman950a13c2015-09-16 16:51:30 +0000314define i32 @simple_loop(i32* %p, i32 %a) {
315entry:
316 %c = icmp eq i32 %a, 0
317 store volatile i32 0, i32* %p
318 br label %loop
319loop:
320 store volatile i32 1, i32* %p
321 br i1 %c, label %loop, label %exit
322exit:
323 store volatile i32 2, i32* %p
324 ret i32 0
325}
326
Dan Gohmane51c0582015-10-06 00:27:55 +0000327; CHECK-LABEL: doubletriangle:
Dan Gohman2726b882016-10-06 22:29:32 +0000328; CHECK: block {{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000329; CHECK: br_if 0, $0{{$}}
Dan Gohman2726b882016-10-06 22:29:32 +0000330; CHECK: block {{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000331; CHECK: br_if 0, $1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000332; CHECK: .LBB9_3:
333; CHECK: .LBB9_4:
Dan Gohmanc9623db2016-08-18 17:51:27 +0000334; CHECK: return
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000335; OPT-LABEL: doubletriangle:
Dan Gohman2726b882016-10-06 22:29:32 +0000336; OPT: block {{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000337; OPT: br_if 0, $0{{$}}
Dan Gohman2726b882016-10-06 22:29:32 +0000338; OPT: block {{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000339; OPT: br_if 0, $1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000340; OPT: .LBB9_3:
341; OPT: .LBB9_4:
Dan Gohmanc9623db2016-08-18 17:51:27 +0000342; OPT: return
Dan Gohman950a13c2015-09-16 16:51:30 +0000343define i32 @doubletriangle(i32 %a, i32 %b, i32* %p) {
344entry:
345 %c = icmp eq i32 %a, 0
346 %d = icmp eq i32 %b, 0
347 store volatile i32 0, i32* %p
348 br i1 %c, label %true, label %exit
349true:
350 store volatile i32 2, i32* %p
351 br i1 %d, label %tt, label %tf
352tt:
353 store volatile i32 3, i32* %p
354 br label %tf
355tf:
356 store volatile i32 4, i32* %p
357 br label %exit
358exit:
359 store volatile i32 5, i32* %p
360 ret i32 0
361}
362
Dan Gohmane51c0582015-10-06 00:27:55 +0000363; CHECK-LABEL: ifelse_earlyexits:
Dan Gohman2726b882016-10-06 22:29:32 +0000364; CHECK: block {{$}}
365; CHECK: block {{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000366; CHECK: br_if 0, $0{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000367; CHECK: br 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000368; CHECK: .LBB10_2:
Dan Gohman06b49582016-02-08 21:50:13 +0000369; CHECK: br_if 0, $1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000370; CHECK: .LBB10_4:
Dan Gohmanb6fd39a2016-01-19 16:59:23 +0000371; CHECK: i32.const $push{{[0-9]+}}=, 0{{$}}
372; CHECK-NEXT: return $pop{{[0-9]+}}{{$}}
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000373; OPT-LABEL: ifelse_earlyexits:
Dan Gohman2726b882016-10-06 22:29:32 +0000374; OPT: block {{$}}
375; OPT: block {{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000376; OPT: br_if 0, {{[^,]+}}{{$}}
377; OPT: br_if 1, $1{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000378; OPT: br 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000379; OPT: .LBB10_3:
380; OPT: .LBB10_4:
Dan Gohmanb6fd39a2016-01-19 16:59:23 +0000381; OPT: i32.const $push{{[0-9]+}}=, 0{{$}}
382; OPT-NEXT: return $pop{{[0-9]+}}{{$}}
Dan Gohman950a13c2015-09-16 16:51:30 +0000383define i32 @ifelse_earlyexits(i32 %a, i32 %b, i32* %p) {
384entry:
385 %c = icmp eq i32 %a, 0
386 %d = icmp eq i32 %b, 0
387 store volatile i32 0, i32* %p
388 br i1 %c, label %true, label %false
389true:
390 store volatile i32 1, i32* %p
391 br label %exit
392false:
393 store volatile i32 2, i32* %p
394 br i1 %d, label %ft, label %exit
395ft:
396 store volatile i32 3, i32* %p
397 br label %exit
398exit:
399 store volatile i32 4, i32* %p
400 ret i32 0
401}
Dan Gohmane3e4a5f2015-10-02 21:11:36 +0000402
Dan Gohman32807932015-11-23 16:19:56 +0000403; CHECK-LABEL: doublediamond_in_a_loop:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000404; CHECK: .LBB11_1:
Dan Gohman2726b882016-10-06 22:29:32 +0000405; CHECK: loop i32{{$}}
406; CHECK: block {{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000407; CHECK: br_if 0, $0{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000408; CHECK: br 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000409; CHECK: .LBB11_3:
Dan Gohman0cfb5f82016-05-10 04:24:02 +0000410; CHECK: end_block{{$}}
Dan Gohman2726b882016-10-06 22:29:32 +0000411; CHECK: block {{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000412; CHECK: br_if 0, $1{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000413; CHECK: br 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000414; CHECK: .LBB11_5:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000415; CHECK: br 0{{$}}
Dan Gohman0cfb5f82016-05-10 04:24:02 +0000416; CHECK: .LBB11_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000417; CHECK-NEXT: end_loop{{$}}
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000418; OPT-LABEL: doublediamond_in_a_loop:
Dan Gohman442bfce2016-02-16 16:22:41 +0000419; OPT: .LBB11_1:
Dan Gohman2726b882016-10-06 22:29:32 +0000420; OPT: loop i32{{$}}
421; OPT: block {{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +0000422; OPT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman2726b882016-10-06 22:29:32 +0000423; OPT: block {{$}}
Dan Gohman0cfb5f82016-05-10 04:24:02 +0000424; OPT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +0000425; OPT: br 2{{$}}
426; OPT-NEXT: .LBB11_4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000427; OPT-NEXT: end_block{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +0000428; OPT: br 1{{$}}
429; OPT: .LBB11_5:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000430; OPT-NEXT: end_block{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +0000431; OPT: br 0{{$}}
Dan Gohman0cfb5f82016-05-10 04:24:02 +0000432; OPT: .LBB11_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000433; OPT-NEXT: end_loop{{$}}
Dan Gohman2726b882016-10-06 22:29:32 +0000434define i32 @doublediamond_in_a_loop(i32 %a, i32 %b, i32* %p) {
Dan Gohman32807932015-11-23 16:19:56 +0000435entry:
436 br label %header
437header:
438 %c = icmp eq i32 %a, 0
439 %d = icmp eq i32 %b, 0
440 store volatile i32 0, i32* %p
441 br i1 %c, label %true, label %false
442true:
443 store volatile i32 1, i32* %p
444 br label %exit
445false:
446 store volatile i32 2, i32* %p
447 br i1 %d, label %ft, label %ff
448ft:
449 store volatile i32 3, i32* %p
450 br label %exit
451ff:
452 store volatile i32 4, i32* %p
453 br label %exit
454exit:
455 store volatile i32 5, i32* %p
456 br label %header
457}
458
Dan Gohmane3e4a5f2015-10-02 21:11:36 +0000459; Test that nested loops are handled.
460
Dan Gohman8fe7e862015-12-14 22:51:54 +0000461; CHECK-LABEL: test3:
462; CHECK: loop
463; CHECK-NEXT: br_if
Dan Gohmana4730cf2016-01-07 18:49:53 +0000464; CHECK-NEXT: .LBB{{[0-9]+}}_{{[0-9]+}}:
Dan Gohman8fe7e862015-12-14 22:51:54 +0000465; CHECK-NEXT: loop
466; OPT-LABEL: test3:
Dan Gohman442bfce2016-02-16 16:22:41 +0000467; OPT: block
468; OPT: br_if
Dan Gohmand85ab7f2016-02-18 06:32:53 +0000469; OPT: .LBB{{[0-9]+}}_{{[0-9]+}}:
Dan Gohman442bfce2016-02-16 16:22:41 +0000470; OPT-NEXT: loop
471; OPT-NEXT: block
472; OPT-NEXT: block
Dan Gohman8fe7e862015-12-14 22:51:54 +0000473; OPT-NEXT: br_if
Dan Gohmana4730cf2016-01-07 18:49:53 +0000474; OPT-NEXT: .LBB{{[0-9]+}}_{{[0-9]+}}:
Dan Gohman8fe7e862015-12-14 22:51:54 +0000475; OPT-NEXT: loop
Dan Gohman442bfce2016-02-16 16:22:41 +0000476; OPT: br_if
477; OPT-NEXT: br
478; OPT-NEXT: .LBB{{[0-9]+}}_{{[0-9]+}}:
479; OPT-NEXT: end_loop
480; OPT-NEXT: end_block
481; OPT-NEXT: unreachable
482; OPT-NEXT: .LBB{{[0-9]+}}_{{[0-9]+}}:
483; OPT-NEXT: end_block
484; OPT: br
485; OPT-NEXT: .LBB{{[0-9]+}}_{{[0-9]+}}:
486; OPT-NEXT: end_loop
Dan Gohmane3e4a5f2015-10-02 21:11:36 +0000487declare void @bar()
Dan Gohmane3e4a5f2015-10-02 21:11:36 +0000488define void @test3(i32 %w) {
489entry:
490 br i1 undef, label %outer.ph, label %exit
491
492outer.ph:
493 br label %outer
494
495outer:
496 %tobool = icmp eq i32 undef, 0
497 br i1 %tobool, label %inner, label %unreachable
498
499unreachable:
500 unreachable
501
502inner:
503 %c = icmp eq i32 undef, %w
504 br i1 %c, label %if.end, label %inner
505
506exit:
507 ret void
508
509if.end:
510 call void @bar()
511 br label %outer
512}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000513
514; Test switch lowering and block placement.
515
516; CHECK-LABEL: test4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000517; CHECK-NEXT: .param i32{{$}}
Dan Gohman2726b882016-10-06 22:29:32 +0000518; CHECK: block {{$}}
519; CHECK-NEXT: block {{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000520; CHECK: br_if 0, $pop{{[0-9]+}}{{$}}
Dan Gohmand85ab7f2016-02-18 06:32:53 +0000521; CHECK: br_if 1, $pop{{[0-9]+}}{{$}}
522; CHECK: br 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000523; CHECK-NEXT: .LBB13_3:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000524; CHECK-NEXT: end_block{{$}}
Dan Gohman2726b882016-10-06 22:29:32 +0000525; CHECK-NEXT: block {{$}}
Dan Gohmand85ab7f2016-02-18 06:32:53 +0000526; CHECK: br_if 0, $pop{{[0-9]+}}{{$}}
527; CHECK: br_if 1, $pop{{[0-9]+}}{{$}}
528; CHECK-NEXT: .LBB13_5:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000529; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000530; CHECK-NEXT: return{{$}}
Dan Gohmand85ab7f2016-02-18 06:32:53 +0000531; CHECK-NEXT: .LBB13_6:
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{{$}}
Dan Gohman2726b882016-10-06 22:29:32 +0000536; OPT: block {{$}}
537; OPT-NEXT: block {{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000538; OPT: br_if 0, $pop{{[0-9]+}}{{$}}
Dan Gohmand85ab7f2016-02-18 06:32:53 +0000539; OPT: br_if 1, $pop{{[0-9]+}}{{$}}
540; OPT: br 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000541; OPT-NEXT: .LBB13_3:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000542; OPT-NEXT: end_block{{$}}
Dan Gohman2726b882016-10-06 22:29:32 +0000543; OPT-NEXT: block {{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000544; OPT: br_if 0, $pop{{[0-9]+}}{{$}}
Dan Gohmand85ab7f2016-02-18 06:32:53 +0000545; OPT: br_if 1, $pop{{[0-9]+}}{{$}}
546; OPT-NEXT: .LBB13_5:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000547; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000548; OPT-NEXT: return{{$}}
Dan Gohmand85ab7f2016-02-18 06:32:53 +0000549; OPT-NEXT: .LBB13_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000550; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000551; OPT-NEXT: return{{$}}
552define void @test4(i32 %t) {
553entry:
554 switch i32 %t, label %default [
555 i32 0, label %bb2
556 i32 2, label %bb2
557 i32 4, label %bb1
558 i32 622, label %bb0
559 ]
560
561bb0:
562 ret void
563
564bb1:
565 ret void
566
567bb2:
568 ret void
569
570default:
571 ret void
572}
573
574; Test a case where the BLOCK needs to be placed before the LOOP in the
575; same basic block.
576
577; CHECK-LABEL: test5:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000578; CHECK: .LBB14_1:
Dan Gohman2726b882016-10-06 22:29:32 +0000579; CHECK-NEXT: block {{$}}
580; CHECK-NEXT: loop {{$}}
Dan Gohman3a643e82016-10-06 22:10:23 +0000581; CHECK: br_if 1, {{[^,]+}}{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000582; CHECK: br_if 0, {{[^,]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000583; CHECK-NEXT: end_loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000584; CHECK: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000585; CHECK-NEXT: .LBB14_4:
Dan Gohman8fe7e862015-12-14 22:51:54 +0000586; CHECK: return{{$}}
587; OPT-LABEL: test5:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000588; OPT: .LBB14_1:
Dan Gohman2726b882016-10-06 22:29:32 +0000589; OPT-NEXT: block {{$}}
590; OPT-NEXT: loop {{$}}
Dan Gohman3a643e82016-10-06 22:10:23 +0000591; OPT: br_if 1, {{[^,]+}}{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000592; OPT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000593; OPT-NEXT: end_loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000594; OPT: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000595; OPT-NEXT: .LBB14_4:
Dan Gohman8fe7e862015-12-14 22:51:54 +0000596; OPT: return{{$}}
597define void @test5(i1 %p, i1 %q) {
598entry:
599 br label %header
600
601header:
602 store volatile i32 0, i32* null
603 br i1 %p, label %more, label %alt
604
605more:
606 store volatile i32 1, i32* null
607 br i1 %q, label %header, label %return
608
609alt:
610 store volatile i32 2, i32* null
611 ret void
612
613return:
614 store volatile i32 3, i32* null
615 ret void
616}
617
618; Test an interesting case of a loop with multiple exits, which
619; aren't to layout successors of the loop, and one of which is to a successors
620; which has another predecessor.
621
622; CHECK-LABEL: test6:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000623; CHECK: .LBB15_1:
Dan Gohman2726b882016-10-06 22:29:32 +0000624; CHECK-NEXT: block {{$}}
625; CHECK-NEXT: block {{$}}
626; CHECK-NEXT: loop {{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000627; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000628; CHECK: br_if 2, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000629; CHECK-NOT: block
Dan Gohman3a643e82016-10-06 22:10:23 +0000630; CHECK: br_if 1, {{[^,]+}}{{$}}
631; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000632; CHECK: br_if 0, {{[^,]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000633; CHECK-NEXT: end_loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000634; CHECK-NOT: block
635; CHECK: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000636; CHECK-NEXT: .LBB15_5:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000637; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000638; CHECK-NOT: block
Dan Gohmana4730cf2016-01-07 18:49:53 +0000639; CHECK: .LBB15_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000640; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000641; CHECK-NOT: block
642; CHECK: return{{$}}
643; OPT-LABEL: test6:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000644; OPT: .LBB15_1:
Dan Gohman2726b882016-10-06 22:29:32 +0000645; OPT-NEXT: block {{$}}
646; OPT-NEXT: block {{$}}
647; OPT-NEXT: loop {{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000648; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000649; OPT: br_if 2, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000650; OPT-NOT: block
Dan Gohman3a643e82016-10-06 22:10:23 +0000651; OPT: br_if 1, {{[^,]+}}{{$}}
652; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000653; OPT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000654; OPT-NEXT: end_loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000655; OPT-NOT: block
656; OPT: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000657; OPT-NEXT: .LBB15_5:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000658; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000659; OPT-NOT: block
Dan Gohmana4730cf2016-01-07 18:49:53 +0000660; OPT: .LBB15_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000661; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000662; OPT-NOT: block
663; OPT: return{{$}}
664define void @test6(i1 %p, i1 %q) {
665entry:
666 br label %header
667
668header:
669 store volatile i32 0, i32* null
670 br i1 %p, label %more, label %second
671
672more:
673 store volatile i32 1, i32* null
674 br i1 %q, label %evenmore, label %first
675
676evenmore:
677 store volatile i32 1, i32* null
678 br i1 %q, label %header, label %return
679
680return:
681 store volatile i32 2, i32* null
682 ret void
683
684first:
685 store volatile i32 3, i32* null
686 br label %second
687
688second:
689 store volatile i32 4, i32* null
690 ret void
691}
692
693; Test a case where there are multiple backedges and multiple loop exits
694; that end in unreachable.
695
696; CHECK-LABEL: test7:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000697; CHECK: .LBB16_1:
Dan Gohman2726b882016-10-06 22:29:32 +0000698; CHECK-NEXT: loop {{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000699; CHECK-NOT: block
Dan Gohman2726b882016-10-06 22:29:32 +0000700; CHECK: block {{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000701; CHECK: br_if 0, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000702; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000703; CHECK: br_if 1, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000704; CHECK-NOT: block
705; CHECK: unreachable
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000706; CHECK-NEXT: .LBB16_4:
707; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000708; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000709; CHECK: br_if 0, {{[^,]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000710; CHECK-NEXT: end_loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000711; CHECK-NOT: block
712; CHECK: unreachable
713; OPT-LABEL: test7:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000714; OPT: .LBB16_1:
Dan Gohman442bfce2016-02-16 16:22:41 +0000715; OPT-NEXT: block
Dan Gohman2726b882016-10-06 22:29:32 +0000716; OPT-NEXT: loop {{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000717; OPT-NOT: block
Dan Gohman2726b882016-10-06 22:29:32 +0000718; OPT: block {{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000719; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000720; OPT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000721; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000722; OPT: br_if 1, {{[^,]+}}{{$}}
Dan Gohman3a643e82016-10-06 22:10:23 +0000723; OPT: br 2{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +0000724; OPT-NEXT: .LBB16_3:
725; OPT-NEXT: end_block
Dan Gohman8fe7e862015-12-14 22:51:54 +0000726; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000727; OPT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +0000728; OPT-NEXT: end_loop
729; OPT-NOT: block
730; OPT: unreachable
731; OPT-NEXT: .LBB16_5:
732; OPT-NEXT: end_block
Dan Gohman8fe7e862015-12-14 22:51:54 +0000733; OPT-NOT: block
734; OPT: unreachable
735define void @test7(i1 %tobool2, i1 %tobool9) {
736entry:
737 store volatile i32 0, i32* null
738 br label %loop
739
740loop:
741 store volatile i32 1, i32* null
742 br i1 %tobool2, label %l1, label %l0
743
744l0:
745 store volatile i32 2, i32* null
746 br i1 %tobool9, label %loop, label %u0
747
748l1:
749 store volatile i32 3, i32* null
750 br i1 %tobool9, label %loop, label %u1
751
752u0:
753 store volatile i32 4, i32* null
754 unreachable
755
756u1:
757 store volatile i32 5, i32* null
758 unreachable
759}
760
761; Test an interesting case using nested loops and switches.
762
763; CHECK-LABEL: test8:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000764; CHECK: .LBB17_1:
Dan Gohman2726b882016-10-06 22:29:32 +0000765; CHECK-NEXT: loop i32{{$}}
Dan Gohmane5d3c152016-01-20 05:55:09 +0000766; CHECK-NEXT: i32.const $push{{[^,]+}}, 0{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000767; CHECK-NEXT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman0cfb5f82016-05-10 04:24:02 +0000768; CHECK-NEXT: br 0{{$}}
769; CHECK-NEXT: .LBB17_2:
770; CHECK-NEXT: end_loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000771; OPT-LABEL: test8:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000772; OPT: .LBB17_1:
Dan Gohman2726b882016-10-06 22:29:32 +0000773; OPT-NEXT: loop i32{{$}}
Dan Gohmane5d3c152016-01-20 05:55:09 +0000774; OPT-NEXT: i32.const $push{{[^,]+}}, 0{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000775; OPT-NEXT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman0cfb5f82016-05-10 04:24:02 +0000776; OPT-NEXT: br 0{{$}}
777; OPT-NEXT: .LBB17_2:
778; OPT-NEXT: end_loop{{$}}
Dan Gohman2726b882016-10-06 22:29:32 +0000779define i32 @test8() {
Dan Gohman8fe7e862015-12-14 22:51:54 +0000780bb:
781 br label %bb1
782
783bb1:
784 br i1 undef, label %bb2, label %bb3
785
786bb2:
787 switch i8 undef, label %bb1 [
788 i8 44, label %bb2
789 ]
790
791bb3:
792 switch i8 undef, label %bb1 [
793 i8 44, label %bb2
794 ]
795}
796
797; Test an interesting case using nested loops that share a bottom block.
798
799; CHECK-LABEL: test9:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000800; CHECK: .LBB18_1:
Dan Gohman2726b882016-10-06 22:29:32 +0000801; CHECK-NEXT: block {{$}}
802; CHECK-NEXT: loop {{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000803; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000804; CHECK: br_if 1, {{[^,]+}}{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000805; CHECK-NEXT: .LBB18_2:
Dan Gohman2726b882016-10-06 22:29:32 +0000806; CHECK-NEXT: loop {{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000807; CHECK-NOT: block
Dan Gohman2726b882016-10-06 22:29:32 +0000808; CHECK: block {{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000809; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000810; CHECK: br_if 0, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000811; CHECK-NOT: block
Dan Gohman3a643e82016-10-06 22:10:23 +0000812; CHECK: br_if 2, {{[^,]+}}{{$}}
Dan Gohmand85ab7f2016-02-18 06:32:53 +0000813; CHECK-NEXT: br 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000814; CHECK-NEXT: .LBB18_4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000815; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000816; CHECK-NOT: block
Dan Gohman3a643e82016-10-06 22:10:23 +0000817; CHECK: br_if 1, {{[^,]+}}{{$}}
Dan Gohmand85ab7f2016-02-18 06:32:53 +0000818; CHECK-NEXT: br 0{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000819; CHECK-NEXT: .LBB18_5:
Dan Gohman8fe7e862015-12-14 22:51:54 +0000820; CHECK-NOT: block
Dan Gohman3a643e82016-10-06 22:10:23 +0000821; CHECK: end_block
822; CHECK-NOT: block
Dan Gohman8fe7e862015-12-14 22:51:54 +0000823; CHECK: return{{$}}
824; OPT-LABEL: test9:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000825; OPT: .LBB18_1:
Dan Gohman2726b882016-10-06 22:29:32 +0000826; OPT-NEXT: block {{$}}
827; OPT-NEXT: loop {{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000828; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000829; OPT: br_if 1, {{[^,]+}}{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000830; OPT-NEXT: .LBB18_2:
Dan Gohman2726b882016-10-06 22:29:32 +0000831; OPT-NEXT: loop {{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000832; OPT-NOT: block
Dan Gohman2726b882016-10-06 22:29:32 +0000833; OPT: block {{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000834; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000835; OPT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000836; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000837; OPT: br_if 1, {{[^,]+}}{{$}}
Dan Gohman3a643e82016-10-06 22:10:23 +0000838; OPT-NEXT: br 2{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000839; OPT-NEXT: .LBB18_4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000840; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000841; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000842; OPT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman3a643e82016-10-06 22:10:23 +0000843; OPT-NEXT: br 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000844; OPT-NEXT: .LBB18_5:
Dan Gohman8fe7e862015-12-14 22:51:54 +0000845; OPT-NOT: block
Dan Gohman3a643e82016-10-06 22:10:23 +0000846; OPT: end_block
847; OPT-NOT: block
Dan Gohman8fe7e862015-12-14 22:51:54 +0000848; OPT: return{{$}}
849declare i1 @a()
850define void @test9() {
851entry:
852 store volatile i32 0, i32* null
853 br label %header
854
855header:
856 store volatile i32 1, i32* null
857 %call4 = call i1 @a()
858 br i1 %call4, label %header2, label %end
859
860header2:
861 store volatile i32 2, i32* null
862 %call = call i1 @a()
863 br i1 %call, label %if.then, label %if.else
864
865if.then:
866 store volatile i32 3, i32* null
867 %call3 = call i1 @a()
868 br i1 %call3, label %header2, label %header
869
870if.else:
871 store volatile i32 4, i32* null
872 %call2 = call i1 @a()
873 br i1 %call2, label %header2, label %header
874
875end:
876 store volatile i32 5, i32* null
877 ret void
878}
879
880; Test an interesting case involving nested loops sharing a loop bottom,
881; and loop exits to a block with unreachable.
882
883; CHECK-LABEL: test10:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000884; CHECK: .LBB19_1:
Dan Gohman2726b882016-10-06 22:29:32 +0000885; CHECK-NEXT: loop {{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000886; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000887; CHECK: br_if 0, {{[^,]+}}{{$}}
JF Bastienc6ba5ea2016-04-05 17:01:52 +0000888; CHECK: .LBB19_3:
Dan Gohman2726b882016-10-06 22:29:32 +0000889; CHECK-NEXT: block {{$}}
890; CHECK-NEXT: loop {{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000891; CHECK-NOT: block
JF Bastienc6ba5ea2016-04-05 17:01:52 +0000892; CHECK: .LBB19_4:
Dan Gohman2726b882016-10-06 22:29:32 +0000893; CHECK-NEXT: loop {{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000894; CHECK-NOT: block
Dan Gohman3a643e82016-10-06 22:10:23 +0000895; CHECK: br_if 3, {{[^,]+}}{{$}}
Dan Gohman2726b882016-10-06 22:29:32 +0000896; CHECK: block {{$}}
Dan Gohman3a643e82016-10-06 22:10:23 +0000897; CHECK: br_table {{[^,]+}}, 1, 0, 4, 2, 3, 1{{$}}
JF Bastienc6ba5ea2016-04-05 17:01:52 +0000898; CHECK-NEXT: .LBB19_6:
Dan Gohman3a643e82016-10-06 22:10:23 +0000899; CHECK-NEXT: end_block{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000900; CHECK-NEXT: end_loop{{$}}
901; CHECK-NEXT: end_loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000902; CHECK-NEXT: return{{$}}
JF Bastienc6ba5ea2016-04-05 17:01:52 +0000903; CHECK-NEXT: .LBB19_7:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000904; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000905; CHECK-NOT: block
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000906; CHECK: br 0{{$}}
JF Bastienc6ba5ea2016-04-05 17:01:52 +0000907; CHECK-NEXT: .LBB19_8:
Dan Gohman8fe7e862015-12-14 22:51:54 +0000908; OPT-LABEL: test10:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000909; OPT: .LBB19_1:
Dan Gohman2726b882016-10-06 22:29:32 +0000910; OPT-NEXT: loop {{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000911; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000912; OPT: br_if 0, {{[^,]+}}{{$}}
JF Bastienc6ba5ea2016-04-05 17:01:52 +0000913; OPT: .LBB19_3:
Dan Gohman2726b882016-10-06 22:29:32 +0000914; OPT-NEXT: block {{$}}
915; OPT-NEXT: loop {{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000916; OPT-NOT: block
JF Bastienc6ba5ea2016-04-05 17:01:52 +0000917; OPT: .LBB19_4:
Dan Gohman2726b882016-10-06 22:29:32 +0000918; OPT-NEXT: loop {{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000919; OPT-NOT: block
Dan Gohman3a643e82016-10-06 22:10:23 +0000920; OPT: br_if 3, {{[^,]+}}{{$}}
921; OPT: block
922; OPT: br_table {{[^,]+}}, 1, 0, 4, 2, 3, 1{{$}}
JF Bastienc6ba5ea2016-04-05 17:01:52 +0000923; OPT-NEXT: .LBB19_6:
Dan Gohman3a643e82016-10-06 22:10:23 +0000924; OPT-NEXT: end_block{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000925; OPT-NEXT: end_loop{{$}}
926; OPT-NEXT: end_loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000927; OPT-NEXT: return{{$}}
JF Bastienc6ba5ea2016-04-05 17:01:52 +0000928; OPT-NEXT: .LBB19_7:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000929; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000930; OPT-NOT: block
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000931; OPT: br 0{{$}}
JF Bastienc6ba5ea2016-04-05 17:01:52 +0000932; OPT-NEXT: .LBB19_8:
Dan Gohman8fe7e862015-12-14 22:51:54 +0000933define void @test10() {
934bb0:
935 br label %bb1
936
937bb1:
938 %tmp = phi i32 [ 2, %bb0 ], [ 3, %bb3 ]
939 %tmp3 = phi i32 [ undef, %bb0 ], [ %tmp11, %bb3 ]
940 %tmp4 = icmp eq i32 %tmp3, 0
941 br i1 %tmp4, label %bb4, label %bb2
942
943bb2:
944 br label %bb3
945
946bb3:
947 %tmp11 = phi i32 [ 1, %bb5 ], [ 0, %bb2 ]
948 br label %bb1
949
950bb4:
951 %tmp6 = phi i32 [ %tmp9, %bb5 ], [ 4, %bb1 ]
952 %tmp7 = phi i32 [ %tmp6, %bb5 ], [ %tmp, %bb1 ]
953 br label %bb5
954
955bb5:
956 %tmp9 = phi i32 [ %tmp6, %bb5 ], [ %tmp7, %bb4 ]
957 switch i32 %tmp9, label %bb2 [
958 i32 0, label %bb5
959 i32 1, label %bb6
960 i32 3, label %bb4
961 i32 4, label %bb3
962 ]
963
964bb6:
965 ret void
966}
967
968; Test a CFG DAG with interesting merging.
969
970; CHECK-LABEL: test11:
Dan Gohman2726b882016-10-06 22:29:32 +0000971; CHECK: block {{$}}
972; CHECK-NEXT: block {{$}}
973; CHECK-NEXT: block {{$}}
974; CHECK-NEXT: block {{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000975; CHECK: br_if 0, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000976; CHECK-NOT: block
Dan Gohman2726b882016-10-06 22:29:32 +0000977; CHECK: block {{$}}
Dan Gohmanc9623db2016-08-18 17:51:27 +0000978; CHECK-NEXT: i32.const
Dan Gohman06b49582016-02-08 21:50:13 +0000979; CHECK-NEXT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000980; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000981; CHECK: br_if 2, {{[^,]+}}{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000982; CHECK-NEXT: .LBB20_3:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000983; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000984; CHECK-NOT: block
985; CHECK: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000986; CHECK-NEXT: .LBB20_4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000987; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000988; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000989; CHECK: br_if 1, {{[^,]+}}{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +0000990; CHECK-NOT: block
991; CHECK: br_if 2, {{[^,]+}}{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000992; CHECK-NEXT: .LBB20_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000993; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000994; CHECK-NOT: block
995; CHECK: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000996; CHECK-NEXT: .LBB20_7:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000997; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000998; CHECK-NOT: block
999; CHECK: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +00001000; CHECK-NEXT: .LBB20_8:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001001; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001002; CHECK-NOT: block
1003; CHECK: return{{$}}
1004; OPT-LABEL: test11:
Dan Gohman2726b882016-10-06 22:29:32 +00001005; OPT: block {{$}}
1006; OPT-NEXT: block {{$}}
Dan Gohman06b49582016-02-08 21:50:13 +00001007; OPT: br_if 0, $pop{{[0-9]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001008; OPT-NOT: block
Dan Gohman2726b882016-10-06 22:29:32 +00001009; OPT: block {{$}}
Dan Gohmanc9623db2016-08-18 17:51:27 +00001010; OPT-NEXT: i32.const
1011; OPT-NEXT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001012; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +00001013; OPT: br_if 2, {{[^,]+}}{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +00001014; OPT-NEXT: .LBB20_3:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001015; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001016; OPT-NOT: block
1017; OPT: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +00001018; OPT-NEXT: .LBB20_4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001019; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001020; OPT-NOT: block
Dan Gohman2726b882016-10-06 22:29:32 +00001021; OPT: block {{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001022; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +00001023; OPT: br_if 0, $pop{{[0-9]+}}{{$}}
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_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001027; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001028; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +00001029; OPT: br_if 0, $pop{{[0-9]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001030; OPT-NOT: block
1031; OPT: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +00001032; OPT-NEXT: .LBB20_8:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001033; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001034; OPT-NOT: block
1035; OPT: return{{$}}
1036define void @test11() {
1037bb0:
1038 store volatile i32 0, i32* null
1039 br i1 undef, label %bb1, label %bb4
1040bb1:
1041 store volatile i32 1, i32* null
1042 br i1 undef, label %bb3, label %bb2
1043bb2:
1044 store volatile i32 2, i32* null
1045 br i1 undef, label %bb3, label %bb7
1046bb3:
1047 store volatile i32 3, i32* null
1048 ret void
1049bb4:
1050 store volatile i32 4, i32* null
1051 br i1 undef, label %bb8, label %bb5
1052bb5:
1053 store volatile i32 5, i32* null
1054 br i1 undef, label %bb6, label %bb7
1055bb6:
1056 store volatile i32 6, i32* null
1057 ret void
1058bb7:
1059 store volatile i32 7, i32* null
1060 ret void
1061bb8:
1062 store volatile i32 8, i32* null
1063 ret void
1064}
1065
1066; CHECK-LABEL: test12:
Dan Gohmana4730cf2016-01-07 18:49:53 +00001067; CHECK: .LBB21_1:
Dan Gohman2726b882016-10-06 22:29:32 +00001068; CHECK-NEXT: block {{$}}
1069; CHECK-NEXT: loop {{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001070; CHECK-NOT: block
Dan Gohman2726b882016-10-06 22:29:32 +00001071; CHECK: block {{$}}
1072; CHECK-NEXT: block {{$}}
Dan Gohman06b49582016-02-08 21:50:13 +00001073; CHECK: br_if 0, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001074; CHECK-NOT: block
Dan Gohman442bfce2016-02-16 16:22:41 +00001075; CHECK: br_if 1, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001076; CHECK-NOT: block
Dan Gohman442bfce2016-02-16 16:22:41 +00001077; CHECK: br_if 1, {{[^,]+}}{{$}}
1078; CHECK-NEXT: br 3{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +00001079; CHECK-NEXT: .LBB21_4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001080; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001081; CHECK-NOT: block
Dan Gohman442bfce2016-02-16 16:22:41 +00001082; CHECK: br_if 0, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001083; CHECK-NOT: block
Dan Gohman442bfce2016-02-16 16:22:41 +00001084; CHECK: br_if 2, {{[^,]+}}{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +00001085; CHECK-NEXT: .LBB21_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001086; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001087; CHECK-NOT: block
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001088; CHECK: br 0{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +00001089; CHECK-NEXT: .LBB21_7:
1090; CHECK-NEXT: end_loop{{$}}
Dan Gohman3a643e82016-10-06 22:10:23 +00001091; CHECK-NEXT: end_block{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +00001092; CHECK-NEXT: return{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001093; OPT-LABEL: test12:
Dan Gohmana4730cf2016-01-07 18:49:53 +00001094; OPT: .LBB21_1:
Dan Gohman2726b882016-10-06 22:29:32 +00001095; OPT-NEXT: block {{$}}
1096; OPT-NEXT: loop {{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001097; OPT-NOT: block
Dan Gohman2726b882016-10-06 22:29:32 +00001098; OPT: block {{$}}
1099; OPT-NEXT: block {{$}}
Dan Gohman06b49582016-02-08 21:50:13 +00001100; OPT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001101; OPT-NOT: block
Dan Gohman442bfce2016-02-16 16:22:41 +00001102; OPT: br_if 1, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001103; OPT-NOT: block
Dan Gohman442bfce2016-02-16 16:22:41 +00001104; OPT: br_if 1, {{[^,]+}}{{$}}
1105; OPT-NEXT: br 3{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +00001106; OPT-NEXT: .LBB21_4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001107; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001108; OPT-NOT: block
Dan Gohman442bfce2016-02-16 16:22:41 +00001109; OPT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001110; OPT-NOT: block
Dan Gohman442bfce2016-02-16 16:22:41 +00001111; OPT: br_if 2, {{[^,]+}}{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +00001112; OPT-NEXT: .LBB21_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001113; OPT-NEXT: end_block{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001114; OPT: br 0{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +00001115; OPT-NEXT: .LBB21_7:
1116; OPT-NEXT: end_loop{{$}}
Dan Gohman3a643e82016-10-06 22:10:23 +00001117; OPT-NEXT: end_block{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +00001118; OPT-NEXT: return{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001119define void @test12(i8* %arg) {
1120bb:
1121 br label %bb1
1122
1123bb1:
1124 %tmp = phi i32 [ 0, %bb ], [ %tmp5, %bb4 ]
1125 %tmp2 = getelementptr i8, i8* %arg, i32 %tmp
1126 %tmp3 = load i8, i8* %tmp2
1127 switch i8 %tmp3, label %bb7 [
1128 i8 42, label %bb4
1129 i8 76, label %bb4
1130 i8 108, label %bb4
1131 i8 104, label %bb4
1132 ]
1133
1134bb4:
1135 %tmp5 = add i32 %tmp, 1
1136 br label %bb1
1137
1138bb7:
1139 ret void
1140}
Dan Gohmanb3aa1ec2015-12-16 19:06:41 +00001141
1142; A block can be "branched to" from another even if it is also reachable via
1143; fallthrough from the other. This would normally be optimized away, so use
1144; optnone to disable optimizations to test this case.
1145
1146; CHECK-LABEL: test13:
Dan Gohmanb6fd39a2016-01-19 16:59:23 +00001147; CHECK-NEXT: .local i32{{$}}
Dan Gohman2726b882016-10-06 22:29:32 +00001148; CHECK-NEXT: block {{$}}
1149; CHECK-NEXT: block {{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +00001150; CHECK: br_if 0, $pop0{{$}}
Dan Gohman2726b882016-10-06 22:29:32 +00001151; CHECK: block {{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +00001152; CHECK: br_if 0, $pop3{{$}}
1153; CHECK: .LBB22_3:
1154; CHECK-NEXT: end_block{{$}}
1155; CHECK: br_if 1, $pop{{[0-9]+}}{{$}}
1156; CHECK-NEXT: br 1{{$}}
1157; CHECK-NEXT: .LBB22_4:
1158; CHECK-NEXT: end_block{{$}}
Dan Gohmanb3aa1ec2015-12-16 19:06:41 +00001159; CHECK-NEXT: return{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +00001160; CHECK-NEXT: .LBB22_5:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001161; CHECK-NEXT: end_block{{$}}
Dan Gohmanb3aa1ec2015-12-16 19:06:41 +00001162; CHECK-NEXT: unreachable{{$}}
1163; OPT-LABEL: test13:
Dan Gohmanb6fd39a2016-01-19 16:59:23 +00001164; OPT-NEXT: .local i32{{$}}
Dan Gohman2726b882016-10-06 22:29:32 +00001165; OPT-NEXT: block {{$}}
1166; OPT-NEXT: block {{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +00001167; OPT: br_if 0, $pop0{{$}}
Dan Gohman2726b882016-10-06 22:29:32 +00001168; OPT: block {{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +00001169; OPT: br_if 0, $pop3{{$}}
1170; OPT: .LBB22_3:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001171; OPT-NEXT: end_block{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +00001172; OPT: br_if 1, $pop{{[0-9]+}}{{$}}
1173; OPT-NEXT: br 1{{$}}
1174; OPT-NEXT: .LBB22_4:
1175; OPT-NEXT: end_block
1176; OPT-NEXT: return
1177; OPT-NEXT: .LBB22_5:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001178; OPT-NEXT: end_block{{$}}
Dan Gohmanb3aa1ec2015-12-16 19:06:41 +00001179; OPT-NEXT: unreachable{{$}}
1180define void @test13() noinline optnone {
1181bb:
1182 br i1 undef, label %bb5, label %bb2
1183bb1:
1184 unreachable
1185bb2:
1186 br i1 undef, label %bb3, label %bb4
1187bb3:
1188 br label %bb4
1189bb4:
1190 %tmp = phi i1 [ false, %bb2 ], [ false, %bb3 ]
1191 br i1 %tmp, label %bb1, label %bb1
1192bb5:
1193 ret void
1194}
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001195
1196; Test a case with a single-block loop that has another loop
1197; as a successor. The end_loop for the first loop should go
1198; before the loop for the second.
1199
1200; CHECK-LABEL: test14:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001201; CHECK-NEXT: .LBB23_1:{{$}}
Dan Gohman2726b882016-10-06 22:29:32 +00001202; CHECK-NEXT: loop {{$}}
Dan Gohmanb6fd39a2016-01-19 16:59:23 +00001203; CHECK-NEXT: i32.const $push0=, 0{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +00001204; CHECK-NEXT: br_if 0, $pop0{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001205; CHECK-NEXT: end_loop{{$}}
Dan Gohman0cfb5f82016-05-10 04:24:02 +00001206; CHECK-NEXT: .LBB23_3:{{$}}
Dan Gohman2726b882016-10-06 22:29:32 +00001207; CHECK-NEXT: loop {{$}}
Dan Gohmanb6fd39a2016-01-19 16:59:23 +00001208; CHECK-NEXT: i32.const $push1=, 0{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +00001209; CHECK-NEXT: br_if 0, $pop1{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001210; CHECK-NEXT: end_loop{{$}}
1211; CHECK-NEXT: return{{$}}
1212define void @test14() {
1213bb:
1214 br label %bb1
1215
1216bb1:
1217 %tmp = bitcast i1 undef to i1
1218 br i1 %tmp, label %bb3, label %bb1
1219
1220bb3:
1221 br label %bb4
1222
1223bb4:
1224 br i1 undef, label %bb7, label %bb48
1225
1226bb7:
1227 br i1 undef, label %bb12, label %bb12
1228
1229bb12:
1230 br i1 undef, label %bb17, label %bb17
1231
1232bb17:
1233 br i1 undef, label %bb22, label %bb22
1234
1235bb22:
1236 br i1 undef, label %bb27, label %bb27
1237
1238bb27:
1239 br i1 undef, label %bb30, label %bb30
1240
1241bb30:
1242 br i1 undef, label %bb35, label %bb35
1243
1244bb35:
1245 br i1 undef, label %bb38, label %bb38
1246
1247bb38:
1248 br i1 undef, label %bb48, label %bb48
1249
1250bb48:
1251 %tmp49 = bitcast i1 undef to i1
1252 br i1 %tmp49, label %bb3, label %bb50
1253
1254bb50:
1255 ret void
1256}
Dan Gohmana187ab22016-02-12 21:19:25 +00001257
1258; Test that a block boundary which ends one block, begins another block, and
1259; also begins a loop, has the markers placed in the correct order.
1260
1261; CHECK-LABEL: test15:
1262; CHECK: block
Dan Gohmana187ab22016-02-12 21:19:25 +00001263; CHECK-NEXT: block
Dan Gohman442bfce2016-02-16 16:22:41 +00001264; CHECK: br_if 0, $pop{{.*}}{{$}}
Dan Gohmand85ab7f2016-02-18 06:32:53 +00001265; CHECK: .LBB24_2:
Dan Gohman2726b882016-10-06 22:29:32 +00001266; CHECK-NEXT: block {{$}}
1267; CHECK-NEXT: block {{$}}
1268; CHECK-NEXT: loop {{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +00001269; CHECK: br_if 1, $pop{{.*}}{{$}}
Dan Gohmand85ab7f2016-02-18 06:32:53 +00001270; CHECK: br_if 0, ${{.*}}{{$}}
1271; CHECK-NEXT: br 2{{$}}
1272; CHECK-NEXT: .LBB24_4:
Dan Gohman442bfce2016-02-16 16:22:41 +00001273; CHECK-NEXT: end_loop{{$}}
Dan Gohmand85ab7f2016-02-18 06:32:53 +00001274; CHECK: .LBB24_5:
Dan Gohman442bfce2016-02-16 16:22:41 +00001275; CHECK-NEXT: end_block{{$}}
1276; CHECK: br_if 1, $pop{{.*}}{{$}}
1277; CHECK: return{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +00001278; CHECK: .LBB24_7:
1279; CHECK-NEXT: end_block{{$}}
Dan Gohmand85ab7f2016-02-18 06:32:53 +00001280; CHECK: .LBB24_8:
1281; CHECK-NEXT: end_block{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +00001282; CHECK-NEXT: return{{$}}
Dan Gohmana187ab22016-02-12 21:19:25 +00001283; OPT-LABEL: test15:
1284; OPT: block
Dan Gohmand85ab7f2016-02-18 06:32:53 +00001285; OPT: block
Dan Gohmana187ab22016-02-12 21:19:25 +00001286; OPT-NEXT: i32.const $push
Dan Gohman804749c2016-05-16 18:59:34 +00001287; OPT-NEXT: i32.eqz $push{{.*}}=, $pop{{.*}}{{$}}
Dan Gohmana187ab22016-02-12 21:19:25 +00001288; OPT-NEXT: br_if 0, $pop{{.*}}{{$}}
1289; OPT-NEXT: call test15_callee1@FUNCTION{{$}}
Dan Gohmand85ab7f2016-02-18 06:32:53 +00001290; OPT-NEXT: br 1{{$}}
Dan Gohmana187ab22016-02-12 21:19:25 +00001291; OPT-NEXT: .LBB24_2:
1292; OPT-NEXT: end_block
Dan Gohmand85ab7f2016-02-18 06:32:53 +00001293; OPT-NEXT: i32.const
1294; OPT-NEXT: .LBB24_3:
Dan Gohmana187ab22016-02-12 21:19:25 +00001295; OPT-NEXT: block
Dan Gohman3a643e82016-10-06 22:10:23 +00001296; OPT-NEXT: block
Dan Gohmana187ab22016-02-12 21:19:25 +00001297; OPT-NEXT: loop
1298%0 = type { i8, i32 }
1299declare void @test15_callee0()
1300declare void @test15_callee1()
1301define void @test15() {
1302bb:
1303 %tmp1 = icmp eq i8 1, 0
1304 br i1 %tmp1, label %bb2, label %bb14
1305
1306bb2:
1307 %tmp3 = phi %0** [ %tmp6, %bb5 ], [ null, %bb ]
1308 %tmp4 = icmp eq i32 0, 11
1309 br i1 %tmp4, label %bb5, label %bb8
1310
1311bb5:
1312 %tmp = bitcast i8* null to %0**
1313 %tmp6 = getelementptr %0*, %0** %tmp3, i32 1
1314 %tmp7 = icmp eq %0** %tmp6, null
1315 br i1 %tmp7, label %bb10, label %bb2
1316
1317bb8:
1318 %tmp9 = icmp eq %0** null, undef
1319 br label %bb10
1320
1321bb10:
1322 %tmp11 = phi %0** [ null, %bb8 ], [ %tmp, %bb5 ]
1323 %tmp12 = icmp eq %0** null, %tmp11
1324 br i1 %tmp12, label %bb15, label %bb13
1325
1326bb13:
1327 call void @test15_callee0()
1328 ret void
1329
1330bb14:
1331 call void @test15_callee1()
1332 ret void
1333
1334bb15:
1335 ret void
1336}