blob: b29cd8860a25a03a35dedb6cde0010962c9e503b [file] [log] [blame]
Dan Gohman2e644382016-05-10 17:39:48 +00001; RUN: llc < %s -asm-verbose=false -disable-block-placement -verify-machineinstrs -fast-isel=false | FileCheck %s
2; RUN: llc < %s -asm-verbose=false -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 Gohmanf0b165a2015-12-05 03:03:35 +000018; CHECK-NOT: br
Dan Gohman8fe7e862015-12-14 22:51:54 +000019; CHECK: i32.add
Dan Gohman442bfce2016-02-16 16:22:41 +000020; CHECK-NEXT: block
21; CHECK-NEXT: i32.lt_s
Dan Gohman8fe7e862015-12-14 22:51:54 +000022; CHECK-NEXT: br_if
Dan Gohman442bfce2016-02-16 16:22:41 +000023; CHECK-NEXT: return
24; CHECK-NEXT: .LBB0_3:
25; CHECK-NEXT: end_block
26; 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 Gohmanf0b165a2015-12-05 03:03:35 +000032; OPT-NOT: br
Dan Gohman8fe7e862015-12-14 22:51:54 +000033; OPT: i32.add
34; OPT-NEXT: i32.ge_s
35; OPT-NEXT: br_if
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 Gohmanf0b165a2015-12-05 03:03:35 +000063; CHECK-NOT: br
Dan Gohman8fe7e862015-12-14 22:51:54 +000064; CHECK: i32.add
Dan Gohman442bfce2016-02-16 16:22:41 +000065; CHECK-NEXT: block
66; CHECK-NEXT: i32.lt_s
Dan Gohman8fe7e862015-12-14 22:51:54 +000067; CHECK-NEXT: br_if
Dan Gohman442bfce2016-02-16 16:22:41 +000068; CHECK-NEXT: return
69; CHECK-NEXT: .LBB1_3:
70; CHECK-NEXT: end_block
71; 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 Gohmanf0b165a2015-12-05 03:03:35 +000077; OPT-NOT: br
Dan Gohman8fe7e862015-12-14 22:51:54 +000078; OPT: i32.add
79; OPT-NEXT: i32.ge_s
80; OPT-NEXT: br_if
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 Gohman06b49582016-02-08 21:50:13 +0000111; CHECK: br_if 0, ${{[0-9]+}}{{$}}
Dan Gohman0cfb5f82016-05-10 04:24:02 +0000112; CHECK: .LBB2_{{[0-9]+}}:
Dan Gohmane51c0582015-10-06 00:27:55 +0000113; CHECK: return{{$}}
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000114; OPT-LABEL: test2:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000115; OPT-NOT: local
116; OPT: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000117; OPT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman0cfb5f82016-05-10 04:24:02 +0000118; OPT: .LBB2_{{[0-9]+}}:
Dan Gohman06b49582016-02-08 21:50:13 +0000119; OPT: br_if 0, ${{[0-9]+}}{{$}}
Dan Gohman0cfb5f82016-05-10 04:24:02 +0000120; OPT: .LBB2_{{[0-9]+}}:
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000121; OPT: return{{$}}
Dan Gohman950a13c2015-09-16 16:51:30 +0000122define void @test2(double* nocapture %p, i32 %n) {
123entry:
124 %cmp.4 = icmp sgt i32 %n, 0
125 br i1 %cmp.4, label %for.body.preheader, label %for.end
126
127for.body.preheader:
128 br label %for.body
129
130for.body:
131 %i.05 = phi i32 [ %inc, %for.body ], [ 0, %for.body.preheader ]
132 %arrayidx = getelementptr inbounds double, double* %p, i32 %i.05
133 %0 = load double, double* %arrayidx, align 8
134 %mul = fmul double %0, 3.200000e+00
135 store double %mul, double* %arrayidx, align 8
136 %inc = add nuw nsw i32 %i.05, 1
137 %exitcond = icmp eq i32 %inc, %n
138 br i1 %exitcond, label %for.end.loopexit, label %for.body
139
140for.end.loopexit:
141 br label %for.end
142
143for.end:
144 ret void
145}
146
Dan Gohmane51c0582015-10-06 00:27:55 +0000147; CHECK-LABEL: doublediamond:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000148; CHECK: block{{$}}
149; CHECK-NEXT: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000150; CHECK: br_if 0, ${{[^,]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000151; CHECK: br 1{{$}}
152; CHECK: .LBB3_2:
153; CHECK-NEXT: end_block{{$}}
154; CHECK: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000155; CHECK: br_if 0, ${{[^,]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000156; CHECK: br 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000157; CHECK: .LBB3_4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000158; CHECK-NEXT: end_block{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000159; CHECK: .LBB3_5:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000160; CHECK-NEXT: end_block{{$}}
Dan Gohmanb6fd39a2016-01-19 16:59:23 +0000161; CHECK: i32.const $push{{[0-9]+}}=, 0{{$}}
162; CHECK-NEXT: return $pop{{[0-9]+}}{{$}}
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000163; OPT-LABEL: doublediamond:
Dan Gohman442bfce2016-02-16 16:22:41 +0000164; OPT: block{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000165; OPT-NEXT: block{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +0000166; OPT-NEXT: block{{$}}
167; OPT: br_if 0, ${{[^,]+}}{{$}}
168; OPT: br_if 1, ${{[^,]+}}{{$}}
169; OPT: br 2{{$}}
170; OPT-NEXT: .LBB3_3:
171; OPT-NEXT: end_block
172; OPT: br 1{{$}}
173; OPT-NEXT: .LBB3_4:
174; OPT: .LBB3_5:
175; OPT-NEXT: end_block
176; OPT: return $pop{{[0-9]+}}{{$}}
Dan Gohman950a13c2015-09-16 16:51:30 +0000177define i32 @doublediamond(i32 %a, i32 %b, i32* %p) {
178entry:
179 %c = icmp eq i32 %a, 0
180 %d = icmp eq i32 %b, 0
181 store volatile i32 0, i32* %p
182 br i1 %c, label %true, label %false
183true:
184 store volatile i32 1, i32* %p
185 br label %exit
186false:
187 store volatile i32 2, i32* %p
188 br i1 %d, label %ft, label %ff
189ft:
190 store volatile i32 3, i32* %p
191 br label %exit
192ff:
193 store volatile i32 4, i32* %p
194 br label %exit
195exit:
196 store volatile i32 5, i32* %p
197 ret i32 0
198}
199
Dan Gohmane51c0582015-10-06 00:27:55 +0000200; CHECK-LABEL: triangle:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000201; CHECK: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000202; CHECK: br_if 0, $1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000203; CHECK: .LBB4_2:
Dan Gohman4ba48162015-11-18 16:12:01 +0000204; CHECK: return ${{[0-9]+}}{{$}}
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000205; OPT-LABEL: triangle:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000206; OPT: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000207; OPT: br_if 0, $1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000208; OPT: .LBB4_2:
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000209; OPT: return ${{[0-9]+}}{{$}}
Dan Gohman950a13c2015-09-16 16:51:30 +0000210define i32 @triangle(i32* %p, i32 %a) {
211entry:
212 %c = icmp eq i32 %a, 0
213 store volatile i32 0, i32* %p
214 br i1 %c, label %true, label %exit
215true:
216 store volatile i32 1, i32* %p
217 br label %exit
218exit:
219 store volatile i32 2, i32* %p
220 ret i32 0
221}
222
Dan Gohmane51c0582015-10-06 00:27:55 +0000223; CHECK-LABEL: diamond:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000224; CHECK: block{{$}}
225; CHECK: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000226; CHECK: br_if 0, $1{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000227; CHECK: br 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000228; CHECK: .LBB5_2:
229; CHECK: .LBB5_3:
Dan Gohmanb6fd39a2016-01-19 16:59:23 +0000230; CHECK: i32.const $push{{[0-9]+}}=, 0{{$}}
231; CHECK-NEXT: return $pop{{[0-9]+}}{{$}}
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000232; OPT-LABEL: diamond:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000233; OPT: block{{$}}
234; OPT: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000235; OPT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000236; OPT: br 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000237; OPT: .LBB5_2:
238; OPT: .LBB5_3:
Dan Gohmanb6fd39a2016-01-19 16:59:23 +0000239; OPT: i32.const $push{{[0-9]+}}=, 0{{$}}
240; OPT-NEXT: return $pop{{[0-9]+}}{{$}}
Dan Gohman950a13c2015-09-16 16:51:30 +0000241define i32 @diamond(i32* %p, i32 %a) {
242entry:
243 %c = icmp eq i32 %a, 0
244 store volatile i32 0, i32* %p
245 br i1 %c, label %true, label %false
246true:
247 store volatile i32 1, i32* %p
248 br label %exit
249false:
250 store volatile i32 2, i32* %p
251 br label %exit
252exit:
253 store volatile i32 3, i32* %p
254 ret i32 0
255}
256
Dan Gohmane51c0582015-10-06 00:27:55 +0000257; CHECK-LABEL: single_block:
Dan Gohman950a13c2015-09-16 16:51:30 +0000258; CHECK-NOT: br
Dan Gohman81719f82015-11-25 16:55:01 +0000259; CHECK: return $pop{{[0-9]+}}{{$}}
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000260; OPT-LABEL: single_block:
261; OPT-NOT: br
262; OPT: return $pop{{[0-9]+}}{{$}}
Dan Gohman950a13c2015-09-16 16:51:30 +0000263define i32 @single_block(i32* %p) {
264entry:
265 store volatile i32 0, i32* %p
266 ret i32 0
267}
268
Dan Gohmane51c0582015-10-06 00:27:55 +0000269; CHECK-LABEL: minimal_loop:
Dan Gohman950a13c2015-09-16 16:51:30 +0000270; CHECK-NOT: br
Dan Gohmana4730cf2016-01-07 18:49:53 +0000271; CHECK: .LBB7_1:
Derek Schuff9d779522015-12-05 00:26:39 +0000272; CHECK: i32.store $discard=, 0($0), $pop{{[0-9]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000273; CHECK: br 0{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000274; CHECK: .LBB7_2:
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000275; OPT-LABEL: minimal_loop:
276; OPT-NOT: br
Dan Gohmana4730cf2016-01-07 18:49:53 +0000277; OPT: .LBB7_1:
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000278; OPT: i32.store $discard=, 0($0), $pop{{[0-9]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000279; OPT: br 0{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000280; OPT: .LBB7_2:
Dan Gohman950a13c2015-09-16 16:51:30 +0000281define i32 @minimal_loop(i32* %p) {
282entry:
283 store volatile i32 0, i32* %p
284 br label %loop
285loop:
286 store volatile i32 1, i32* %p
287 br label %loop
288}
289
Dan Gohmane51c0582015-10-06 00:27:55 +0000290; CHECK-LABEL: simple_loop:
Dan Gohman950a13c2015-09-16 16:51:30 +0000291; CHECK-NOT: br
Dan Gohmana4730cf2016-01-07 18:49:53 +0000292; CHECK: .LBB8_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000293; CHECK: loop{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000294; CHECK: br_if 0, $pop{{[0-9]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000295; CHECK-NEXT: end_loop{{$}}
Dan Gohmanb6fd39a2016-01-19 16:59:23 +0000296; CHECK: i32.const $push{{[0-9]+}}=, 0{{$}}
297; CHECK-NEXT: return $pop{{[0-9]+}}{{$}}
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000298; OPT-LABEL: simple_loop:
299; OPT-NOT: br
Dan Gohmana4730cf2016-01-07 18:49:53 +0000300; OPT: .LBB8_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000301; OPT: loop{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000302; OPT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000303; OPT-NEXT: end_loop{{$}}
Dan Gohmanb6fd39a2016-01-19 16:59:23 +0000304; OPT: i32.const $push{{[0-9]+}}=, 0{{$}}
305; OPT-NEXT: return $pop{{[0-9]+}}{{$}}
Dan Gohman950a13c2015-09-16 16:51:30 +0000306define i32 @simple_loop(i32* %p, i32 %a) {
307entry:
308 %c = icmp eq i32 %a, 0
309 store volatile i32 0, i32* %p
310 br label %loop
311loop:
312 store volatile i32 1, i32* %p
313 br i1 %c, label %loop, label %exit
314exit:
315 store volatile i32 2, i32* %p
316 ret i32 0
317}
318
Dan Gohmane51c0582015-10-06 00:27:55 +0000319; CHECK-LABEL: doubletriangle:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000320; CHECK: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000321; CHECK: br_if 0, $0{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000322; CHECK: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000323; CHECK: br_if 0, $1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000324; CHECK: .LBB9_3:
325; CHECK: .LBB9_4:
Dan Gohman4ba48162015-11-18 16:12:01 +0000326; CHECK: return ${{[0-9]+}}{{$}}
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000327; OPT-LABEL: doubletriangle:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000328; OPT: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000329; OPT: br_if 0, $0{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000330; OPT: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000331; OPT: br_if 0, $1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000332; OPT: .LBB9_3:
333; OPT: .LBB9_4:
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000334; OPT: return ${{[0-9]+}}{{$}}
Dan Gohman950a13c2015-09-16 16:51:30 +0000335define i32 @doubletriangle(i32 %a, i32 %b, i32* %p) {
336entry:
337 %c = icmp eq i32 %a, 0
338 %d = icmp eq i32 %b, 0
339 store volatile i32 0, i32* %p
340 br i1 %c, label %true, label %exit
341true:
342 store volatile i32 2, i32* %p
343 br i1 %d, label %tt, label %tf
344tt:
345 store volatile i32 3, i32* %p
346 br label %tf
347tf:
348 store volatile i32 4, i32* %p
349 br label %exit
350exit:
351 store volatile i32 5, i32* %p
352 ret i32 0
353}
354
Dan Gohmane51c0582015-10-06 00:27:55 +0000355; CHECK-LABEL: ifelse_earlyexits:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000356; CHECK: block{{$}}
357; CHECK: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000358; CHECK: br_if 0, $0{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000359; CHECK: br 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000360; CHECK: .LBB10_2:
Dan Gohman06b49582016-02-08 21:50:13 +0000361; CHECK: br_if 0, $1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000362; CHECK: .LBB10_4:
Dan Gohmanb6fd39a2016-01-19 16:59:23 +0000363; CHECK: i32.const $push{{[0-9]+}}=, 0{{$}}
364; CHECK-NEXT: return $pop{{[0-9]+}}{{$}}
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000365; OPT-LABEL: ifelse_earlyexits:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000366; OPT: block{{$}}
367; OPT: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000368; OPT: br_if 0, {{[^,]+}}{{$}}
369; OPT: br_if 1, $1{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000370; OPT: br 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000371; OPT: .LBB10_3:
372; OPT: .LBB10_4:
Dan Gohmanb6fd39a2016-01-19 16:59:23 +0000373; OPT: i32.const $push{{[0-9]+}}=, 0{{$}}
374; OPT-NEXT: return $pop{{[0-9]+}}{{$}}
Dan Gohman950a13c2015-09-16 16:51:30 +0000375define i32 @ifelse_earlyexits(i32 %a, i32 %b, i32* %p) {
376entry:
377 %c = icmp eq i32 %a, 0
378 %d = icmp eq i32 %b, 0
379 store volatile i32 0, i32* %p
380 br i1 %c, label %true, label %false
381true:
382 store volatile i32 1, i32* %p
383 br label %exit
384false:
385 store volatile i32 2, i32* %p
386 br i1 %d, label %ft, label %exit
387ft:
388 store volatile i32 3, i32* %p
389 br label %exit
390exit:
391 store volatile i32 4, i32* %p
392 ret i32 0
393}
Dan Gohmane3e4a5f2015-10-02 21:11:36 +0000394
Dan Gohman32807932015-11-23 16:19:56 +0000395; CHECK-LABEL: doublediamond_in_a_loop:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000396; CHECK: .LBB11_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000397; CHECK: loop{{$}}
398; CHECK: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000399; CHECK: br_if 0, $0{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000400; CHECK: br 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000401; CHECK: .LBB11_3:
Dan Gohman0cfb5f82016-05-10 04:24:02 +0000402; CHECK: end_block{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000403; CHECK: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000404; CHECK: br_if 0, $1{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000405; CHECK: br 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000406; CHECK: .LBB11_5:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000407; CHECK: br 0{{$}}
Dan Gohman0cfb5f82016-05-10 04:24:02 +0000408; CHECK: .LBB11_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000409; CHECK-NEXT: end_loop{{$}}
Dan Gohmanf0b165a2015-12-05 03:03:35 +0000410; OPT-LABEL: doublediamond_in_a_loop:
Dan Gohman442bfce2016-02-16 16:22:41 +0000411; OPT: .LBB11_1:
412; OPT: loop{{$}}
413; OPT: block{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +0000414; OPT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman0cfb5f82016-05-10 04:24:02 +0000415; OPT: block{{$}}
416; OPT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +0000417; OPT: br 2{{$}}
418; OPT-NEXT: .LBB11_4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000419; OPT-NEXT: end_block{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +0000420; OPT: br 1{{$}}
421; OPT: .LBB11_5:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000422; OPT-NEXT: end_block{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +0000423; OPT: br 0{{$}}
Dan Gohman0cfb5f82016-05-10 04:24:02 +0000424; OPT: .LBB11_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000425; OPT-NEXT: end_loop{{$}}
Dan Gohman32807932015-11-23 16:19:56 +0000426define i32 @doublediamond_in_a_loop(i32 %a, i32 %b, i32* %p) {
427entry:
428 br label %header
429header:
430 %c = icmp eq i32 %a, 0
431 %d = icmp eq i32 %b, 0
432 store volatile i32 0, i32* %p
433 br i1 %c, label %true, label %false
434true:
435 store volatile i32 1, i32* %p
436 br label %exit
437false:
438 store volatile i32 2, i32* %p
439 br i1 %d, label %ft, label %ff
440ft:
441 store volatile i32 3, i32* %p
442 br label %exit
443ff:
444 store volatile i32 4, i32* %p
445 br label %exit
446exit:
447 store volatile i32 5, i32* %p
448 br label %header
449}
450
Dan Gohmane3e4a5f2015-10-02 21:11:36 +0000451; Test that nested loops are handled.
452
Dan Gohman8fe7e862015-12-14 22:51:54 +0000453; CHECK-LABEL: test3:
454; CHECK: loop
455; CHECK-NEXT: br_if
Dan Gohmana4730cf2016-01-07 18:49:53 +0000456; CHECK-NEXT: .LBB{{[0-9]+}}_{{[0-9]+}}:
Dan Gohman8fe7e862015-12-14 22:51:54 +0000457; CHECK-NEXT: loop
458; OPT-LABEL: test3:
Dan Gohman442bfce2016-02-16 16:22:41 +0000459; OPT: block
460; OPT: br_if
Dan Gohmand85ab7f2016-02-18 06:32:53 +0000461; OPT: .LBB{{[0-9]+}}_{{[0-9]+}}:
Dan Gohman442bfce2016-02-16 16:22:41 +0000462; OPT-NEXT: loop
463; OPT-NEXT: block
464; OPT-NEXT: block
Dan Gohman8fe7e862015-12-14 22:51:54 +0000465; OPT-NEXT: br_if
Dan Gohmana4730cf2016-01-07 18:49:53 +0000466; OPT-NEXT: .LBB{{[0-9]+}}_{{[0-9]+}}:
Dan Gohman8fe7e862015-12-14 22:51:54 +0000467; OPT-NEXT: loop
Dan Gohman442bfce2016-02-16 16:22:41 +0000468; OPT: br_if
469; OPT-NEXT: br
470; OPT-NEXT: .LBB{{[0-9]+}}_{{[0-9]+}}:
471; OPT-NEXT: end_loop
472; OPT-NEXT: end_block
473; OPT-NEXT: unreachable
474; OPT-NEXT: .LBB{{[0-9]+}}_{{[0-9]+}}:
475; OPT-NEXT: end_block
476; OPT: br
477; OPT-NEXT: .LBB{{[0-9]+}}_{{[0-9]+}}:
478; OPT-NEXT: end_loop
Dan Gohmane3e4a5f2015-10-02 21:11:36 +0000479declare void @bar()
Dan Gohmane3e4a5f2015-10-02 21:11:36 +0000480define void @test3(i32 %w) {
481entry:
482 br i1 undef, label %outer.ph, label %exit
483
484outer.ph:
485 br label %outer
486
487outer:
488 %tobool = icmp eq i32 undef, 0
489 br i1 %tobool, label %inner, label %unreachable
490
491unreachable:
492 unreachable
493
494inner:
495 %c = icmp eq i32 undef, %w
496 br i1 %c, label %if.end, label %inner
497
498exit:
499 ret void
500
501if.end:
502 call void @bar()
503 br label %outer
504}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000505
506; Test switch lowering and block placement.
507
508; CHECK-LABEL: test4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000509; CHECK-NEXT: .param i32{{$}}
510; CHECK: block{{$}}
511; CHECK-NEXT: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000512; CHECK: br_if 0, $pop{{[0-9]+}}{{$}}
Dan Gohmand85ab7f2016-02-18 06:32:53 +0000513; CHECK: br_if 1, $pop{{[0-9]+}}{{$}}
514; CHECK: br 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000515; CHECK-NEXT: .LBB13_3:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000516; CHECK-NEXT: end_block{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +0000517; CHECK-NEXT: block{{$}}
Dan Gohmand85ab7f2016-02-18 06:32:53 +0000518; CHECK: br_if 0, $pop{{[0-9]+}}{{$}}
519; CHECK: br_if 1, $pop{{[0-9]+}}{{$}}
520; CHECK-NEXT: .LBB13_5:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000521; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000522; CHECK-NEXT: return{{$}}
Dan Gohmand85ab7f2016-02-18 06:32:53 +0000523; CHECK-NEXT: .LBB13_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000524; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000525; CHECK-NEXT: return{{$}}
526; OPT-LABEL: test4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000527; OPT-NEXT: .param i32{{$}}
528; OPT: block{{$}}
529; OPT-NEXT: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000530; OPT: br_if 0, $pop{{[0-9]+}}{{$}}
Dan Gohmand85ab7f2016-02-18 06:32:53 +0000531; OPT: br_if 1, $pop{{[0-9]+}}{{$}}
532; OPT: br 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000533; OPT-NEXT: .LBB13_3:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000534; OPT-NEXT: end_block{{$}}
Dan Gohmand85ab7f2016-02-18 06:32:53 +0000535; 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-NEXT: .LBB13_5:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000539; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000540; OPT-NEXT: return{{$}}
Dan Gohmand85ab7f2016-02-18 06:32:53 +0000541; OPT-NEXT: .LBB13_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000542; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000543; OPT-NEXT: return{{$}}
544define void @test4(i32 %t) {
545entry:
546 switch i32 %t, label %default [
547 i32 0, label %bb2
548 i32 2, label %bb2
549 i32 4, label %bb1
550 i32 622, label %bb0
551 ]
552
553bb0:
554 ret void
555
556bb1:
557 ret void
558
559bb2:
560 ret void
561
562default:
563 ret void
564}
565
566; Test a case where the BLOCK needs to be placed before the LOOP in the
567; same basic block.
568
569; CHECK-LABEL: test5:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000570; CHECK: .LBB14_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000571; CHECK-NEXT: block{{$}}
572; CHECK-NEXT: loop{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000573; CHECK: br_if 2, {{[^,]+}}{{$}}
574; CHECK: br_if 0, {{[^,]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000575; CHECK-NEXT: end_loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000576; CHECK: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000577; CHECK-NEXT: .LBB14_4:
Dan Gohman8fe7e862015-12-14 22:51:54 +0000578; CHECK: return{{$}}
579; OPT-LABEL: test5:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000580; OPT: .LBB14_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000581; OPT-NEXT: block{{$}}
582; OPT-NEXT: loop{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000583; OPT: br_if 2, {{[^,]+}}{{$}}
584; OPT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000585; OPT-NEXT: end_loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000586; OPT: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000587; OPT-NEXT: .LBB14_4:
Dan Gohman8fe7e862015-12-14 22:51:54 +0000588; OPT: return{{$}}
589define void @test5(i1 %p, i1 %q) {
590entry:
591 br label %header
592
593header:
594 store volatile i32 0, i32* null
595 br i1 %p, label %more, label %alt
596
597more:
598 store volatile i32 1, i32* null
599 br i1 %q, label %header, label %return
600
601alt:
602 store volatile i32 2, i32* null
603 ret void
604
605return:
606 store volatile i32 3, i32* null
607 ret void
608}
609
610; Test an interesting case of a loop with multiple exits, which
611; aren't to layout successors of the loop, and one of which is to a successors
612; which has another predecessor.
613
614; CHECK-LABEL: test6:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000615; CHECK: .LBB15_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000616; CHECK-NEXT: block{{$}}
617; CHECK-NEXT: block{{$}}
618; CHECK-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000619; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000620; CHECK: br_if 3, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000621; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000622; CHECK: br_if 2, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000623; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000624; CHECK: br_if 0, {{[^,]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000625; CHECK-NEXT: end_loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000626; CHECK-NOT: block
627; CHECK: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000628; CHECK-NEXT: .LBB15_5:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000629; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000630; CHECK-NOT: block
Dan Gohmana4730cf2016-01-07 18:49:53 +0000631; CHECK: .LBB15_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000632; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000633; CHECK-NOT: block
634; CHECK: return{{$}}
635; OPT-LABEL: test6:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000636; OPT: .LBB15_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000637; OPT-NEXT: block{{$}}
638; OPT-NEXT: block{{$}}
639; OPT-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000640; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000641; OPT: br_if 3, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000642; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000643; OPT: br_if 2, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000644; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000645; OPT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000646; OPT-NEXT: end_loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000647; OPT-NOT: block
648; OPT: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000649; OPT-NEXT: .LBB15_5:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000650; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000651; OPT-NOT: block
Dan Gohmana4730cf2016-01-07 18:49:53 +0000652; OPT: .LBB15_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000653; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000654; OPT-NOT: block
655; OPT: return{{$}}
656define void @test6(i1 %p, i1 %q) {
657entry:
658 br label %header
659
660header:
661 store volatile i32 0, i32* null
662 br i1 %p, label %more, label %second
663
664more:
665 store volatile i32 1, i32* null
666 br i1 %q, label %evenmore, label %first
667
668evenmore:
669 store volatile i32 1, i32* null
670 br i1 %q, label %header, label %return
671
672return:
673 store volatile i32 2, i32* null
674 ret void
675
676first:
677 store volatile i32 3, i32* null
678 br label %second
679
680second:
681 store volatile i32 4, i32* null
682 ret void
683}
684
685; Test a case where there are multiple backedges and multiple loop exits
686; that end in unreachable.
687
688; CHECK-LABEL: test7:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000689; CHECK: .LBB16_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000690; CHECK-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000691; CHECK-NOT: block
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000692; CHECK: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000693; CHECK: br_if 0, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000694; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000695; CHECK: br_if 1, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000696; CHECK-NOT: block
697; CHECK: unreachable
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000698; CHECK-NEXT: .LBB16_4:
699; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000700; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000701; CHECK: br_if 0, {{[^,]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000702; CHECK-NEXT: end_loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000703; CHECK-NOT: block
704; CHECK: unreachable
705; OPT-LABEL: test7:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000706; OPT: .LBB16_1:
Dan Gohman442bfce2016-02-16 16:22:41 +0000707; OPT-NEXT: block
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000708; OPT-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000709; OPT-NOT: block
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000710; OPT: block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000711; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000712; OPT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000713; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000714; OPT: br_if 1, {{[^,]+}}{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +0000715; OPT: br 3{{$}}
716; OPT-NEXT: .LBB16_3:
717; OPT-NEXT: end_block
Dan Gohman8fe7e862015-12-14 22:51:54 +0000718; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000719; OPT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +0000720; OPT-NEXT: end_loop
721; OPT-NOT: block
722; OPT: unreachable
723; OPT-NEXT: .LBB16_5:
724; OPT-NEXT: end_block
Dan Gohman8fe7e862015-12-14 22:51:54 +0000725; OPT-NOT: block
726; OPT: unreachable
727define void @test7(i1 %tobool2, i1 %tobool9) {
728entry:
729 store volatile i32 0, i32* null
730 br label %loop
731
732loop:
733 store volatile i32 1, i32* null
734 br i1 %tobool2, label %l1, label %l0
735
736l0:
737 store volatile i32 2, i32* null
738 br i1 %tobool9, label %loop, label %u0
739
740l1:
741 store volatile i32 3, i32* null
742 br i1 %tobool9, label %loop, label %u1
743
744u0:
745 store volatile i32 4, i32* null
746 unreachable
747
748u1:
749 store volatile i32 5, i32* null
750 unreachable
751}
752
753; Test an interesting case using nested loops and switches.
754
755; CHECK-LABEL: test8:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000756; CHECK: .LBB17_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000757; CHECK-NEXT: loop{{$}}
Dan Gohmane5d3c152016-01-20 05:55:09 +0000758; CHECK-NEXT: i32.const $push{{[^,]+}}, 0{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000759; CHECK-NEXT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman0cfb5f82016-05-10 04:24:02 +0000760; CHECK-NEXT: br 0{{$}}
761; CHECK-NEXT: .LBB17_2:
762; CHECK-NEXT: end_loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000763; OPT-LABEL: test8:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000764; OPT: .LBB17_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000765; OPT-NEXT: loop{{$}}
Dan Gohmane5d3c152016-01-20 05:55:09 +0000766; OPT-NEXT: i32.const $push{{[^,]+}}, 0{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000767; OPT-NEXT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman0cfb5f82016-05-10 04:24:02 +0000768; OPT-NEXT: br 0{{$}}
769; OPT-NEXT: .LBB17_2:
770; OPT-NEXT: end_loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000771define i32 @test8() {
772bb:
773 br label %bb1
774
775bb1:
776 br i1 undef, label %bb2, label %bb3
777
778bb2:
779 switch i8 undef, label %bb1 [
780 i8 44, label %bb2
781 ]
782
783bb3:
784 switch i8 undef, label %bb1 [
785 i8 44, label %bb2
786 ]
787}
788
789; Test an interesting case using nested loops that share a bottom block.
790
791; CHECK-LABEL: test9:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000792; CHECK: .LBB18_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000793; CHECK-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000794; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000795; CHECK: br_if 1, {{[^,]+}}{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000796; CHECK-NEXT: .LBB18_2:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000797; CHECK-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000798; CHECK-NOT: block
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000799; CHECK: block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000800; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000801; CHECK: br_if 0, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000802; CHECK-NOT: block
Dan Gohmand85ab7f2016-02-18 06:32:53 +0000803; CHECK: br_if 3, {{[^,]+}}{{$}}
804; CHECK-NEXT: br 1{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000805; CHECK-NEXT: .LBB18_4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000806; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000807; CHECK-NOT: block
Dan Gohmand85ab7f2016-02-18 06:32:53 +0000808; CHECK: br_if 2, {{[^,]+}}{{$}}
809; CHECK-NEXT: br 0{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000810; CHECK-NEXT: .LBB18_5:
Dan Gohman8fe7e862015-12-14 22:51:54 +0000811; CHECK-NOT: block
812; CHECK: return{{$}}
813; OPT-LABEL: test9:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000814; OPT: .LBB18_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000815; OPT-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000816; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000817; OPT: br_if 1, {{[^,]+}}{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000818; OPT-NEXT: .LBB18_2:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000819; OPT-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000820; OPT-NOT: block
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000821; OPT: block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000822; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000823; OPT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000824; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000825; OPT: br_if 1, {{[^,]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000826; OPT-NEXT: br 3{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000827; OPT-NEXT: .LBB18_4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000828; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000829; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000830; OPT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000831; OPT-NEXT: br 2{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000832; OPT-NEXT: .LBB18_5:
Dan Gohman8fe7e862015-12-14 22:51:54 +0000833; OPT-NOT: block
834; OPT: return{{$}}
835declare i1 @a()
836define void @test9() {
837entry:
838 store volatile i32 0, i32* null
839 br label %header
840
841header:
842 store volatile i32 1, i32* null
843 %call4 = call i1 @a()
844 br i1 %call4, label %header2, label %end
845
846header2:
847 store volatile i32 2, i32* null
848 %call = call i1 @a()
849 br i1 %call, label %if.then, label %if.else
850
851if.then:
852 store volatile i32 3, i32* null
853 %call3 = call i1 @a()
854 br i1 %call3, label %header2, label %header
855
856if.else:
857 store volatile i32 4, i32* null
858 %call2 = call i1 @a()
859 br i1 %call2, label %header2, label %header
860
861end:
862 store volatile i32 5, i32* null
863 ret void
864}
865
866; Test an interesting case involving nested loops sharing a loop bottom,
867; and loop exits to a block with unreachable.
868
869; CHECK-LABEL: test10:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000870; CHECK: .LBB19_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000871; CHECK-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000872; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000873; CHECK: br_if 0, {{[^,]+}}{{$}}
JF Bastienc6ba5ea2016-04-05 17:01:52 +0000874; CHECK: .LBB19_3:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000875; CHECK-NEXT: block{{$}}
876; CHECK-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000877; CHECK-NOT: block
JF Bastienc6ba5ea2016-04-05 17:01:52 +0000878; CHECK: .LBB19_4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000879; CHECK-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000880; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000881; CHECK: br_if 5, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000882; CHECK-NOT: block
Dan Gohman14026062016-03-08 03:18:12 +0000883; CHECK: br_table {{[^,]+}}, 0, 1, 5, 2, 4, 0{{$}}
JF Bastienc6ba5ea2016-04-05 17:01:52 +0000884; CHECK-NEXT: .LBB19_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000885; CHECK-NEXT: end_loop{{$}}
886; CHECK-NEXT: end_loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000887; CHECK-NEXT: return{{$}}
JF Bastienc6ba5ea2016-04-05 17:01:52 +0000888; CHECK-NEXT: .LBB19_7:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000889; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000890; CHECK-NOT: block
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000891; CHECK: br 0{{$}}
JF Bastienc6ba5ea2016-04-05 17:01:52 +0000892; CHECK-NEXT: .LBB19_8:
Dan Gohman8fe7e862015-12-14 22:51:54 +0000893; OPT-LABEL: test10:
Dan Gohmana4730cf2016-01-07 18:49:53 +0000894; OPT: .LBB19_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000895; OPT-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000896; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000897; OPT: br_if 0, {{[^,]+}}{{$}}
JF Bastienc6ba5ea2016-04-05 17:01:52 +0000898; OPT: .LBB19_3:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000899; OPT-NEXT: block{{$}}
900; OPT-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000901; OPT-NOT: block
JF Bastienc6ba5ea2016-04-05 17:01:52 +0000902; OPT: .LBB19_4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000903; OPT-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000904; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000905; OPT: br_if 5, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000906; OPT-NOT: block
Dan Gohman14026062016-03-08 03:18:12 +0000907; OPT: br_table {{[^,]+}}, 0, 1, 5, 2, 4, 0{{$}}
JF Bastienc6ba5ea2016-04-05 17:01:52 +0000908; OPT-NEXT: .LBB19_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000909; OPT-NEXT: end_loop{{$}}
910; OPT-NEXT: end_loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000911; OPT-NEXT: return{{$}}
JF Bastienc6ba5ea2016-04-05 17:01:52 +0000912; OPT-NEXT: .LBB19_7:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000913; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000914; OPT-NOT: block
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000915; OPT: br 0{{$}}
JF Bastienc6ba5ea2016-04-05 17:01:52 +0000916; OPT-NEXT: .LBB19_8:
Dan Gohman8fe7e862015-12-14 22:51:54 +0000917define void @test10() {
918bb0:
919 br label %bb1
920
921bb1:
922 %tmp = phi i32 [ 2, %bb0 ], [ 3, %bb3 ]
923 %tmp3 = phi i32 [ undef, %bb0 ], [ %tmp11, %bb3 ]
924 %tmp4 = icmp eq i32 %tmp3, 0
925 br i1 %tmp4, label %bb4, label %bb2
926
927bb2:
928 br label %bb3
929
930bb3:
931 %tmp11 = phi i32 [ 1, %bb5 ], [ 0, %bb2 ]
932 br label %bb1
933
934bb4:
935 %tmp6 = phi i32 [ %tmp9, %bb5 ], [ 4, %bb1 ]
936 %tmp7 = phi i32 [ %tmp6, %bb5 ], [ %tmp, %bb1 ]
937 br label %bb5
938
939bb5:
940 %tmp9 = phi i32 [ %tmp6, %bb5 ], [ %tmp7, %bb4 ]
941 switch i32 %tmp9, label %bb2 [
942 i32 0, label %bb5
943 i32 1, label %bb6
944 i32 3, label %bb4
945 i32 4, label %bb3
946 ]
947
948bb6:
949 ret void
950}
951
952; Test a CFG DAG with interesting merging.
953
954; CHECK-LABEL: test11:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000955; CHECK: block{{$}}
956; CHECK-NEXT: block{{$}}
957; CHECK-NEXT: block{{$}}
958; CHECK-NEXT: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000959; CHECK: br_if 0, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000960; CHECK-NOT: block
Dan Gohmaned0f1132016-01-30 05:01:06 +0000961; CHECK: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000962; CHECK-NEXT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000963; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000964; CHECK: br_if 2, {{[^,]+}}{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000965; CHECK-NEXT: .LBB20_3:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000966; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000967; CHECK-NOT: block
968; CHECK: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000969; CHECK-NEXT: .LBB20_4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000970; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000971; CHECK-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000972; CHECK: br_if 1, {{[^,]+}}{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +0000973; CHECK-NOT: block
974; CHECK: br_if 2, {{[^,]+}}{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000975; CHECK-NEXT: .LBB20_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000976; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000977; CHECK-NOT: block
978; CHECK: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000979; CHECK-NEXT: .LBB20_7:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000980; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000981; CHECK-NOT: block
982; CHECK: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000983; CHECK-NEXT: .LBB20_8:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000984; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000985; CHECK-NOT: block
986; CHECK: return{{$}}
987; OPT-LABEL: test11:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000988; OPT: block{{$}}
989; OPT-NEXT: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000990; OPT: br_if 0, $pop{{[0-9]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000991; OPT-NOT: block
Dan Gohmaned0f1132016-01-30 05:01:06 +0000992; OPT: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +0000993; OPT-NEXT: br_if 0, $0{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000994; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +0000995; OPT: br_if 2, {{[^,]+}}{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +0000996; OPT-NEXT: .LBB20_3:
Dan Gohman1d68e80f2016-01-12 19:14:46 +0000997; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +0000998; OPT-NOT: block
999; OPT: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +00001000; OPT-NEXT: .LBB20_4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001001; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001002; OPT-NOT: block
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001003; OPT: block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001004; OPT-NOT: 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
1007; OPT: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +00001008; OPT-NEXT: .LBB20_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001009; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001010; OPT-NOT: block
Dan Gohman06b49582016-02-08 21:50:13 +00001011; OPT: br_if 0, $pop{{[0-9]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001012; OPT-NOT: block
1013; OPT: return{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +00001014; OPT-NEXT: .LBB20_8:
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{{$}}
1018define void @test11() {
1019bb0:
1020 store volatile i32 0, i32* null
1021 br i1 undef, label %bb1, label %bb4
1022bb1:
1023 store volatile i32 1, i32* null
1024 br i1 undef, label %bb3, label %bb2
1025bb2:
1026 store volatile i32 2, i32* null
1027 br i1 undef, label %bb3, label %bb7
1028bb3:
1029 store volatile i32 3, i32* null
1030 ret void
1031bb4:
1032 store volatile i32 4, i32* null
1033 br i1 undef, label %bb8, label %bb5
1034bb5:
1035 store volatile i32 5, i32* null
1036 br i1 undef, label %bb6, label %bb7
1037bb6:
1038 store volatile i32 6, i32* null
1039 ret void
1040bb7:
1041 store volatile i32 7, i32* null
1042 ret void
1043bb8:
1044 store volatile i32 8, i32* null
1045 ret void
1046}
1047
1048; CHECK-LABEL: test12:
Dan Gohmana4730cf2016-01-07 18:49:53 +00001049; CHECK: .LBB21_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001050; CHECK-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001051; CHECK-NOT: block
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001052; CHECK: block{{$}}
1053; CHECK-NEXT: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +00001054; CHECK: br_if 0, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001055; CHECK-NOT: block
Dan Gohman442bfce2016-02-16 16:22:41 +00001056; CHECK: br_if 1, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001057; CHECK-NOT: block
Dan Gohman442bfce2016-02-16 16:22:41 +00001058; CHECK: br_if 1, {{[^,]+}}{{$}}
1059; CHECK-NEXT: br 3{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +00001060; CHECK-NEXT: .LBB21_4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001061; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001062; CHECK-NOT: block
Dan Gohman442bfce2016-02-16 16:22:41 +00001063; CHECK: br_if 0, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001064; CHECK-NOT: block
Dan Gohman442bfce2016-02-16 16:22:41 +00001065; CHECK: br_if 2, {{[^,]+}}{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +00001066; CHECK-NEXT: .LBB21_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001067; CHECK-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001068; CHECK-NOT: block
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001069; CHECK: br 0{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +00001070; CHECK-NEXT: .LBB21_7:
1071; CHECK-NEXT: end_loop{{$}}
1072; CHECK-NEXT: return{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001073; OPT-LABEL: test12:
Dan Gohmana4730cf2016-01-07 18:49:53 +00001074; OPT: .LBB21_1:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001075; OPT-NEXT: loop{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001076; OPT-NOT: block
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001077; OPT: block{{$}}
1078; OPT-NEXT: block{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +00001079; OPT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001080; OPT-NOT: block
Dan Gohman442bfce2016-02-16 16:22:41 +00001081; OPT: br_if 1, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001082; OPT-NOT: block
Dan Gohman442bfce2016-02-16 16:22:41 +00001083; OPT: br_if 1, {{[^,]+}}{{$}}
1084; OPT-NEXT: br 3{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +00001085; OPT-NEXT: .LBB21_4:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001086; OPT-NEXT: end_block{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001087; OPT-NOT: block
Dan Gohman442bfce2016-02-16 16:22:41 +00001088; OPT: br_if 0, {{[^,]+}}{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001089; OPT-NOT: block
Dan Gohman442bfce2016-02-16 16:22:41 +00001090; OPT: br_if 2, {{[^,]+}}{{$}}
Dan Gohmana4730cf2016-01-07 18:49:53 +00001091; OPT-NEXT: .LBB21_6:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001092; OPT-NEXT: end_block{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001093; OPT: br 0{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +00001094; OPT-NEXT: .LBB21_7:
1095; OPT-NEXT: end_loop{{$}}
1096; OPT-NEXT: return{{$}}
Dan Gohman8fe7e862015-12-14 22:51:54 +00001097define void @test12(i8* %arg) {
1098bb:
1099 br label %bb1
1100
1101bb1:
1102 %tmp = phi i32 [ 0, %bb ], [ %tmp5, %bb4 ]
1103 %tmp2 = getelementptr i8, i8* %arg, i32 %tmp
1104 %tmp3 = load i8, i8* %tmp2
1105 switch i8 %tmp3, label %bb7 [
1106 i8 42, label %bb4
1107 i8 76, label %bb4
1108 i8 108, label %bb4
1109 i8 104, label %bb4
1110 ]
1111
1112bb4:
1113 %tmp5 = add i32 %tmp, 1
1114 br label %bb1
1115
1116bb7:
1117 ret void
1118}
Dan Gohmanb3aa1ec2015-12-16 19:06:41 +00001119
1120; A block can be "branched to" from another even if it is also reachable via
1121; fallthrough from the other. This would normally be optimized away, so use
1122; optnone to disable optimizations to test this case.
1123
1124; CHECK-LABEL: test13:
Dan Gohmanb6fd39a2016-01-19 16:59:23 +00001125; CHECK-NEXT: .local i32{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +00001126; CHECK-NEXT: block{{$}}
1127; CHECK-NEXT: block{{$}}
1128; CHECK: br_if 0, $pop0{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001129; CHECK: block{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +00001130; CHECK: br_if 0, $pop3{{$}}
1131; CHECK: .LBB22_3:
1132; CHECK-NEXT: end_block{{$}}
1133; CHECK: br_if 1, $pop{{[0-9]+}}{{$}}
1134; CHECK-NEXT: br 1{{$}}
1135; CHECK-NEXT: .LBB22_4:
1136; CHECK-NEXT: end_block{{$}}
Dan Gohmanb3aa1ec2015-12-16 19:06:41 +00001137; CHECK-NEXT: return{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +00001138; CHECK-NEXT: .LBB22_5:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001139; CHECK-NEXT: end_block{{$}}
Dan Gohmanb3aa1ec2015-12-16 19:06:41 +00001140; CHECK-NEXT: unreachable{{$}}
1141; OPT-LABEL: test13:
Dan Gohmanb6fd39a2016-01-19 16:59:23 +00001142; OPT-NEXT: .local i32{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +00001143; OPT-NEXT: block{{$}}
1144; OPT-NEXT: block{{$}}
1145; OPT: br_if 0, $pop0{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001146; OPT: block{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +00001147; OPT: br_if 0, $pop3{{$}}
1148; OPT: .LBB22_3:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001149; OPT-NEXT: end_block{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +00001150; OPT: br_if 1, $pop{{[0-9]+}}{{$}}
1151; OPT-NEXT: br 1{{$}}
1152; OPT-NEXT: .LBB22_4:
1153; OPT-NEXT: end_block
1154; OPT-NEXT: return
1155; OPT-NEXT: .LBB22_5:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001156; OPT-NEXT: end_block{{$}}
Dan Gohmanb3aa1ec2015-12-16 19:06:41 +00001157; OPT-NEXT: unreachable{{$}}
1158define void @test13() noinline optnone {
1159bb:
1160 br i1 undef, label %bb5, label %bb2
1161bb1:
1162 unreachable
1163bb2:
1164 br i1 undef, label %bb3, label %bb4
1165bb3:
1166 br label %bb4
1167bb4:
1168 %tmp = phi i1 [ false, %bb2 ], [ false, %bb3 ]
1169 br i1 %tmp, label %bb1, label %bb1
1170bb5:
1171 ret void
1172}
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001173
1174; Test a case with a single-block loop that has another loop
1175; as a successor. The end_loop for the first loop should go
1176; before the loop for the second.
1177
1178; CHECK-LABEL: test14:
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001179; CHECK-NEXT: .LBB23_1:{{$}}
1180; CHECK-NEXT: loop{{$}}
Dan Gohmanb6fd39a2016-01-19 16:59:23 +00001181; CHECK-NEXT: i32.const $push0=, 0{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +00001182; CHECK-NEXT: br_if 0, $pop0{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001183; CHECK-NEXT: end_loop{{$}}
Dan Gohman0cfb5f82016-05-10 04:24:02 +00001184; CHECK-NEXT: .LBB23_3:{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001185; CHECK-NEXT: loop{{$}}
Dan Gohmanb6fd39a2016-01-19 16:59:23 +00001186; CHECK-NEXT: i32.const $push1=, 0{{$}}
Dan Gohman06b49582016-02-08 21:50:13 +00001187; CHECK-NEXT: br_if 0, $pop1{{$}}
Dan Gohman1d68e80f2016-01-12 19:14:46 +00001188; CHECK-NEXT: end_loop{{$}}
1189; CHECK-NEXT: return{{$}}
1190define void @test14() {
1191bb:
1192 br label %bb1
1193
1194bb1:
1195 %tmp = bitcast i1 undef to i1
1196 br i1 %tmp, label %bb3, label %bb1
1197
1198bb3:
1199 br label %bb4
1200
1201bb4:
1202 br i1 undef, label %bb7, label %bb48
1203
1204bb7:
1205 br i1 undef, label %bb12, label %bb12
1206
1207bb12:
1208 br i1 undef, label %bb17, label %bb17
1209
1210bb17:
1211 br i1 undef, label %bb22, label %bb22
1212
1213bb22:
1214 br i1 undef, label %bb27, label %bb27
1215
1216bb27:
1217 br i1 undef, label %bb30, label %bb30
1218
1219bb30:
1220 br i1 undef, label %bb35, label %bb35
1221
1222bb35:
1223 br i1 undef, label %bb38, label %bb38
1224
1225bb38:
1226 br i1 undef, label %bb48, label %bb48
1227
1228bb48:
1229 %tmp49 = bitcast i1 undef to i1
1230 br i1 %tmp49, label %bb3, label %bb50
1231
1232bb50:
1233 ret void
1234}
Dan Gohmana187ab22016-02-12 21:19:25 +00001235
1236; Test that a block boundary which ends one block, begins another block, and
1237; also begins a loop, has the markers placed in the correct order.
1238
1239; CHECK-LABEL: test15:
1240; CHECK: block
Dan Gohmana187ab22016-02-12 21:19:25 +00001241; CHECK-NEXT: block
Dan Gohman442bfce2016-02-16 16:22:41 +00001242; CHECK: br_if 0, $pop{{.*}}{{$}}
Dan Gohmand85ab7f2016-02-18 06:32:53 +00001243; CHECK: .LBB24_2:
Dan Gohman442bfce2016-02-16 16:22:41 +00001244; CHECK-NEXT: block{{$}}
1245; CHECK-NEXT: loop{{$}}
1246; CHECK: br_if 1, $pop{{.*}}{{$}}
Dan Gohmand85ab7f2016-02-18 06:32:53 +00001247; CHECK: br_if 0, ${{.*}}{{$}}
1248; CHECK-NEXT: br 2{{$}}
1249; CHECK-NEXT: .LBB24_4:
Dan Gohman442bfce2016-02-16 16:22:41 +00001250; CHECK-NEXT: end_loop{{$}}
Dan Gohmand85ab7f2016-02-18 06:32:53 +00001251; CHECK: .LBB24_5:
Dan Gohman442bfce2016-02-16 16:22:41 +00001252; CHECK-NEXT: end_block{{$}}
1253; CHECK: br_if 1, $pop{{.*}}{{$}}
1254; CHECK: return{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +00001255; CHECK: .LBB24_7:
1256; CHECK-NEXT: end_block{{$}}
Dan Gohmand85ab7f2016-02-18 06:32:53 +00001257; CHECK: .LBB24_8:
1258; CHECK-NEXT: end_block{{$}}
Dan Gohman442bfce2016-02-16 16:22:41 +00001259; CHECK-NEXT: return{{$}}
Dan Gohmana187ab22016-02-12 21:19:25 +00001260; OPT-LABEL: test15:
1261; OPT: block
Dan Gohmand85ab7f2016-02-18 06:32:53 +00001262; OPT: block
Dan Gohmana187ab22016-02-12 21:19:25 +00001263; OPT-NEXT: i32.const $push
1264; OPT-NEXT: i32.const $push
1265; OPT-NEXT: i32.eq $push{{.*}}=, $pop{{.*}}, $pop{{.*}}{{$}}
1266; OPT-NEXT: br_if 0, $pop{{.*}}{{$}}
1267; OPT-NEXT: call test15_callee1@FUNCTION{{$}}
Dan Gohmand85ab7f2016-02-18 06:32:53 +00001268; OPT-NEXT: br 1{{$}}
Dan Gohmana187ab22016-02-12 21:19:25 +00001269; OPT-NEXT: .LBB24_2:
1270; OPT-NEXT: end_block
Dan Gohmand85ab7f2016-02-18 06:32:53 +00001271; OPT-NEXT: i32.const
1272; OPT-NEXT: .LBB24_3:
Dan Gohmana187ab22016-02-12 21:19:25 +00001273; OPT-NEXT: block
1274; OPT-NEXT: loop
1275%0 = type { i8, i32 }
1276declare void @test15_callee0()
1277declare void @test15_callee1()
1278define void @test15() {
1279bb:
1280 %tmp1 = icmp eq i8 1, 0
1281 br i1 %tmp1, label %bb2, label %bb14
1282
1283bb2:
1284 %tmp3 = phi %0** [ %tmp6, %bb5 ], [ null, %bb ]
1285 %tmp4 = icmp eq i32 0, 11
1286 br i1 %tmp4, label %bb5, label %bb8
1287
1288bb5:
1289 %tmp = bitcast i8* null to %0**
1290 %tmp6 = getelementptr %0*, %0** %tmp3, i32 1
1291 %tmp7 = icmp eq %0** %tmp6, null
1292 br i1 %tmp7, label %bb10, label %bb2
1293
1294bb8:
1295 %tmp9 = icmp eq %0** null, undef
1296 br label %bb10
1297
1298bb10:
1299 %tmp11 = phi %0** [ null, %bb8 ], [ %tmp, %bb5 ]
1300 %tmp12 = icmp eq %0** null, %tmp11
1301 br i1 %tmp12, label %bb15, label %bb13
1302
1303bb13:
1304 call void @test15_callee0()
1305 ret void
1306
1307bb14:
1308 call void @test15_callee1()
1309 ret void
1310
1311bb15:
1312 ret void
1313}