1 ; RUN: llc < %s -asm-verbose=false -verify-machineinstrs -disable-block-placement -wasm-disable-explicit-locals -wasm-keep-registers | FileCheck %s
3 ; Test irreducible CFG handling.
5 target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
6 target triple = "wasm32-unknown-unknown"
8 ; A simple loop with two entries.
12 ; CHECK: i32.const $[[REG:[^,]+]]=
13 ; CHECK: br_table $[[REG]],
14 define void @test0(double* %arg, i32 %arg1, i32 %arg2, i32 %arg3) {
16 %tmp = icmp eq i32 %arg2, 0
17 br i1 %tmp, label %bb6, label %bb3
20 %tmp4 = getelementptr double, double* %arg, i32 %arg3
21 %tmp5 = load double, double* %tmp4, align 4
25 %tmp7 = phi i32 [ %tmp18, %bb13 ], [ 0, %bb ]
26 %tmp8 = icmp slt i32 %tmp7, %arg1
27 br i1 %tmp8, label %bb9, label %bb19
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
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
49 ; A simple loop with two entries and an inner natural loop.
53 ; CHECK: i32.const $[[REG:[^,]+]]=
54 ; CHECK: br_table $[[REG]],
55 define void @test1(double* %arg, i32 %arg1, i32 %arg2, i32 %arg3) {
57 %tmp = icmp eq i32 %arg2, 0
58 br i1 %tmp, label %bb6, label %bb3
61 %tmp4 = getelementptr double, double* %arg, i32 %arg3
62 %tmp5 = load double, double* %tmp4, align 4
66 %tmp7 = phi i32 [ %tmp18, %bb13 ], [ 0, %bb ]
67 %tmp8 = icmp slt i32 %tmp7, %arg1
68 br i1 %tmp8, label %bb9, label %bb19
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
78 %p = phi i32 [ 0, %bb9 ], [ %pn, %bb10 ]
80 %c = icmp slt i32 %pn, 256
81 br i1 %c, label %bb10, label %bb13
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
96 ; A simple loop 2 blocks that are both entries.
100 ; CHECK: i32.const $[[REG:[^,]+]]=
101 ; CHECK: br_table $[[REG]],
102 define internal i32 @test2(i32) noinline {
107 %a0a = tail call i32 @test2(i32 1)
108 %a0b = icmp eq i32 %a0a, 0
109 br i1 %a0b, label %A1, label %A2
112 %a1a = tail call i32 @test2(i32 2)
113 %a1b = icmp eq i32 %a1a, 0
114 br i1 %a1b, label %A1, label %A2
117 %a2a = tail call i32 @test2(i32 3)
118 %a2b = icmp eq i32 %a2a, 0
119 br i1 %a2b, label %A1, label %A2
122 ; An interesting loop with inner loop and if-else structure too.
124 ; CHECK-LABEL: test3:
126 define void @test3(i32 %ws) {
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
134 if.then: ; preds = %entry
137 if.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
142 if.then2: ; preds = %if.end
145 for.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
150 if.then4: ; preds = %for.cond
153 if.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
158 if.then7: ; preds = %if.end5
161 if.end8: ; preds = %if.end5
164 wynn: ; preds = %if.end8, %if.then
167 if.end9: ; preds = %if.end
171 ; Multi-level irreducibility, after reducing in the main scope we must then
172 ; reduce in the inner loop that we just created.
175 define void @pi_next() {
177 br i1 undef, label %sw.bb5, label %return
179 sw.bb5: ; preds = %entry
180 br i1 undef, label %if.then.i49, label %if.else.i52
182 if.then.i49: ; preds = %sw.bb5
183 br label %for.inc197.i
185 if.else.i52: ; preds = %sw.bb5
186 br label %for.cond57.i
188 for.cond57.i: ; preds = %for.inc205.i, %if.else.i52
189 store i32 0, i32* undef, align 4
190 br label %for.cond65.i
192 for.cond65.i: ; preds = %for.inc201.i, %for.cond57.i
193 br i1 undef, label %for.body70.i, label %for.inc205.i
195 for.body70.i: ; preds = %for.cond65.i
196 br label %for.cond76.i
198 for.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
203 for.body82.i: ; preds = %for.cond76.i
204 br label %for.inc197.i
206 for.inc197.i: ; preds = %for.body82.i, %if.then.i49
207 %inc199.i = add nsw i32 undef, 1
208 br label %for.cond76.i
210 for.inc201.i: ; preds = %for.cond76.i
211 br label %for.cond65.i
213 for.inc205.i: ; preds = %for.cond65.i
214 br label %for.cond57.i
216 return: ; preds = %entry