1 ; RUN: opt -simplifycfg -S -o - < %s | FileCheck %s
3 declare void @func2(i32)
4 declare void @func4(i32)
5 declare void @func6(i32)
6 declare void @func8(i32)
8 ;; test1 - create a switch with case 2 and case 4 from two branches: N == 2
10 define void @test1(i32 %N) nounwind uwtable {
12 %cmp = icmp eq i32 %N, 2
13 br i1 %cmp, label %if.then, label %if.else, !prof !0
15 ; CHECK: switch i32 %N
19 call void @func2(i32 %N) nounwind
23 %cmp2 = icmp eq i32 %N, 4
24 br i1 %cmp2, label %if.then7, label %if.else8, !prof !1
27 call void @func4(i32 %N) nounwind
31 call void @func8(i32 %N) nounwind
41 ;; test2 - Merge two switches where PredDefault == BB.
42 define void @test2(i32 %M, i32 %N) nounwind uwtable {
44 %cmp = icmp sgt i32 %M, 2
45 br i1 %cmp, label %sw1, label %sw2
48 switch i32 %N, label %sw2 [
53 ; CHECK: switch i32 %N, label %sw.epilog
54 ; CHECK: i32 2, label %sw.bb
55 ; CHECK: i32 3, label %sw.bb1
56 ; CHECK: i32 4, label %sw.bb5
60 call void @func2(i32 %N) nounwind
64 call void @func4(i32 %N) nounwind
68 ;; Here "case 2" is invalidated if control is transferred through default case
69 ;; of the first switch.
70 switch i32 %N, label %sw.epilog [
76 call void @func6(i32 %N) nounwind
80 call void @func8(i32 %N) nounwind
87 ;; test3 - Merge two switches where PredDefault != BB.
88 define void @test3(i32 %M, i32 %N) nounwind uwtable {
90 %cmp = icmp sgt i32 %M, 2
91 br i1 %cmp, label %sw1, label %sw2
94 switch i32 %N, label %sw.bb [
100 ; CHECK: switch i32 %N, label %sw.bb
101 ; CHECK: i32 1, label %sw.bb1
102 ; CHECK: i32 3, label %sw.bb4
103 ; CHECK: i32 2, label %sw.epilog
107 call void @func2(i32 %N) nounwind
111 call void @func4(i32 %N) nounwind
115 switch i32 %N, label %sw.epilog [
121 call void @func6(i32 %N) nounwind
125 call void @func8(i32 %N) nounwind
132 !0 = !{!"branch_weights", i32 64, i32 4}
133 !1 = !{!"branch_weights", i32 4, i32 64}
134 ; CHECK: !0 = !{!"branch_weights", i32 256, i32 4352, i32 16}
135 !2 = !{!"branch_weights", i32 4, i32 4, i32 8}
136 !3 = !{!"branch_weights", i32 8, i32 8, i32 4}
137 ; CHECK: !1 = !{!"branch_weights", i32 32, i32 48, i32 96, i32 16}
138 !4 = !{!"branch_weights", i32 7, i32 6, i32 4, i32 3}
139 !5 = !{!"branch_weights", i32 17, i32 13, i32 9}
140 ; CHECK: !3 = !{!"branch_weights", i32 7, i32 3, i32 4, i32 6}