blob: 02c3fd30283acc7522486d00edf25d7b66e979c6 [file] [log] [blame]
Dan Gohmanb7c24002016-05-21 00:21:56 +00001; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -disable-block-placement -verify-machineinstrs -fast-isel=false | FileCheck %s
Kyle Butt25ac35d2016-10-05 01:39:29 +00002; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -verify-machineinstrs -fast-isel=false | FileCheck -check-prefix=OPT %s
Dan Gohman950a13c2015-09-16 16:51:30 +00003
4; Test the CFG stackifier pass.
5
Dan Gohman2e644382016-05-10 17:39:48 +00006; Explicitly disable fast-isel, since it gets implicitly enabled in the
7; optnone test.
8
Dan Gohman0c6f5ac2016-01-07 03:19:23 +00009target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
Dan Gohman950a13c2015-09-16 16:51:30 +000010target triple = "wasm32-unknown-unknown"
11
12declare void @something()
13
14; Test that loops are made contiguous, even in the presence of split backedges.
15
Dan Gohmane51c0582015-10-06 00:27:55 +000016; CHECK-LABEL: test0:
17; CHECK: loop
Dan Gohman442bfce2016-02-16 16:22:41 +000018; CHECK-NEXT: block
Dan Gohman12de0b92016-05-17 20:19:47 +000019; CHECK: 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 Gohman1d68e80f2016-01-12 19:14:46 +0000108; CHECK: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000109; CHECK: br_if 0, {{[^,]+}}{{$}}
Dan Gohman0cfb5f82016-05-10 04:24:02 +0000110; CHECK: .LBB2_{{[0-9]+}}:
Dan Gohman12de0b92016-05-17 20:19:47 +0000111; CHECK: loop
112; CHECK: br_if 0, $pop{{[0-9]+}}{{$}}
Dan Gohman0cfb5f82016-05-10 04:24:02 +0000113; CHECK: .LBB2_{{[0-9]+}}:
Dan Gohman12de0b92016-05-17 20:19:47 +0000114; CHECK: end_loop
115; CHECK: end_block
Dan Gohmane51c0582015-10-06 00:27:55 +0000116; CHECK: return{{$}}
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000117; OPT-LABEL: test2:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000118; OPT-NOT: local
119; OPT: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000120; OPT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman0cfb5f82016-05-10 04:24:02 +0000121; OPT: .LBB2_{{[0-9]+}}:
Dan Gohman12de0b92016-05-17 20:19:47 +0000122; OPT: loop
123; OPT: br_if 0, $pop{{[0-9]+}}{{$}}
Dan Gohman0cfb5f82016-05-10 04:24:02 +0000124; OPT: .LBB2_{{[0-9]+}}:
Dan Gohman12de0b92016-05-17 20:19:47 +0000125; OPT: end_loop
126; OPT: end_block
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000127; OPT: return{{$}}
Dan Gohman950a13c2015-09-16 16:51:30 +0000128define void @test2(double* nocapture %p, i32 %n) {
129entry:
130 %cmp.4 = icmp sgt i32 %n, 0
131 br i1 %cmp.4, label %for.body.preheader, label %for.end
132
133for.body.preheader:
134 br label %for.body
135
136for.body:
137 %i.05 = phi i32 [ %inc, %for.body ], [ 0, %for.body.preheader ]
138 %arrayidx = getelementptr inbounds double, double* %p, i32 %i.05
139 %0 = load double, double* %arrayidx, align 8
140 %mul = fmul double %0, 3.200000e+00
141 store double %mul, double* %arrayidx, align 8
142 %inc = add nuw nsw i32 %i.05, 1
143 %exitcond = icmp eq i32 %inc, %n
144 br i1 %exitcond, label %for.end.loopexit, label %for.body
145
146for.end.loopexit:
147 br label %for.end
148
149for.end:
150 ret void
151}
152
Dan Gohmane51c0582015-10-06 00:27:55 +0000153; CHECK-LABEL: doublediamond:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000154; CHECK: block{{$}}
155; CHECK-NEXT: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000156; CHECK: br_if 0, ${{[^,]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000157; CHECK: br 1{{$}}
158; CHECK: .LBB3_2:
159; CHECK-NEXT: end_block{{$}}
160; CHECK: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000161; CHECK: br_if 0, ${{[^,]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000162; CHECK: br 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000163; CHECK: .LBB3_4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000164; CHECK-NEXT: end_block{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000165; CHECK: .LBB3_5:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000166; CHECK-NEXT: end_block{{$}}
Dan Gohmanb6fd39a2016-01-19 16:59:23 +0000167; CHECK: i32.const $push{{[0-9]+}}=, 0{{$}}
168; CHECK-NEXT: return $pop{{[0-9]+}}{{$}}
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000169; OPT-LABEL: doublediamond:
Dan Gohman442bfce2016-02-16 16:22:41 +0000170; OPT: block{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000171; OPT-NEXT: block{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +0000172; OPT-NEXT: block{{$}}
173; OPT: br_if 0, ${{[^,]+}}{{$}}
174; OPT: br_if 1, ${{[^,]+}}{{$}}
175; OPT: br 2{{$}}
176; OPT-NEXT: .LBB3_3:
177; OPT-NEXT: end_block
178; OPT: br 1{{$}}
179; OPT-NEXT: .LBB3_4:
180; OPT: .LBB3_5:
181; OPT-NEXT: end_block
182; OPT: return $pop{{[0-9]+}}{{$}}
Dan Gohman950a13c2015-09-16 16:51:30 +0000183define i32 @doublediamond(i32 %a, i32 %b, i32* %p) {
184entry:
185 %c = icmp eq i32 %a, 0
186 %d = icmp eq i32 %b, 0
187 store volatile i32 0, i32* %p
188 br i1 %c, label %true, label %false
189true:
190 store volatile i32 1, i32* %p
191 br label %exit
192false:
193 store volatile i32 2, i32* %p
194 br i1 %d, label %ft, label %ff
195ft:
196 store volatile i32 3, i32* %p
197 br label %exit
198ff:
199 store volatile i32 4, i32* %p
200 br label %exit
201exit:
202 store volatile i32 5, i32* %p
203 ret i32 0
204}
205
Dan Gohmane51c0582015-10-06 00:27:55 +0000206; CHECK-LABEL: triangle:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000207; CHECK: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000208; CHECK: br_if 0, $1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000209; CHECK: .LBB4_2:
Dan Gohmanc9623db2016-08-18 17:51:27 +0000210; CHECK: return
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000211; OPT-LABEL: triangle:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000212; OPT: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000213; OPT: br_if 0, $1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000214; OPT: .LBB4_2:
Dan 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 Gohman1d68e80f2016-01-12 19:14:46 +0000230; CHECK: block{{$}}
231; CHECK: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000232; CHECK: br_if 0, $1{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000233; CHECK: br 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000234; CHECK: .LBB5_2:
235; CHECK: .LBB5_3:
Dan Gohmanb6fd39a2016-01-19 16:59:23 +0000236; CHECK: i32.const $push{{[0-9]+}}=, 0{{$}}
237; CHECK-NEXT: return $pop{{[0-9]+}}{{$}}
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000238; OPT-LABEL: diamond:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000239; OPT: block{{$}}
240; OPT: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000241; OPT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000242; OPT: br 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000243; OPT: .LBB5_2:
244; OPT: .LBB5_3:
Dan Gohmanb6fd39a2016-01-19 16:59:23 +0000245; OPT: i32.const $push{{[0-9]+}}=, 0{{$}}
246; OPT-NEXT: return $pop{{[0-9]+}}{{$}}
Dan Gohman950a13c2015-09-16 16:51:30 +0000247define i32 @diamond(i32* %p, i32 %a) {
248entry:
249 %c = icmp eq i32 %a, 0
250 store volatile i32 0, i32* %p
251 br i1 %c, label %true, label %false
252true:
253 store volatile i32 1, i32* %p
254 br label %exit
255false:
256 store volatile i32 2, i32* %p
257 br label %exit
258exit:
259 store volatile i32 3, i32* %p
260 ret i32 0
261}
262
Dan Gohmane51c0582015-10-06 00:27:55 +0000263; CHECK-LABEL: single_block:
Dan Gohman950a13c2015-09-16 16:51:30 +0000264; CHECK-NOT: br
Dan Gohman81719f82015-11-25 16:55:01 +0000265; CHECK: return $pop{{[0-9]+}}{{$}}
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000266; OPT-LABEL: single_block:
267; OPT-NOT: br
268; OPT: return $pop{{[0-9]+}}{{$}}
Dan Gohman950a13c2015-09-16 16:51:30 +0000269define i32 @single_block(i32* %p) {
270entry:
271 store volatile i32 0, i32* %p
272 ret i32 0
273}
274
Dan Gohmane51c0582015-10-06 00:27:55 +0000275; CHECK-LABEL: minimal_loop:
Dan Gohman950a13c2015-09-16 16:51:30 +0000276; CHECK-NOT: br
Dan Gohmana4730cf2016-01-07 18:49:53 +0000277; CHECK: .LBB7_1:
Dan Gohman7f1bdb22016-10-06 22:08:28 +0000278; CHECK: i32.store 0($0), $pop{{[0-9]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000279; CHECK: br 0{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000280; CHECK: .LBB7_2:
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000281; OPT-LABEL: minimal_loop:
282; OPT-NOT: br
Dan Gohmana4730cf2016-01-07 18:49:53 +0000283; OPT: .LBB7_1:
Dan Gohman7f1bdb22016-10-06 22:08:28 +0000284; OPT: i32.store 0($0), $pop{{[0-9]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000285; OPT: br 0{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000286; OPT: .LBB7_2:
Derek Schuff3b04b7e2016-09-16 20:58:31 +0000287define void @minimal_loop(i32* %p) {
Dan Gohman950a13c2015-09-16 16:51:30 +0000288entry:
289 store volatile i32 0, i32* %p
290 br label %loop
291loop:
292 store volatile i32 1, i32* %p
293 br label %loop
294}
295
Dan Gohmane51c0582015-10-06 00:27:55 +0000296; CHECK-LABEL: simple_loop:
Dan Gohman950a13c2015-09-16 16:51:30 +0000297; CHECK-NOT: br
Dan Gohmana4730cf2016-01-07 18:49:53 +0000298; CHECK: .LBB8_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000299; CHECK: loop{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000300; CHECK: br_if 0, $pop{{[0-9]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000301; CHECK-NEXT: end_loop{{$}}
Dan Gohmanb6fd39a2016-01-19 16:59:23 +0000302; CHECK: i32.const $push{{[0-9]+}}=, 0{{$}}
303; CHECK-NEXT: return $pop{{[0-9]+}}{{$}}
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000304; OPT-LABEL: simple_loop:
305; OPT-NOT: br
Dan Gohmana4730cf2016-01-07 18:49:53 +0000306; OPT: .LBB8_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000307; OPT: loop{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000308; OPT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000309; OPT-NEXT: end_loop{{$}}
Dan Gohmanb6fd39a2016-01-19 16:59:23 +0000310; OPT: i32.const $push{{[0-9]+}}=, 0{{$}}
311; OPT-NEXT: return $pop{{[0-9]+}}{{$}}
Dan Gohman950a13c2015-09-16 16:51:30 +0000312define i32 @simple_loop(i32* %p, i32 %a) {
313entry:
314 %c = icmp eq i32 %a, 0
315 store volatile i32 0, i32* %p
316 br label %loop
317loop:
318 store volatile i32 1, i32* %p
319 br i1 %c, label %loop, label %exit
320exit:
321 store volatile i32 2, i32* %p
322 ret i32 0
323}
324
Dan Gohmane51c0582015-10-06 00:27:55 +0000325; CHECK-LABEL: doubletriangle:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000326; CHECK: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000327; CHECK: br_if 0, $0{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000328; CHECK: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000329; CHECK: br_if 0, $1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000330; CHECK: .LBB9_3:
331; CHECK: .LBB9_4:
Dan Gohmanc9623db2016-08-18 17:51:27 +0000332; CHECK: return
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000333; OPT-LABEL: doubletriangle:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000334; OPT: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000335; OPT: br_if 0, $0{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000336; OPT: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000337; OPT: br_if 0, $1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000338; OPT: .LBB9_3:
339; OPT: .LBB9_4:
Dan Gohmanc9623db2016-08-18 17:51:27 +0000340; OPT: return
Dan Gohman950a13c2015-09-16 16:51:30 +0000341define i32 @doubletriangle(i32 %a, i32 %b, i32* %p) {
342entry:
343 %c = icmp eq i32 %a, 0
344 %d = icmp eq i32 %b, 0
345 store volatile i32 0, i32* %p
346 br i1 %c, label %true, label %exit
347true:
348 store volatile i32 2, i32* %p
349 br i1 %d, label %tt, label %tf
350tt:
351 store volatile i32 3, i32* %p
352 br label %tf
353tf:
354 store volatile i32 4, i32* %p
355 br label %exit
356exit:
357 store volatile i32 5, i32* %p
358 ret i32 0
359}
360
Dan Gohmane51c0582015-10-06 00:27:55 +0000361; CHECK-LABEL: ifelse_earlyexits:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000362; CHECK: block{{$}}
363; CHECK: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000364; CHECK: br_if 0, $0{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000365; CHECK: br 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000366; CHECK: .LBB10_2:
Dan Gohman06b49582016-02-08 21:50:13 +0000367; CHECK: br_if 0, $1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000368; CHECK: .LBB10_4:
Dan Gohmanb6fd39a2016-01-19 16:59:23 +0000369; CHECK: i32.const $push{{[0-9]+}}=, 0{{$}}
370; CHECK-NEXT: return $pop{{[0-9]+}}{{$}}
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000371; OPT-LABEL: ifelse_earlyexits:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000372; OPT: block{{$}}
373; OPT: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000374; OPT: br_if 0, {{[^,]+}}{{$}}
375; OPT: br_if 1, $1{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000376; OPT: br 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000377; OPT: .LBB10_3:
378; OPT: .LBB10_4:
Dan Gohmanb6fd39a2016-01-19 16:59:23 +0000379; OPT: i32.const $push{{[0-9]+}}=, 0{{$}}
380; OPT-NEXT: return $pop{{[0-9]+}}{{$}}
Dan Gohman950a13c2015-09-16 16:51:30 +0000381define i32 @ifelse_earlyexits(i32 %a, i32 %b, i32* %p) {
382entry:
383 %c = icmp eq i32 %a, 0
384 %d = icmp eq i32 %b, 0
385 store volatile i32 0, i32* %p
386 br i1 %c, label %true, label %false
387true:
388 store volatile i32 1, i32* %p
389 br label %exit
390false:
391 store volatile i32 2, i32* %p
392 br i1 %d, label %ft, label %exit
393ft:
394 store volatile i32 3, i32* %p
395 br label %exit
396exit:
397 store volatile i32 4, i32* %p
398 ret i32 0
399}
Dan Gohmane3e4a5f2015-10-02 21:11:36 +0000400
Dan Gohman32807932015-11-23 16:19:56 +0000401; CHECK-LABEL: doublediamond_in_a_loop:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000402; CHECK: .LBB11_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000403; CHECK: loop{{$}}
404; CHECK: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000405; CHECK: br_if 0, $0{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000406; CHECK: br 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000407; CHECK: .LBB11_3:
Dan Gohman0cfb5f82016-05-10 04:24:02 +0000408; CHECK: end_block{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000409; CHECK: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000410; CHECK: br_if 0, $1{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000411; CHECK: br 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000412; CHECK: .LBB11_5:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000413; CHECK: br 0{{$}}
Dan Gohman0cfb5f82016-05-10 04:24:02 +0000414; CHECK: .LBB11_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000415; CHECK-NEXT: end_loop{{$}}
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000416; OPT-LABEL: doublediamond_in_a_loop:
Dan Gohman442bfce2016-02-16 16:22:41 +0000417; OPT: .LBB11_1:
418; OPT: loop{{$}}
419; OPT: block{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +0000420; OPT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman0cfb5f82016-05-10 04:24:02 +0000421; OPT: block{{$}}
422; OPT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +0000423; OPT: br 2{{$}}
424; OPT-NEXT: .LBB11_4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000425; OPT-NEXT: end_block{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +0000426; OPT: br 1{{$}}
427; OPT: .LBB11_5:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000428; OPT-NEXT: end_block{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +0000429; OPT: br 0{{$}}
Dan Gohman0cfb5f82016-05-10 04:24:02 +0000430; OPT: .LBB11_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000431; OPT-NEXT: end_loop{{$}}
Derek Schuff3b04b7e2016-09-16 20:58:31 +0000432define void @doublediamond_in_a_loop(i32 %a, i32 %b, i32* %p) {
Dan Gohman32807932015-11-23 16:19:56 +0000433entry:
434 br label %header
435header:
436 %c = icmp eq i32 %a, 0
437 %d = icmp eq i32 %b, 0
438 store volatile i32 0, i32* %p
439 br i1 %c, label %true, label %false
440true:
441 store volatile i32 1, i32* %p
442 br label %exit
443false:
444 store volatile i32 2, i32* %p
445 br i1 %d, label %ft, label %ff
446ft:
447 store volatile i32 3, i32* %p
448 br label %exit
449ff:
450 store volatile i32 4, i32* %p
451 br label %exit
452exit:
453 store volatile i32 5, i32* %p
454 br label %header
455}
456
Dan Gohmane3e4a5f2015-10-02 21:11:36 +0000457; Test that nested loops are handled.
458
Dan Gohman8fe7e862015-12-14 22:51:54 +0000459; CHECK-LABEL: test3:
460; CHECK: loop
461; CHECK-NEXT: br_if
Dan Gohmana4730cf2016-01-07 18:49:53 +0000462; CHECK-NEXT: .LBB{{[0-9]+}}_{{[0-9]+}}:
Dan Gohman8fe7e862015-12-14 22:51:54 +0000463; CHECK-NEXT: loop
464; OPT-LABEL: test3:
Dan Gohman442bfce2016-02-16 16:22:41 +0000465; OPT: block
466; OPT: br_if
Dan Gohmand85ab7f2016-02-18 06:32:53 +0000467; OPT: .LBB{{[0-9]+}}_{{[0-9]+}}:
Dan Gohman442bfce2016-02-16 16:22:41 +0000468; OPT-NEXT: loop
469; OPT-NEXT: block
470; OPT-NEXT: block
Dan Gohman8fe7e862015-12-14 22:51:54 +0000471; OPT-NEXT: br_if
Dan Gohmana4730cf2016-01-07 18:49:53 +0000472; OPT-NEXT: .LBB{{[0-9]+}}_{{[0-9]+}}:
Dan Gohman8fe7e862015-12-14 22:51:54 +0000473; OPT-NEXT: loop
Dan Gohman442bfce2016-02-16 16:22:41 +0000474; OPT: br_if
475; OPT-NEXT: br
476; OPT-NEXT: .LBB{{[0-9]+}}_{{[0-9]+}}:
477; OPT-NEXT: end_loop
478; OPT-NEXT: end_block
479; OPT-NEXT: unreachable
480; OPT-NEXT: .LBB{{[0-9]+}}_{{[0-9]+}}:
481; OPT-NEXT: end_block
482; OPT: br
483; OPT-NEXT: .LBB{{[0-9]+}}_{{[0-9]+}}:
484; OPT-NEXT: end_loop
Dan Gohmane3e4a5f2015-10-02 21:11:36 +0000485declare void @bar()
Dan Gohmane3e4a5f2015-10-02 21:11:36 +0000486define void @test3(i32 %w) {
487entry:
488 br i1 undef, label %outer.ph, label %exit
489
490outer.ph:
491 br label %outer
492
493outer:
494 %tobool = icmp eq i32 undef, 0
495 br i1 %tobool, label %inner, label %unreachable
496
497unreachable:
498 unreachable
499
500inner:
501 %c = icmp eq i32 undef, %w
502 br i1 %c, label %if.end, label %inner
503
504exit:
505 ret void
506
507if.end:
508 call void @bar()
509 br label %outer
510}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000511
512; Test switch lowering and block placement.
513
514; CHECK-LABEL: test4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000515; CHECK-NEXT: .param i32{{$}}
516; CHECK: block{{$}}
517; CHECK-NEXT: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000518; CHECK: br_if 0, $pop{{[0-9]+}}{{$}}
Dan Gohmand85ab7f2016-02-18 06:32:53 +0000519; CHECK: br_if 1, $pop{{[0-9]+}}{{$}}
520; CHECK: br 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000521; CHECK-NEXT: .LBB13_3:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000522; CHECK-NEXT: end_block{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +0000523; CHECK-NEXT: block{{$}}
Dan Gohmand85ab7f2016-02-18 06:32:53 +0000524; CHECK: br_if 0, $pop{{[0-9]+}}{{$}}
525; CHECK: br_if 1, $pop{{[0-9]+}}{{$}}
526; CHECK-NEXT: .LBB13_5:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000527; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000528; CHECK-NEXT: return{{$}}
Dan Gohmand85ab7f2016-02-18 06:32:53 +0000529; CHECK-NEXT: .LBB13_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000530; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000531; CHECK-NEXT: return{{$}}
532; OPT-LABEL: test4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000533; OPT-NEXT: .param i32{{$}}
534; OPT: block{{$}}
535; OPT-NEXT: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000536; OPT: br_if 0, $pop{{[0-9]+}}{{$}}
Dan Gohmand85ab7f2016-02-18 06:32:53 +0000537; OPT: br_if 1, $pop{{[0-9]+}}{{$}}
538; OPT: br 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000539; OPT-NEXT: .LBB13_3:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000540; OPT-NEXT: end_block{{$}}
Dan Gohmand85ab7f2016-02-18 06:32:53 +0000541; OPT-NEXT: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000542; OPT: br_if 0, $pop{{[0-9]+}}{{$}}
Dan Gohmand85ab7f2016-02-18 06:32:53 +0000543; OPT: br_if 1, $pop{{[0-9]+}}{{$}}
544; OPT-NEXT: .LBB13_5:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000545; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000546; OPT-NEXT: return{{$}}
Dan Gohmand85ab7f2016-02-18 06:32:53 +0000547; OPT-NEXT: .LBB13_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000548; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000549; OPT-NEXT: return{{$}}
550define void @test4(i32 %t) {
551entry:
552 switch i32 %t, label %default [
553 i32 0, label %bb2
554 i32 2, label %bb2
555 i32 4, label %bb1
556 i32 622, label %bb0
557 ]
558
559bb0:
560 ret void
561
562bb1:
563 ret void
564
565bb2:
566 ret void
567
568default:
569 ret void
570}
571
572; Test a case where the BLOCK needs to be placed before the LOOP in the
573; same basic block.
574
575; CHECK-LABEL: test5:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000576; CHECK: .LBB14_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000577; CHECK-NEXT: block{{$}}
578; CHECK-NEXT: loop{{$}}
Dan Gohman3a643e82016-10-06 22:10:23 +0000579; CHECK: br_if 1, {{[^,]+}}{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000580; CHECK: br_if 0, {{[^,]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000581; CHECK-NEXT: end_loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000582; CHECK: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000583; CHECK-NEXT: .LBB14_4:
Dan Gohman8fe7e862015-12-14 22:51:54 +0000584; CHECK: return{{$}}
585; OPT-LABEL: test5:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000586; OPT: .LBB14_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000587; OPT-NEXT: block{{$}}
588; OPT-NEXT: loop{{$}}
Dan Gohman3a643e82016-10-06 22:10:23 +0000589; OPT: br_if 1, {{[^,]+}}{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000590; OPT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000591; OPT-NEXT: end_loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000592; OPT: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000593; OPT-NEXT: .LBB14_4:
Dan Gohman8fe7e862015-12-14 22:51:54 +0000594; OPT: return{{$}}
595define void @test5(i1 %p, i1 %q) {
596entry:
597 br label %header
598
599header:
600 store volatile i32 0, i32* null
601 br i1 %p, label %more, label %alt
602
603more:
604 store volatile i32 1, i32* null
605 br i1 %q, label %header, label %return
606
607alt:
608 store volatile i32 2, i32* null
609 ret void
610
611return:
612 store volatile i32 3, i32* null
613 ret void
614}
615
616; Test an interesting case of a loop with multiple exits, which
617; aren't to layout successors of the loop, and one of which is to a successors
618; which has another predecessor.
619
620; CHECK-LABEL: test6:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000621; CHECK: .LBB15_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000622; CHECK-NEXT: block{{$}}
623; CHECK-NEXT: block{{$}}
624; CHECK-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000625; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000626; CHECK: br_if 2, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000627; CHECK-NOT: block
Dan Gohman3a643e82016-10-06 22:10:23 +0000628; CHECK: br_if 1, {{[^,]+}}{{$}}
629; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000630; CHECK: br_if 0, {{[^,]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000631; CHECK-NEXT: end_loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000632; CHECK-NOT: block
633; CHECK: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000634; CHECK-NEXT: .LBB15_5:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000635; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000636; CHECK-NOT: block
Dan Gohmana4730cf2016-01-07 18:49:53 +0000637; CHECK: .LBB15_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000638; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000639; CHECK-NOT: block
640; CHECK: return{{$}}
641; OPT-LABEL: test6:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000642; OPT: .LBB15_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000643; OPT-NEXT: block{{$}}
644; OPT-NEXT: block{{$}}
645; OPT-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000646; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000647; OPT: br_if 2, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000648; OPT-NOT: block
Dan Gohman3a643e82016-10-06 22:10:23 +0000649; OPT: br_if 1, {{[^,]+}}{{$}}
650; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000651; OPT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000652; OPT-NEXT: end_loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000653; OPT-NOT: block
654; OPT: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000655; OPT-NEXT: .LBB15_5:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000656; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000657; OPT-NOT: block
Dan Gohmana4730cf2016-01-07 18:49:53 +0000658; OPT: .LBB15_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000659; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000660; OPT-NOT: block
661; OPT: return{{$}}
662define void @test6(i1 %p, i1 %q) {
663entry:
664 br label %header
665
666header:
667 store volatile i32 0, i32* null
668 br i1 %p, label %more, label %second
669
670more:
671 store volatile i32 1, i32* null
672 br i1 %q, label %evenmore, label %first
673
674evenmore:
675 store volatile i32 1, i32* null
676 br i1 %q, label %header, label %return
677
678return:
679 store volatile i32 2, i32* null
680 ret void
681
682first:
683 store volatile i32 3, i32* null
684 br label %second
685
686second:
687 store volatile i32 4, i32* null
688 ret void
689}
690
691; Test a case where there are multiple backedges and multiple loop exits
692; that end in unreachable.
693
694; CHECK-LABEL: test7:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000695; CHECK: .LBB16_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000696; CHECK-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000697; CHECK-NOT: block
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000698; CHECK: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000699; CHECK: br_if 0, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000700; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000701; CHECK: br_if 1, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000702; CHECK-NOT: block
703; CHECK: unreachable
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000704; CHECK-NEXT: .LBB16_4:
705; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000706; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000707; CHECK: br_if 0, {{[^,]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000708; CHECK-NEXT: end_loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000709; CHECK-NOT: block
710; CHECK: unreachable
711; OPT-LABEL: test7:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000712; OPT: .LBB16_1:
Dan Gohman442bfce2016-02-16 16:22:41 +0000713; OPT-NEXT: block
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000714; OPT-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000715; OPT-NOT: block
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000716; OPT: block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000717; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000718; OPT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000719; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000720; OPT: br_if 1, {{[^,]+}}{{$}}
Dan Gohman3a643e82016-10-06 22:10:23 +0000721; OPT: br 2{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +0000722; OPT-NEXT: .LBB16_3:
723; OPT-NEXT: end_block
Dan Gohman8fe7e862015-12-14 22:51:54 +0000724; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000725; OPT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +0000726; OPT-NEXT: end_loop
727; OPT-NOT: block
728; OPT: unreachable
729; OPT-NEXT: .LBB16_5:
730; OPT-NEXT: end_block
Dan Gohman8fe7e862015-12-14 22:51:54 +0000731; OPT-NOT: block
732; OPT: unreachable
733define void @test7(i1 %tobool2, i1 %tobool9) {
734entry:
735 store volatile i32 0, i32* null
736 br label %loop
737
738loop:
739 store volatile i32 1, i32* null
740 br i1 %tobool2, label %l1, label %l0
741
742l0:
743 store volatile i32 2, i32* null
744 br i1 %tobool9, label %loop, label %u0
745
746l1:
747 store volatile i32 3, i32* null
748 br i1 %tobool9, label %loop, label %u1
749
750u0:
751 store volatile i32 4, i32* null
752 unreachable
753
754u1:
755 store volatile i32 5, i32* null
756 unreachable
757}
758
759; Test an interesting case using nested loops and switches.
760
761; CHECK-LABEL: test8:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000762; CHECK: .LBB17_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000763; CHECK-NEXT: loop{{$}}
Dan Gohmane5d3c152016-01-20 05:55:09 +0000764; CHECK-NEXT: i32.const $push{{[^,]+}}, 0{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000765; CHECK-NEXT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman0cfb5f82016-05-10 04:24:02 +0000766; CHECK-NEXT: br 0{{$}}
767; CHECK-NEXT: .LBB17_2:
768; CHECK-NEXT: end_loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000769; OPT-LABEL: test8:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000770; OPT: .LBB17_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000771; OPT-NEXT: loop{{$}}
Dan Gohmane5d3c152016-01-20 05:55:09 +0000772; OPT-NEXT: i32.const $push{{[^,]+}}, 0{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000773; OPT-NEXT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman0cfb5f82016-05-10 04:24:02 +0000774; OPT-NEXT: br 0{{$}}
775; OPT-NEXT: .LBB17_2:
776; OPT-NEXT: end_loop{{$}}
Derek Schuff3b04b7e2016-09-16 20:58:31 +0000777define void @test8() {
Dan Gohman8fe7e862015-12-14 22:51:54 +0000778bb:
779 br label %bb1
780
781bb1:
782 br i1 undef, label %bb2, label %bb3
783
784bb2:
785 switch i8 undef, label %bb1 [
786 i8 44, label %bb2
787 ]
788
789bb3:
790 switch i8 undef, label %bb1 [
791 i8 44, label %bb2
792 ]
793}
794
795; Test an interesting case using nested loops that share a bottom block.
796
797; CHECK-LABEL: test9:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000798; CHECK: .LBB18_1:
Dan Gohman3a643e82016-10-06 22:10:23 +0000799; CHECK-NEXT: block{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000800; CHECK-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000801; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000802; CHECK: br_if 1, {{[^,]+}}{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000803; CHECK-NEXT: .LBB18_2:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000804; CHECK-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000805; CHECK-NOT: block
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000806; CHECK: block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000807; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000808; CHECK: br_if 0, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000809; CHECK-NOT: block
Dan Gohman3a643e82016-10-06 22:10:23 +0000810; CHECK: br_if 2, {{[^,]+}}{{$}}
Dan Gohmand85ab7f2016-02-18 06:32:53 +0000811; CHECK-NEXT: br 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000812; CHECK-NEXT: .LBB18_4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000813; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000814; CHECK-NOT: block
Dan Gohman3a643e82016-10-06 22:10:23 +0000815; CHECK: br_if 1, {{[^,]+}}{{$}}
Dan Gohmand85ab7f2016-02-18 06:32:53 +0000816; CHECK-NEXT: br 0{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000817; CHECK-NEXT: .LBB18_5:
Dan Gohman8fe7e862015-12-14 22:51:54 +0000818; CHECK-NOT: block
Dan Gohman3a643e82016-10-06 22:10:23 +0000819; CHECK: end_block
820; CHECK-NOT: block
Dan Gohman8fe7e862015-12-14 22:51:54 +0000821; CHECK: return{{$}}
822; OPT-LABEL: test9:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000823; OPT: .LBB18_1:
Dan Gohman3a643e82016-10-06 22:10:23 +0000824; OPT-NEXT: block{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000825; OPT-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000826; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000827; OPT: br_if 1, {{[^,]+}}{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000828; OPT-NEXT: .LBB18_2:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000829; OPT-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000830; OPT-NOT: block
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000831; OPT: block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000832; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000833; OPT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000834; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000835; OPT: br_if 1, {{[^,]+}}{{$}}
Dan Gohman3a643e82016-10-06 22:10:23 +0000836; OPT-NEXT: br 2{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000837; OPT-NEXT: .LBB18_4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000838; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000839; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000840; OPT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman3a643e82016-10-06 22:10:23 +0000841; OPT-NEXT: br 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000842; OPT-NEXT: .LBB18_5:
Dan Gohman8fe7e862015-12-14 22:51:54 +0000843; OPT-NOT: block
Dan Gohman3a643e82016-10-06 22:10:23 +0000844; OPT: end_block
845; OPT-NOT: block
Dan Gohman8fe7e862015-12-14 22:51:54 +0000846; OPT: return{{$}}
847declare i1 @a()
848define void @test9() {
849entry:
850 store volatile i32 0, i32* null
851 br label %header
852
853header:
854 store volatile i32 1, i32* null
855 %call4 = call i1 @a()
856 br i1 %call4, label %header2, label %end
857
858header2:
859 store volatile i32 2, i32* null
860 %call = call i1 @a()
861 br i1 %call, label %if.then, label %if.else
862
863if.then:
864 store volatile i32 3, i32* null
865 %call3 = call i1 @a()
866 br i1 %call3, label %header2, label %header
867
868if.else:
869 store volatile i32 4, i32* null
870 %call2 = call i1 @a()
871 br i1 %call2, label %header2, label %header
872
873end:
874 store volatile i32 5, i32* null
875 ret void
876}
877
878; Test an interesting case involving nested loops sharing a loop bottom,
879; and loop exits to a block with unreachable.
880
881; CHECK-LABEL: test10:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000882; CHECK: .LBB19_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000883; CHECK-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000884; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000885; CHECK: br_if 0, {{[^,]+}}{{$}}
JF Bastienc6ba5ea2016-04-05 17:01:52 +0000886; CHECK: .LBB19_3:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000887; CHECK-NEXT: block{{$}}
888; CHECK-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000889; CHECK-NOT: block
JF Bastienc6ba5ea2016-04-05 17:01:52 +0000890; CHECK: .LBB19_4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000891; CHECK-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000892; CHECK-NOT: block
Dan Gohman3a643e82016-10-06 22:10:23 +0000893; CHECK: br_if 3, {{[^,]+}}{{$}}
894; CHECK: block{{$}}
895; CHECK: br_table {{[^,]+}}, 1, 0, 4, 2, 3, 1{{$}}
JF Bastienc6ba5ea2016-04-05 17:01:52 +0000896; CHECK-NEXT: .LBB19_6:
Dan Gohman3a643e82016-10-06 22:10:23 +0000897; CHECK-NEXT: end_block{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000898; CHECK-NEXT: end_loop{{$}}
899; CHECK-NEXT: end_loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000900; CHECK-NEXT: return{{$}}
JF Bastienc6ba5ea2016-04-05 17:01:52 +0000901; CHECK-NEXT: .LBB19_7:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000902; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000903; CHECK-NOT: block
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000904; CHECK: br 0{{$}}
JF Bastienc6ba5ea2016-04-05 17:01:52 +0000905; CHECK-NEXT: .LBB19_8:
Dan Gohman8fe7e862015-12-14 22:51:54 +0000906; OPT-LABEL: test10:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000907; OPT: .LBB19_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000908; OPT-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000909; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000910; OPT: br_if 0, {{[^,]+}}{{$}}
JF Bastienc6ba5ea2016-04-05 17:01:52 +0000911; OPT: .LBB19_3:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000912; OPT-NEXT: block{{$}}
913; OPT-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000914; OPT-NOT: block
JF Bastienc6ba5ea2016-04-05 17:01:52 +0000915; OPT: .LBB19_4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000916; OPT-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000917; OPT-NOT: block
Dan Gohman3a643e82016-10-06 22:10:23 +0000918; OPT: br_if 3, {{[^,]+}}{{$}}
919; OPT: block
920; OPT: br_table {{[^,]+}}, 1, 0, 4, 2, 3, 1{{$}}
JF Bastienc6ba5ea2016-04-05 17:01:52 +0000921; OPT-NEXT: .LBB19_6:
Dan Gohman3a643e82016-10-06 22:10:23 +0000922; OPT-NEXT: end_block{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000923; OPT-NEXT: end_loop{{$}}
924; OPT-NEXT: end_loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000925; OPT-NEXT: return{{$}}
JF Bastienc6ba5ea2016-04-05 17:01:52 +0000926; OPT-NEXT: .LBB19_7:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000927; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000928; OPT-NOT: block
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000929; OPT: br 0{{$}}
JF Bastienc6ba5ea2016-04-05 17:01:52 +0000930; OPT-NEXT: .LBB19_8:
Dan Gohman8fe7e862015-12-14 22:51:54 +0000931define void @test10() {
932bb0:
933 br label %bb1
934
935bb1:
936 %tmp = phi i32 [ 2, %bb0 ], [ 3, %bb3 ]
937 %tmp3 = phi i32 [ undef, %bb0 ], [ %tmp11, %bb3 ]
938 %tmp4 = icmp eq i32 %tmp3, 0
939 br i1 %tmp4, label %bb4, label %bb2
940
941bb2:
942 br label %bb3
943
944bb3:
945 %tmp11 = phi i32 [ 1, %bb5 ], [ 0, %bb2 ]
946 br label %bb1
947
948bb4:
949 %tmp6 = phi i32 [ %tmp9, %bb5 ], [ 4, %bb1 ]
950 %tmp7 = phi i32 [ %tmp6, %bb5 ], [ %tmp, %bb1 ]
951 br label %bb5
952
953bb5:
954 %tmp9 = phi i32 [ %tmp6, %bb5 ], [ %tmp7, %bb4 ]
955 switch i32 %tmp9, label %bb2 [
956 i32 0, label %bb5
957 i32 1, label %bb6
958 i32 3, label %bb4
959 i32 4, label %bb3
960 ]
961
962bb6:
963 ret void
964}
965
966; Test a CFG DAG with interesting merging.
967
968; CHECK-LABEL: test11:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000969; CHECK: block{{$}}
970; CHECK-NEXT: block{{$}}
971; CHECK-NEXT: block{{$}}
972; CHECK-NEXT: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000973; CHECK: br_if 0, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000974; CHECK-NOT: block
Dan Gohmaned0f1132016-01-30 05:01:06 +0000975; CHECK: block{{$}}
Dan Gohmanc9623db2016-08-18 17:51:27 +0000976; CHECK-NEXT: i32.const
Dan Gohman06b49582016-02-08 21:50:13 +0000977; CHECK-NEXT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000978; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000979; CHECK: br_if 2, {{[^,]+}}{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000980; CHECK-NEXT: .LBB20_3:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000981; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000982; CHECK-NOT: block
983; CHECK: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000984; CHECK-NEXT: .LBB20_4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000985; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000986; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000987; CHECK: br_if 1, {{[^,]+}}{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +0000988; CHECK-NOT: block
989; CHECK: br_if 2, {{[^,]+}}{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000990; CHECK-NEXT: .LBB20_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000991; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000992; CHECK-NOT: block
993; CHECK: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000994; CHECK-NEXT: .LBB20_7:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000995; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000996; CHECK-NOT: block
997; CHECK: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000998; CHECK-NEXT: .LBB20_8:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000999; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001000; CHECK-NOT: block
1001; CHECK: return{{$}}
1002; OPT-LABEL: test11:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001003; OPT: block{{$}}
1004; OPT-NEXT: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +00001005; OPT: br_if 0, $pop{{[0-9]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001006; OPT-NOT: block
Dan Gohmaned0f1132016-01-30 05:01:06 +00001007; OPT: block{{$}}
Dan Gohmanc9623db2016-08-18 17:51:27 +00001008; OPT-NEXT: i32.const
1009; OPT-NEXT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001010; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +00001011; OPT: br_if 2, {{[^,]+}}{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +00001012; OPT-NEXT: .LBB20_3:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001013; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001014; OPT-NOT: block
1015; OPT: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +00001016; OPT-NEXT: .LBB20_4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001017; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001018; OPT-NOT: block
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001019; OPT: block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001020; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +00001021; OPT: br_if 0, $pop{{[0-9]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001022; OPT-NOT: block
1023; OPT: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +00001024; OPT-NEXT: .LBB20_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001025; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001026; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +00001027; OPT: br_if 0, $pop{{[0-9]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001028; OPT-NOT: block
1029; OPT: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +00001030; OPT-NEXT: .LBB20_8:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001031; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001032; OPT-NOT: block
1033; OPT: return{{$}}
1034define void @test11() {
1035bb0:
1036 store volatile i32 0, i32* null
1037 br i1 undef, label %bb1, label %bb4
1038bb1:
1039 store volatile i32 1, i32* null
1040 br i1 undef, label %bb3, label %bb2
1041bb2:
1042 store volatile i32 2, i32* null
1043 br i1 undef, label %bb3, label %bb7
1044bb3:
1045 store volatile i32 3, i32* null
1046 ret void
1047bb4:
1048 store volatile i32 4, i32* null
1049 br i1 undef, label %bb8, label %bb5
1050bb5:
1051 store volatile i32 5, i32* null
1052 br i1 undef, label %bb6, label %bb7
1053bb6:
1054 store volatile i32 6, i32* null
1055 ret void
1056bb7:
1057 store volatile i32 7, i32* null
1058 ret void
1059bb8:
1060 store volatile i32 8, i32* null
1061 ret void
1062}
1063
1064; CHECK-LABEL: test12:
Dan Gohmana4730cf2016-01-07 18:49:53 +00001065; CHECK: .LBB21_1:
Dan Gohman3a643e82016-10-06 22:10:23 +00001066; CHECK-NEXT: block{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001067; CHECK-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001068; CHECK-NOT: block
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001069; CHECK: block{{$}}
1070; CHECK-NEXT: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +00001071; CHECK: br_if 0, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001072; CHECK-NOT: block
Dan Gohman442bfce2016-02-16 16:22:41 +00001073; CHECK: br_if 1, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001074; CHECK-NOT: block
Dan Gohman442bfce2016-02-16 16:22:41 +00001075; CHECK: br_if 1, {{[^,]+}}{{$}}
1076; CHECK-NEXT: br 3{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +00001077; CHECK-NEXT: .LBB21_4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001078; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001079; CHECK-NOT: block
Dan Gohman442bfce2016-02-16 16:22:41 +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 2, {{[^,]+}}{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +00001083; CHECK-NEXT: .LBB21_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001084; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001085; CHECK-NOT: block
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001086; CHECK: br 0{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +00001087; CHECK-NEXT: .LBB21_7:
1088; CHECK-NEXT: end_loop{{$}}
Dan Gohman3a643e82016-10-06 22:10:23 +00001089; CHECK-NEXT: end_block{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +00001090; CHECK-NEXT: return{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001091; OPT-LABEL: test12:
Dan Gohmana4730cf2016-01-07 18:49:53 +00001092; OPT: .LBB21_1:
Dan Gohman3a643e82016-10-06 22:10:23 +00001093; OPT-NEXT: block{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001094; OPT-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001095; OPT-NOT: block
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001096; OPT: block{{$}}
1097; OPT-NEXT: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +00001098; OPT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001099; OPT-NOT: block
Dan Gohman442bfce2016-02-16 16:22:41 +00001100; OPT: br_if 1, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001101; OPT-NOT: block
Dan Gohman442bfce2016-02-16 16:22:41 +00001102; OPT: br_if 1, {{[^,]+}}{{$}}
1103; OPT-NEXT: br 3{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +00001104; OPT-NEXT: .LBB21_4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001105; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001106; OPT-NOT: block
Dan Gohman442bfce2016-02-16 16:22:41 +00001107; OPT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001108; OPT-NOT: block
Dan Gohman442bfce2016-02-16 16:22:41 +00001109; OPT: br_if 2, {{[^,]+}}{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +00001110; OPT-NEXT: .LBB21_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001111; OPT-NEXT: end_block{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001112; OPT: br 0{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +00001113; OPT-NEXT: .LBB21_7:
1114; OPT-NEXT: end_loop{{$}}
Dan Gohman3a643e82016-10-06 22:10:23 +00001115; OPT-NEXT: end_block{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +00001116; OPT-NEXT: return{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001117define void @test12(i8* %arg) {
1118bb:
1119 br label %bb1
1120
1121bb1:
1122 %tmp = phi i32 [ 0, %bb ], [ %tmp5, %bb4 ]
1123 %tmp2 = getelementptr i8, i8* %arg, i32 %tmp
1124 %tmp3 = load i8, i8* %tmp2
1125 switch i8 %tmp3, label %bb7 [
1126 i8 42, label %bb4
1127 i8 76, label %bb4
1128 i8 108, label %bb4
1129 i8 104, label %bb4
1130 ]
1131
1132bb4:
1133 %tmp5 = add i32 %tmp, 1
1134 br label %bb1
1135
1136bb7:
1137 ret void
1138}
Dan Gohmanb3aa1ec2015-12-16 19:06:41 +00001139
1140; A block can be "branched to" from another even if it is also reachable via
1141; fallthrough from the other. This would normally be optimized away, so use
1142; optnone to disable optimizations to test this case.
1143
1144; CHECK-LABEL: test13:
Dan Gohmanb6fd39a2016-01-19 16:59:23 +00001145; CHECK-NEXT: .local i32{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +00001146; CHECK-NEXT: block{{$}}
1147; CHECK-NEXT: block{{$}}
1148; CHECK: br_if 0, $pop0{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001149; CHECK: block{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +00001150; CHECK: br_if 0, $pop3{{$}}
1151; CHECK: .LBB22_3:
1152; CHECK-NEXT: end_block{{$}}
1153; CHECK: br_if 1, $pop{{[0-9]+}}{{$}}
1154; CHECK-NEXT: br 1{{$}}
1155; CHECK-NEXT: .LBB22_4:
1156; CHECK-NEXT: end_block{{$}}
Dan Gohmanb3aa1ec2015-12-16 19:06:41 +00001157; CHECK-NEXT: return{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +00001158; CHECK-NEXT: .LBB22_5:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001159; CHECK-NEXT: end_block{{$}}
Dan Gohmanb3aa1ec2015-12-16 19:06:41 +00001160; CHECK-NEXT: unreachable{{$}}
1161; OPT-LABEL: test13:
Dan Gohmanb6fd39a2016-01-19 16:59:23 +00001162; OPT-NEXT: .local i32{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +00001163; OPT-NEXT: block{{$}}
1164; OPT-NEXT: block{{$}}
1165; OPT: br_if 0, $pop0{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001166; OPT: block{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +00001167; OPT: br_if 0, $pop3{{$}}
1168; OPT: .LBB22_3:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001169; OPT-NEXT: end_block{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +00001170; OPT: br_if 1, $pop{{[0-9]+}}{{$}}
1171; OPT-NEXT: br 1{{$}}
1172; OPT-NEXT: .LBB22_4:
1173; OPT-NEXT: end_block
1174; OPT-NEXT: return
1175; OPT-NEXT: .LBB22_5:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001176; OPT-NEXT: end_block{{$}}
Dan Gohmanb3aa1ec2015-12-16 19:06:41 +00001177; OPT-NEXT: unreachable{{$}}
1178define void @test13() noinline optnone {
1179bb:
1180 br i1 undef, label %bb5, label %bb2
1181bb1:
1182 unreachable
1183bb2:
1184 br i1 undef, label %bb3, label %bb4
1185bb3:
1186 br label %bb4
1187bb4:
1188 %tmp = phi i1 [ false, %bb2 ], [ false, %bb3 ]
1189 br i1 %tmp, label %bb1, label %bb1
1190bb5:
1191 ret void
1192}
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001193
1194; Test a case with a single-block loop that has another loop
1195; as a successor. The end_loop for the first loop should go
1196; before the loop for the second.
1197
1198; CHECK-LABEL: test14:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001199; CHECK-NEXT: .LBB23_1:{{$}}
1200; CHECK-NEXT: loop{{$}}
Dan Gohmanb6fd39a2016-01-19 16:59:23 +00001201; CHECK-NEXT: i32.const $push0=, 0{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +00001202; CHECK-NEXT: br_if 0, $pop0{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001203; CHECK-NEXT: end_loop{{$}}
Dan Gohman0cfb5f82016-05-10 04:24:02 +00001204; CHECK-NEXT: .LBB23_3:{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001205; CHECK-NEXT: loop{{$}}
Dan Gohmanb6fd39a2016-01-19 16:59:23 +00001206; CHECK-NEXT: i32.const $push1=, 0{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +00001207; CHECK-NEXT: br_if 0, $pop1{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001208; CHECK-NEXT: end_loop{{$}}
1209; CHECK-NEXT: return{{$}}
1210define void @test14() {
1211bb:
1212 br label %bb1
1213
1214bb1:
1215 %tmp = bitcast i1 undef to i1
1216 br i1 %tmp, label %bb3, label %bb1
1217
1218bb3:
1219 br label %bb4
1220
1221bb4:
1222 br i1 undef, label %bb7, label %bb48
1223
1224bb7:
1225 br i1 undef, label %bb12, label %bb12
1226
1227bb12:
1228 br i1 undef, label %bb17, label %bb17
1229
1230bb17:
1231 br i1 undef, label %bb22, label %bb22
1232
1233bb22:
1234 br i1 undef, label %bb27, label %bb27
1235
1236bb27:
1237 br i1 undef, label %bb30, label %bb30
1238
1239bb30:
1240 br i1 undef, label %bb35, label %bb35
1241
1242bb35:
1243 br i1 undef, label %bb38, label %bb38
1244
1245bb38:
1246 br i1 undef, label %bb48, label %bb48
1247
1248bb48:
1249 %tmp49 = bitcast i1 undef to i1
1250 br i1 %tmp49, label %bb3, label %bb50
1251
1252bb50:
1253 ret void
1254}
Dan Gohmana187ab22016-02-12 21:19:25 +00001255
1256; Test that a block boundary which ends one block, begins another block, and
1257; also begins a loop, has the markers placed in the correct order.
1258
1259; CHECK-LABEL: test15:
1260; CHECK: block
Dan Gohmana187ab22016-02-12 21:19:25 +00001261; CHECK-NEXT: block
Dan Gohman442bfce2016-02-16 16:22:41 +00001262; CHECK: br_if 0, $pop{{.*}}{{$}}
Dan Gohmand85ab7f2016-02-18 06:32:53 +00001263; CHECK: .LBB24_2:
Dan Gohman442bfce2016-02-16 16:22:41 +00001264; CHECK-NEXT: block{{$}}
Dan Gohman3a643e82016-10-06 22:10:23 +00001265; CHECK-NEXT: block{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +00001266; CHECK-NEXT: loop{{$}}
1267; CHECK: br_if 1, $pop{{.*}}{{$}}
Dan Gohmand85ab7f2016-02-18 06:32:53 +00001268; CHECK: br_if 0, ${{.*}}{{$}}
1269; CHECK-NEXT: br 2{{$}}
1270; CHECK-NEXT: .LBB24_4:
Dan Gohman442bfce2016-02-16 16:22:41 +00001271; CHECK-NEXT: end_loop{{$}}
Dan Gohmand85ab7f2016-02-18 06:32:53 +00001272; CHECK: .LBB24_5:
Dan Gohman442bfce2016-02-16 16:22:41 +00001273; CHECK-NEXT: end_block{{$}}
1274; CHECK: br_if 1, $pop{{.*}}{{$}}
1275; CHECK: return{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +00001276; CHECK: .LBB24_7:
1277; CHECK-NEXT: end_block{{$}}
Dan Gohmand85ab7f2016-02-18 06:32:53 +00001278; CHECK: .LBB24_8:
1279; CHECK-NEXT: end_block{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +00001280; CHECK-NEXT: return{{$}}
Dan Gohmana187ab22016-02-12 21:19:25 +00001281; OPT-LABEL: test15:
1282; OPT: block
Dan Gohmand85ab7f2016-02-18 06:32:53 +00001283; OPT: block
Dan Gohmana187ab22016-02-12 21:19:25 +00001284; OPT-NEXT: i32.const $push
Dan Gohman804749c2016-05-16 18:59:34 +00001285; OPT-NEXT: i32.eqz $push{{.*}}=, $pop{{.*}}{{$}}
Dan Gohmana187ab22016-02-12 21:19:25 +00001286; OPT-NEXT: br_if 0, $pop{{.*}}{{$}}
1287; OPT-NEXT: call test15_callee1@FUNCTION{{$}}
Dan Gohmand85ab7f2016-02-18 06:32:53 +00001288; OPT-NEXT: br 1{{$}}
Dan Gohmana187ab22016-02-12 21:19:25 +00001289; OPT-NEXT: .LBB24_2:
1290; OPT-NEXT: end_block
Dan Gohmand85ab7f2016-02-18 06:32:53 +00001291; OPT-NEXT: i32.const
1292; OPT-NEXT: .LBB24_3:
Dan Gohmana187ab22016-02-12 21:19:25 +00001293; OPT-NEXT: block
Dan Gohman3a643e82016-10-06 22:10:23 +00001294; OPT-NEXT: block
Dan Gohmana187ab22016-02-12 21:19:25 +00001295; OPT-NEXT: loop
1296%0 = type { i8, i32 }
1297declare void @test15_callee0()
1298declare void @test15_callee1()
1299define void @test15() {
1300bb:
1301 %tmp1 = icmp eq i8 1, 0
1302 br i1 %tmp1, label %bb2, label %bb14
1303
1304bb2:
1305 %tmp3 = phi %0** [ %tmp6, %bb5 ], [ null, %bb ]
1306 %tmp4 = icmp eq i32 0, 11
1307 br i1 %tmp4, label %bb5, label %bb8
1308
1309bb5:
1310 %tmp = bitcast i8* null to %0**
1311 %tmp6 = getelementptr %0*, %0** %tmp3, i32 1
1312 %tmp7 = icmp eq %0** %tmp6, null
1313 br i1 %tmp7, label %bb10, label %bb2
1314
1315bb8:
1316 %tmp9 = icmp eq %0** null, undef
1317 br label %bb10
1318
1319bb10:
1320 %tmp11 = phi %0** [ null, %bb8 ], [ %tmp, %bb5 ]
1321 %tmp12 = icmp eq %0** null, %tmp11
1322 br i1 %tmp12, label %bb15, label %bb13
1323
1324bb13:
1325 call void @test15_callee0()
1326 ret void
1327
1328bb14:
1329 call void @test15_callee1()
1330 ret void
1331
1332bb15:
1333 ret void
1334}