1 ; RUN: opt -lowerswitch -S < %s | FileCheck %s
3 ; Test that we don't crash and have a different basic block for each incoming edge.
6 ; CHECK: %merge = phi i64 [ 1, %BB3 ], [ 0, %NodeBlock5 ], [ 0, %LeafBlock1 ], [ 0, %NewDefault ]
8 switch i32 undef, label %BB2 [
17 %merge = phi i64 [ 1, %BB3 ], [ 0, %BB1 ], [ 0, %BB1 ], [ 0, %BB1 ]
24 ; Test switch cases that are merged into a single case during lowerswitch
25 ; (take 84 and 85 below) - check that the number of incoming phi values match
26 ; the number of branches.
27 define void @test1() {
33 switch i32 undef, label %bb1 [
46 ; CHECK: %tmp = phi i32 [ 1, %NodeBlock ], [ 0, %bb2 ], [ 1, %LeafBlock3 ]
47 %tmp = phi i32 [ 1, %bb1 ], [ 0, %bb2 ], [ 1, %bb1 ], [ 1, %bb1 ]
48 ; CHECK-NEXT: %tmp2 = phi i32 [ 2, %NodeBlock ], [ 5, %bb2 ], [ 2, %LeafBlock3 ]
49 %tmp2 = phi i32 [ 2, %bb1 ], [ 2, %bb1 ], [ 5, %bb2 ], [ 2, %bb1 ]
56 ; Test that we don't crash.
57 define void @test2(i32 %mode) {
59 br i1 undef, label %1, label %._crit_edge
61 ; <label>:1 ; preds = %0
62 switch i32 %mode, label %33 [
86 ; <label>:2 ; preds = %1
89 ; <label>:3 ; preds = %1
92 ; <label>:4 ; preds = %1
95 ; <label>:5 ; preds = %1
98 ; <label>:6 ; preds = %1
101 ; <label>:7 ; preds = %1
104 ; <label>:8 ; preds = %1
107 ; <label>:9 ; preds = %1
110 ; <label>:10 ; preds = %1
111 br i1 undef, label %11, label %12
113 ; <label>:11 ; preds = %10
116 ; <label>:12 ; preds = %10
119 ; <label>:13 ; preds = %12, %11
122 ; <label>:14 ; preds = %1
123 br i1 undef, label %15, label %16
125 ; <label>:15 ; preds = %14
128 ; <label>:16 ; preds = %14
131 ; <label>:17 ; preds = %16, %15
134 ; <label>:18 ; preds = %1
135 br i1 undef, label %19, label %20
137 ; <label>:19 ; preds = %18
140 ; <label>:20 ; preds = %18
143 ; <label>:21 ; preds = %20, %19
146 ; <label>:22 ; preds = %1
147 br i1 undef, label %23, label %24
149 ; <label>:23 ; preds = %22
152 ; <label>:24 ; preds = %22
155 ; <label>:25 ; preds = %24, %23
158 ; <label>:26 ; preds = %1
161 ; <label>:27 ; preds = %1
162 br i1 undef, label %28, label %29
164 ; <label>:28 ; preds = %27
167 ; <label>:29 ; preds = %27
170 ; <label>:30 ; preds = %29, %28
173 ; <label>:31 ; preds = %1
176 ; <label>:32 ; preds = %1
179 ; <label>:33 ; preds = %1
182 ; <label>:34 ; preds = %33, %32, %31, %30, %26, %25, %21, %17, %13, %9, %8, %7, %6, %5, %4, %3, %2, %1, %1, %1, %1, %1
183 %o.0 = phi float [ undef, %33 ], [ undef, %32 ], [ undef, %31 ], [ undef, %30 ], [ undef, %26 ], [ undef, %25 ], [ undef, %21 ], [ undef, %17 ], [ undef, %13 ], [ undef, %9 ], [ undef, %8 ], [ undef, %7 ], [ undef, %6 ], [ undef, %5 ], [ undef, %4 ], [ undef, %3 ], [ undef, %2 ], [ undef, %1 ], [ undef, %1 ], [ undef, %1 ], [ undef, %1 ], [ undef, %1 ]
184 br label %._crit_edge
186 ._crit_edge: ; preds = %34, %0
190 ; Test that the PHI node in for.cond should have one entry for each predecessor
191 ; of its parent basic block after lowerswitch merged several cases into a new
193 define void @test3() {
194 ; CHECK-LABEL: @test3
198 lbl1: ; preds = %cleanup, %entry
201 lbl2: ; preds = %cleanup, %lbl1
204 for.cond: ; preds = %cleanup, %cleanup, %lbl2
206 ; CHECK: phi i16 [ undef, %lbl2 ], [ %b.3, %NewDefault ]{{$}}
208 %b.2 = phi i16 [ undef, %lbl2 ], [ %b.3, %cleanup ], [ %b.3, %cleanup ]
211 for.cond1: ; preds = %for.inc, %for.cond
212 %b.3 = phi i16 [ %b.2, %for.cond ], [ undef, %for.inc ]
213 %tobool = icmp ne i16 %b.3, 0
214 br i1 %tobool, label %for.body, label %for.end
216 for.body: ; preds = %for.cond1
217 br i1 undef, label %if.then, label %for.inc
219 if.then: ; preds = %for.body
222 for.inc: ; preds = %for.body
225 for.end: ; preds = %for.cond1
226 br i1 undef, label %if.then4, label %for.body7
228 if.then4: ; preds = %for.end
231 for.body7: ; preds = %for.end
234 cleanup: ; preds = %for.body7, %if.then4, %if.then
235 switch i32 undef, label %unreachable [
236 i32 0, label %for.cond
238 i32 5, label %for.cond
242 unreachable: ; preds = %cleanup
246 ; Test that the PHI node in cleanup17 is removed as the switch default block is
248 define void @test4() {
249 ; CHECK-LABEL: @test4
251 switch i32 undef, label %cleanup17 [
258 ; CHECK-NOT: phi i16 [ undef, %entry ]
261 %retval.4 = phi i16 [ undef, %entry ]
268 ; Test that the PHI node in for.inc is updated correctly as the switch is
269 ; replaced with a single branch to for.inc
270 define void @test5() {
271 ; CHECK-LABEL: @test5
273 br i1 undef, label %cleanup10, label %cleanup10.thread
279 switch i32 undef, label %unreachable [
280 i32 0, label %for.inc
281 i32 4, label %for.inc
286 ; CHECK-NEXT: phi i16 [ 0, %cleanup10.thread ], [ undef, %cleanup10 ]
287 %0 = phi i16 [ undef, %cleanup10 ], [ 0, %cleanup10.thread ], [ undef, %cleanup10 ]