blob: 8eb0a6f592220e2464bfc110776fcc9817ae3207 [file] [log] [blame]
Wouter van Oortmerssen8a9cb242018-08-27 15:45:51 +00001; RUN: llc < %s -asm-verbose=false -verify-machineinstrs -disable-block-placement -wasm-disable-explicit-locals -wasm-keep-registers | FileCheck %s
Dan Gohmand7a2eea2016-03-09 02:01:14 +00002
3; Test irreducible CFG handling.
4
5target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
Sam Clegga5908002018-05-10 17:49:11 +00006target triple = "wasm32-unknown-unknown"
Dan Gohmand7a2eea2016-03-09 02:01:14 +00007
8; A simple loop with two entries.
9
10; CHECK-LABEL: test0:
Dan Gohmanf4562902016-04-26 01:40:56 +000011; CHECK: f64.load
Heejin Ahn777d01c2019-01-03 23:10:11 +000012; CHECK: i32.const $[[REG:[^,]+]]=
Dan Gohmanf4562902016-04-26 01:40:56 +000013; CHECK: br_table $[[REG]],
Dan Gohmand7a2eea2016-03-09 02:01:14 +000014define void @test0(double* %arg, i32 %arg1, i32 %arg2, i32 %arg3) {
15bb:
16 %tmp = icmp eq i32 %arg2, 0
17 br i1 %tmp, label %bb6, label %bb3
18
19bb3:
20 %tmp4 = getelementptr double, double* %arg, i32 %arg3
21 %tmp5 = load double, double* %tmp4, align 4
22 br label %bb13
23
24bb6:
25 %tmp7 = phi i32 [ %tmp18, %bb13 ], [ 0, %bb ]
26 %tmp8 = icmp slt i32 %tmp7, %arg1
27 br i1 %tmp8, label %bb9, label %bb19
28
29bb9:
30 %tmp10 = getelementptr double, double* %arg, i32 %tmp7
31 %tmp11 = load double, double* %tmp10, align 4
32 %tmp12 = fmul double %tmp11, 2.300000e+00
33 store double %tmp12, double* %tmp10, align 4
34 br label %bb13
35
36bb13:
37 %tmp14 = phi double [ %tmp5, %bb3 ], [ %tmp12, %bb9 ]
38 %tmp15 = phi i32 [ undef, %bb3 ], [ %tmp7, %bb9 ]
39 %tmp16 = getelementptr double, double* %arg, i32 %tmp15
40 %tmp17 = fadd double %tmp14, 1.300000e+00
41 store double %tmp17, double* %tmp16, align 4
42 %tmp18 = add nsw i32 %tmp15, 1
43 br label %bb6
44
45bb19:
46 ret void
47}
48
49; A simple loop with two entries and an inner natural loop.
50
51; CHECK-LABEL: test1:
Dan Gohmanf4562902016-04-26 01:40:56 +000052; CHECK: f64.load
Heejin Ahn777d01c2019-01-03 23:10:11 +000053; CHECK: i32.const $[[REG:[^,]+]]=
Dan Gohmanf4562902016-04-26 01:40:56 +000054; CHECK: br_table $[[REG]],
Dan Gohmand7a2eea2016-03-09 02:01:14 +000055define void @test1(double* %arg, i32 %arg1, i32 %arg2, i32 %arg3) {
56bb:
57 %tmp = icmp eq i32 %arg2, 0
58 br i1 %tmp, label %bb6, label %bb3
59
60bb3:
61 %tmp4 = getelementptr double, double* %arg, i32 %arg3
62 %tmp5 = load double, double* %tmp4, align 4
63 br label %bb13
64
65bb6:
66 %tmp7 = phi i32 [ %tmp18, %bb13 ], [ 0, %bb ]
67 %tmp8 = icmp slt i32 %tmp7, %arg1
68 br i1 %tmp8, label %bb9, label %bb19
69
70bb9:
71 %tmp10 = getelementptr double, double* %arg, i32 %tmp7
72 %tmp11 = load double, double* %tmp10, align 4
73 %tmp12 = fmul double %tmp11, 2.300000e+00
74 store double %tmp12, double* %tmp10, align 4
75 br label %bb10
76
77bb10:
78 %p = phi i32 [ 0, %bb9 ], [ %pn, %bb10 ]
79 %pn = add i32 %p, 1
80 %c = icmp slt i32 %pn, 256
81 br i1 %c, label %bb10, label %bb13
82
83bb13:
84 %tmp14 = phi double [ %tmp5, %bb3 ], [ %tmp12, %bb10 ]
85 %tmp15 = phi i32 [ undef, %bb3 ], [ %tmp7, %bb10 ]
86 %tmp16 = getelementptr double, double* %arg, i32 %tmp15
87 %tmp17 = fadd double %tmp14, 1.300000e+00
88 store double %tmp17, double* %tmp16, align 4
89 %tmp18 = add nsw i32 %tmp15, 1
90 br label %bb6
91
92bb19:
93 ret void
94}
Heejin Ahn777d01c2019-01-03 23:10:11 +000095
96; A simple loop 2 blocks that are both entries.
97
98; CHECK-LABEL: test2:
99; CHECK: br_if
100; CHECK: i32.const $[[REG:[^,]+]]=
101; CHECK: br_table $[[REG]],
102define internal i32 @test2(i32) noinline {
103entry:
104 br label %A0
105
106A0:
107 %a0a = tail call i32 @test2(i32 1)
108 %a0b = icmp eq i32 %a0a, 0
109 br i1 %a0b, label %A1, label %A2
110
111A1:
112 %a1a = tail call i32 @test2(i32 2)
113 %a1b = icmp eq i32 %a1a, 0
114 br i1 %a1b, label %A1, label %A2
115
116A2:
117 %a2a = tail call i32 @test2(i32 3)
118 %a2b = icmp eq i32 %a2a, 0
119 br i1 %a2b, label %A1, label %A2
120}
121
122; An interesting loop with inner loop and if-else structure too.
123
124; CHECK-LABEL: test3:
125; CHECK: br_if
126define void @test3(i32 %ws) {
127entry:
128 %ws.addr = alloca i32, align 4
129 store volatile i32 %ws, i32* %ws.addr, align 4
130 %0 = load volatile i32, i32* %ws.addr, align 4
131 %tobool = icmp ne i32 %0, 0
132 br i1 %tobool, label %if.then, label %if.end
133
134if.then: ; preds = %entry
135 br label %wynn
136
137if.end: ; preds = %entry
138 %1 = load volatile i32, i32* %ws.addr, align 4
139 %tobool1 = icmp ne i32 %1, 0
140 br i1 %tobool1, label %if.end9, label %if.then2
141
142if.then2: ; preds = %if.end
143 br label %for.cond
144
145for.cond: ; preds = %wynn, %if.then7, %if.then2
146 %2 = load volatile i32, i32* %ws.addr, align 4
147 %tobool3 = icmp ne i32 %2, 0
148 br i1 %tobool3, label %if.then4, label %if.end5
149
150if.then4: ; preds = %for.cond
151 br label %if.end5
152
153if.end5: ; preds = %if.then4, %for.cond
154 %3 = load volatile i32, i32* %ws.addr, align 4
155 %tobool6 = icmp ne i32 %3, 0
156 br i1 %tobool6, label %if.then7, label %if.end8
157
158if.then7: ; preds = %if.end5
159 br label %for.cond
160
161if.end8: ; preds = %if.end5
162 br label %wynn
163
164wynn: ; preds = %if.end8, %if.then
165 br label %for.cond
166
167if.end9: ; preds = %if.end
168 ret void
169}
170
171; Multi-level irreducibility, after reducing in the main scope we must then
172; reduce in the inner loop that we just created.
173; CHECK: br_table
174; CHECK: br_table
175define void @pi_next() {
176entry:
177 br i1 undef, label %sw.bb5, label %return
178
179sw.bb5: ; preds = %entry
180 br i1 undef, label %if.then.i49, label %if.else.i52
181
182if.then.i49: ; preds = %sw.bb5
183 br label %for.inc197.i
184
185if.else.i52: ; preds = %sw.bb5
186 br label %for.cond57.i
187
188for.cond57.i: ; preds = %for.inc205.i, %if.else.i52
189 store i32 0, i32* undef, align 4
190 br label %for.cond65.i
191
192for.cond65.i: ; preds = %for.inc201.i, %for.cond57.i
193 br i1 undef, label %for.body70.i, label %for.inc205.i
194
195for.body70.i: ; preds = %for.cond65.i
196 br label %for.cond76.i
197
198for.cond76.i: ; preds = %for.inc197.i, %for.body70.i
199 %0 = phi i32 [ %inc199.i, %for.inc197.i ], [ 0, %for.body70.i ]
200 %cmp81.i = icmp slt i32 %0, 0
201 br i1 %cmp81.i, label %for.body82.i, label %for.inc201.i
202
203for.body82.i: ; preds = %for.cond76.i
204 br label %for.inc197.i
205
206for.inc197.i: ; preds = %for.body82.i, %if.then.i49
207 %inc199.i = add nsw i32 undef, 1
208 br label %for.cond76.i
209
210for.inc201.i: ; preds = %for.cond76.i
211 br label %for.cond65.i
212
213for.inc205.i: ; preds = %for.cond65.i
214 br label %for.cond57.i
215
216return: ; preds = %entry
217 ret void
218}
219