blob: 9d1ef58796b196d43f7b386eb610ee4f3b0501df [file] [log] [blame]
Dan Gohman950a13c2015-09-16 16:51:30 +00001; RUN: llc < %s -asm-verbose=false | FileCheck %s
2
3; Test the CFG stackifier pass.
4
5target datalayout = "e-p:32:32-i64:64-n32:64-S128"
6target triple = "wasm32-unknown-unknown"
7
8declare void @something()
9
10; Test that loops are made contiguous, even in the presence of split backedges.
11
Dan Gohmane51c0582015-10-06 00:27:55 +000012; CHECK-LABEL: test0:
13; CHECK: loop
Dan Gohman3cb66c82015-11-06 21:32:42 +000014; CHECK: i32.add
JF Bastien3b0177c2015-10-20 00:37:42 +000015; CHECK: br_if
Dan Gohmane51c0582015-10-06 00:27:55 +000016; CHECK: call
Dan Gohmancf4748f2015-11-12 17:04:33 +000017; CHECK: br BB0_1{{$}}
Dan Gohmane51c0582015-10-06 00:27:55 +000018; CHECK: return{{$}}
Dan Gohman950a13c2015-09-16 16:51:30 +000019define void @test0(i32 %n) {
20entry:
21 br label %header
22
23header:
24 %i = phi i32 [ 0, %entry ], [ %i.next, %back ]
25 %i.next = add i32 %i, 1
26
27 %c = icmp slt i32 %i.next, %n
28 br i1 %c, label %back, label %exit
29
30exit:
31 ret void
32
33back:
34 call void @something()
35 br label %header
36}
37
38; Same as test0, but the branch condition is reversed.
39
Dan Gohmane51c0582015-10-06 00:27:55 +000040; CHECK-LABEL: test1:
41; CHECK: loop
Dan Gohman3cb66c82015-11-06 21:32:42 +000042; CHECK: i32.add
JF Bastien3b0177c2015-10-20 00:37:42 +000043; CHECK: br_if
Dan Gohmane51c0582015-10-06 00:27:55 +000044; CHECK: call
Dan Gohmancf4748f2015-11-12 17:04:33 +000045; CHECK: br BB1_1{{$}}
Dan Gohmane51c0582015-10-06 00:27:55 +000046; CHECK: return{{$}}
Dan Gohman950a13c2015-09-16 16:51:30 +000047define void @test1(i32 %n) {
48entry:
49 br label %header
50
51header:
52 %i = phi i32 [ 0, %entry ], [ %i.next, %back ]
53 %i.next = add i32 %i, 1
54
55 %c = icmp sge i32 %i.next, %n
56 br i1 %c, label %exit, label %back
57
58exit:
59 ret void
60
61back:
62 call void @something()
63 br label %header
64}
65
66; Test that a simple loop is handled as expected.
67
Dan Gohmane51c0582015-10-06 00:27:55 +000068; CHECK-LABEL: test2:
Dan Gohmancf4748f2015-11-12 17:04:33 +000069; CHECK: block BB2_2{{$}}
Derek Schuff4ed47782015-11-16 21:04:51 +000070; CHECK: br_if {{.*}}, BB2_2{{$}}
Dan Gohman950a13c2015-09-16 16:51:30 +000071; CHECK: BB2_1:
Dan Gohman4ba48162015-11-18 16:12:01 +000072; CHECK: br_if $pop{{[0-9]+}}, BB2_1{{$}}
Dan Gohman950a13c2015-09-16 16:51:30 +000073; CHECK: BB2_2:
Dan Gohmane51c0582015-10-06 00:27:55 +000074; CHECK: return{{$}}
Dan Gohman950a13c2015-09-16 16:51:30 +000075define void @test2(double* nocapture %p, i32 %n) {
76entry:
77 %cmp.4 = icmp sgt i32 %n, 0
78 br i1 %cmp.4, label %for.body.preheader, label %for.end
79
80for.body.preheader:
81 br label %for.body
82
83for.body:
84 %i.05 = phi i32 [ %inc, %for.body ], [ 0, %for.body.preheader ]
85 %arrayidx = getelementptr inbounds double, double* %p, i32 %i.05
86 %0 = load double, double* %arrayidx, align 8
87 %mul = fmul double %0, 3.200000e+00
88 store double %mul, double* %arrayidx, align 8
89 %inc = add nuw nsw i32 %i.05, 1
90 %exitcond = icmp eq i32 %inc, %n
91 br i1 %exitcond, label %for.end.loopexit, label %for.body
92
93for.end.loopexit:
94 br label %for.end
95
96for.end:
97 ret void
98}
99
Dan Gohmane51c0582015-10-06 00:27:55 +0000100; CHECK-LABEL: doublediamond:
Dan Gohmancf4748f2015-11-12 17:04:33 +0000101; CHECK: block BB3_5{{$}}
102; CHECK: block BB3_4{{$}}
103; CHECK: block BB3_2{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +0000104; CHECK: br_if $pop{{[0-9]+}}, BB3_2{{$}}
105; CHECK: br_if $pop{{[0-9]+}}, BB3_4{{$}}
Dan Gohmancf4748f2015-11-12 17:04:33 +0000106; CHECK: br BB3_5{{$}}
Dan Gohman950a13c2015-09-16 16:51:30 +0000107; CHECK: BB3_4:
108; CHECK: BB3_5:
Dan Gohman4ba48162015-11-18 16:12:01 +0000109; CHECK: return ${{[0-9]+}}{{$}}
Dan Gohman950a13c2015-09-16 16:51:30 +0000110define i32 @doublediamond(i32 %a, i32 %b, i32* %p) {
111entry:
112 %c = icmp eq i32 %a, 0
113 %d = icmp eq i32 %b, 0
114 store volatile i32 0, i32* %p
115 br i1 %c, label %true, label %false
116true:
117 store volatile i32 1, i32* %p
118 br label %exit
119false:
120 store volatile i32 2, i32* %p
121 br i1 %d, label %ft, label %ff
122ft:
123 store volatile i32 3, i32* %p
124 br label %exit
125ff:
126 store volatile i32 4, i32* %p
127 br label %exit
128exit:
129 store volatile i32 5, i32* %p
130 ret i32 0
131}
132
Dan Gohmane51c0582015-10-06 00:27:55 +0000133; CHECK-LABEL: triangle:
Dan Gohmancf4748f2015-11-12 17:04:33 +0000134; CHECK: block BB4_2{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +0000135; CHECK: br_if $pop{{[0-9]+}}, BB4_2{{$}}
Dan Gohman950a13c2015-09-16 16:51:30 +0000136; CHECK: BB4_2:
Dan Gohman4ba48162015-11-18 16:12:01 +0000137; CHECK: return ${{[0-9]+}}{{$}}
Dan Gohman950a13c2015-09-16 16:51:30 +0000138define i32 @triangle(i32* %p, i32 %a) {
139entry:
140 %c = icmp eq i32 %a, 0
141 store volatile i32 0, i32* %p
142 br i1 %c, label %true, label %exit
143true:
144 store volatile i32 1, i32* %p
145 br label %exit
146exit:
147 store volatile i32 2, i32* %p
148 ret i32 0
149}
150
Dan Gohmane51c0582015-10-06 00:27:55 +0000151; CHECK-LABEL: diamond:
Dan Gohmancf4748f2015-11-12 17:04:33 +0000152; CHECK: block BB5_3{{$}}
153; CHECK: block BB5_2{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +0000154; CHECK: br_if $pop{{[0-9]+}}, BB5_2{{$}}
Dan Gohmancf4748f2015-11-12 17:04:33 +0000155; CHECK: br BB5_3{{$}}
Dan Gohman950a13c2015-09-16 16:51:30 +0000156; CHECK: BB5_2:
157; CHECK: BB5_3:
Dan Gohman4ba48162015-11-18 16:12:01 +0000158; CHECK: return ${{[0-9]+}}{{$}}
Dan Gohman950a13c2015-09-16 16:51:30 +0000159define i32 @diamond(i32* %p, i32 %a) {
160entry:
161 %c = icmp eq i32 %a, 0
162 store volatile i32 0, i32* %p
163 br i1 %c, label %true, label %false
164true:
165 store volatile i32 1, i32* %p
166 br label %exit
167false:
168 store volatile i32 2, i32* %p
169 br label %exit
170exit:
171 store volatile i32 3, i32* %p
172 ret i32 0
173}
174
Dan Gohmane51c0582015-10-06 00:27:55 +0000175; CHECK-LABEL: single_block:
Dan Gohman950a13c2015-09-16 16:51:30 +0000176; CHECK-NOT: br
Dan Gohman4ba48162015-11-18 16:12:01 +0000177; CHECK: return ${{[0-9]+}}{{$}}
Dan Gohman950a13c2015-09-16 16:51:30 +0000178define i32 @single_block(i32* %p) {
179entry:
180 store volatile i32 0, i32* %p
181 ret i32 0
182}
183
Dan Gohmane51c0582015-10-06 00:27:55 +0000184; CHECK-LABEL: minimal_loop:
Dan Gohman950a13c2015-09-16 16:51:30 +0000185; CHECK-NOT: br
186; CHECK: BB7_1:
Dan Gohman4ba48162015-11-18 16:12:01 +0000187; CHECK: i32.store $0, $pop{{[0-9]+}}{{$}}
Dan Gohmancf4748f2015-11-12 17:04:33 +0000188; CHECK: br BB7_1{{$}}
Dan Gohman950a13c2015-09-16 16:51:30 +0000189define i32 @minimal_loop(i32* %p) {
190entry:
191 store volatile i32 0, i32* %p
192 br label %loop
193loop:
194 store volatile i32 1, i32* %p
195 br label %loop
196}
197
Dan Gohmane51c0582015-10-06 00:27:55 +0000198; CHECK-LABEL: simple_loop:
Dan Gohman950a13c2015-09-16 16:51:30 +0000199; CHECK-NOT: br
200; CHECK: BB8_1:
Dan Gohmancf4748f2015-11-12 17:04:33 +0000201; CHECK: loop BB8_2{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +0000202; CHECK: br_if $pop{{[0-9]+}}, BB8_1{{$}}
203; CHECK: return ${{[0-9]+}}{{$}}
Dan Gohman950a13c2015-09-16 16:51:30 +0000204define i32 @simple_loop(i32* %p, i32 %a) {
205entry:
206 %c = icmp eq i32 %a, 0
207 store volatile i32 0, i32* %p
208 br label %loop
209loop:
210 store volatile i32 1, i32* %p
211 br i1 %c, label %loop, label %exit
212exit:
213 store volatile i32 2, i32* %p
214 ret i32 0
215}
216
Dan Gohmane51c0582015-10-06 00:27:55 +0000217; CHECK-LABEL: doubletriangle:
Dan Gohmancf4748f2015-11-12 17:04:33 +0000218; CHECK: block BB9_4{{$}}
219; CHECK: block BB9_3{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +0000220; CHECK: br_if $pop{{[0-9]+}}, BB9_4{{$}}
221; CHECK: br_if $pop{{[0-9]+}}, BB9_3{{$}}
Dan Gohman950a13c2015-09-16 16:51:30 +0000222; CHECK: BB9_3:
223; CHECK: BB9_4:
Dan Gohman4ba48162015-11-18 16:12:01 +0000224; CHECK: return ${{[0-9]+}}{{$}}
Dan Gohman950a13c2015-09-16 16:51:30 +0000225define i32 @doubletriangle(i32 %a, i32 %b, i32* %p) {
226entry:
227 %c = icmp eq i32 %a, 0
228 %d = icmp eq i32 %b, 0
229 store volatile i32 0, i32* %p
230 br i1 %c, label %true, label %exit
231true:
232 store volatile i32 2, i32* %p
233 br i1 %d, label %tt, label %tf
234tt:
235 store volatile i32 3, i32* %p
236 br label %tf
237tf:
238 store volatile i32 4, i32* %p
239 br label %exit
240exit:
241 store volatile i32 5, i32* %p
242 ret i32 0
243}
244
Dan Gohmane51c0582015-10-06 00:27:55 +0000245; CHECK-LABEL: ifelse_earlyexits:
Dan Gohmancf4748f2015-11-12 17:04:33 +0000246; CHECK: block BB10_4{{$}}
247; CHECK: block BB10_2{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +0000248; CHECK: br_if $pop{{[0-9]+}}, BB10_2{{$}}
Dan Gohmancf4748f2015-11-12 17:04:33 +0000249; CHECK: br BB10_4{{$}}
Dan Gohman950a13c2015-09-16 16:51:30 +0000250; CHECK: BB10_2:
Dan Gohman4ba48162015-11-18 16:12:01 +0000251; CHECK: br_if $pop{{[0-9]+}}, BB10_4{{$}}
Dan Gohman950a13c2015-09-16 16:51:30 +0000252; CHECK: BB10_4:
Dan Gohman4ba48162015-11-18 16:12:01 +0000253; CHECK: return ${{[0-9]+}}{{$}}
Dan Gohman950a13c2015-09-16 16:51:30 +0000254define i32 @ifelse_earlyexits(i32 %a, i32 %b, i32* %p) {
255entry:
256 %c = icmp eq i32 %a, 0
257 %d = icmp eq i32 %b, 0
258 store volatile i32 0, i32* %p
259 br i1 %c, label %true, label %false
260true:
261 store volatile i32 1, i32* %p
262 br label %exit
263false:
264 store volatile i32 2, i32* %p
265 br i1 %d, label %ft, label %exit
266ft:
267 store volatile i32 3, i32* %p
268 br label %exit
269exit:
270 store volatile i32 4, i32* %p
271 ret i32 0
272}
Dan Gohmane3e4a5f2015-10-02 21:11:36 +0000273
274; Test that nested loops are handled.
275
276declare void @bar()
277
278define void @test3(i32 %w) {
279entry:
280 br i1 undef, label %outer.ph, label %exit
281
282outer.ph:
283 br label %outer
284
285outer:
286 %tobool = icmp eq i32 undef, 0
287 br i1 %tobool, label %inner, label %unreachable
288
289unreachable:
290 unreachable
291
292inner:
293 %c = icmp eq i32 undef, %w
294 br i1 %c, label %if.end, label %inner
295
296exit:
297 ret void
298
299if.end:
300 call void @bar()
301 br label %outer
302}