1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -passes=ipsccp < %s | FileCheck %s
4 ; Make sure we always consider the default edge executable for a switch
9 ; CHECK-NEXT: switch i32 undef, label [[D:%.*]] [
12 ; CHECK-NEXT: call void @foo()
13 ; CHECK-NEXT: ret void
15 switch i32 undef, label %d []
21 define i32 @test_duplicate_successors_phi(i1 %c, i32 %x) {
22 ; CHECK-LABEL: @test_duplicate_successors_phi(
24 ; CHECK-NEXT: br i1 [[C:%.*]], label [[SWITCH:%.*]], label [[END:%.*]]
26 ; CHECK-NEXT: br label [[SWITCH_DEFAULT:%.*]]
27 ; CHECK: switch.default:
28 ; CHECK-NEXT: ret i32 -1
30 ; CHECK-NEXT: ret i32 [[X:%.*]]
33 br i1 %c, label %switch, label %end
36 switch i32 -1, label %switch.default [
45 %phi = phi i32 [ %x, %entry ], [ 1, %switch ], [ 1, %switch ]
49 define i32 @test_duplicate_successors_phi_2(i1 %c, i32 %x) {
50 ; CHECK-LABEL: @test_duplicate_successors_phi_2(
52 ; CHECK-NEXT: br i1 [[C:%.*]], label [[SWITCH:%.*]], label [[END:%.*]]
54 ; CHECK-NEXT: br label [[END]]
56 ; CHECK-NEXT: [[PHI:%.*]] = phi i32 [ [[X:%.*]], [[ENTRY:%.*]] ], [ 1, [[SWITCH]] ]
57 ; CHECK-NEXT: ret i32 [[PHI]]
60 br i1 %c, label %switch, label %end
63 switch i32 0, label %switch.default [
72 %phi = phi i32 [ %x, %entry ], [ 1, %switch ], [ 1, %switch ]
76 define i32 @test_duplicate_successors_phi_3(i1 %c1, i32* %p, i32 %y) {
77 ; CHECK-LABEL: @test_duplicate_successors_phi_3(
79 ; CHECK-NEXT: br i1 [[C1:%.*]], label [[SWITCH:%.*]], label [[SWITCH_1:%.*]]
81 ; CHECK-NEXT: [[X:%.*]] = load i32, i32* [[P:%.*]], align 4, !range !0
82 ; CHECK-NEXT: switch i32 [[X]], label [[SWITCH_DEFAULT:%.*]] [
83 ; CHECK-NEXT: i32 0, label [[SWITCH_DEFAULT]]
84 ; CHECK-NEXT: i32 1, label [[SWITCH_0:%.*]]
85 ; CHECK-NEXT: i32 2, label [[SWITCH_0]]
87 ; CHECK: switch.default:
88 ; CHECK-NEXT: ret i32 -1
90 ; CHECK-NEXT: ret i32 0
92 ; CHECK-NEXT: ret i32 [[Y:%.*]]
95 br i1 %c1, label %switch, label %switch.1
98 %x = load i32, i32* %p, !range !{i32 0, i32 3}
99 switch i32 %x, label %switch.default [
100 i32 0, label %switch.default
101 i32 1, label %switch.0
102 i32 2, label %switch.0
103 i32 3, label %switch.1
104 i32 4, label %switch.1
114 %phi = phi i32 [ %y, %entry ], [ 0, %switch ], [ 0, %switch ]
118 ; TODO: Determine that the default destination is dead.
119 define i32 @test_local_range(i32* %p) {
120 ; CHECK-LABEL: @test_local_range(
121 ; CHECK-NEXT: [[X:%.*]] = load i32, i32* [[P:%.*]], align 4, !range !0
122 ; CHECK-NEXT: switch i32 [[X]], label [[SWITCH_DEFAULT:%.*]] [
123 ; CHECK-NEXT: i32 0, label [[SWITCH_0:%.*]]
124 ; CHECK-NEXT: i32 1, label [[SWITCH_1:%.*]]
125 ; CHECK-NEXT: i32 2, label [[SWITCH_2:%.*]]
127 ; CHECK: switch.default:
128 ; CHECK-NEXT: ret i32 -1
130 ; CHECK-NEXT: ret i32 0
132 ; CHECK-NEXT: ret i32 1
134 ; CHECK-NEXT: ret i32 2
136 %x = load i32, i32* %p, !range !{i32 0, i32 3}
137 switch i32 %x, label %switch.default [
138 i32 0, label %switch.0
139 i32 1, label %switch.1
140 i32 2, label %switch.2
141 i32 3, label %switch.3
160 ; TODO: Determine that case i3 is dead, even though the edge is shared?
161 define i32 @test_duplicate_successors(i32* %p) {
162 ; CHECK-LABEL: @test_duplicate_successors(
163 ; CHECK-NEXT: [[X:%.*]] = load i32, i32* [[P:%.*]], align 4, !range !0
164 ; CHECK-NEXT: switch i32 [[X]], label [[SWITCH_DEFAULT:%.*]] [
165 ; CHECK-NEXT: i32 0, label [[SWITCH_0:%.*]]
166 ; CHECK-NEXT: i32 1, label [[SWITCH_0]]
167 ; CHECK-NEXT: i32 2, label [[SWITCH_1:%.*]]
168 ; CHECK-NEXT: i32 3, label [[SWITCH_1]]
170 ; CHECK: switch.default:
171 ; CHECK-NEXT: ret i32 -1
173 ; CHECK-NEXT: ret i32 0
175 ; CHECK-NEXT: ret i32 1
177 %x = load i32, i32* %p, !range !{i32 0, i32 3}
178 switch i32 %x, label %switch.default [
179 i32 0, label %switch.0
180 i32 1, label %switch.0
181 i32 2, label %switch.1
182 i32 3, label %switch.1
183 i32 4, label %switch.2
184 i32 5, label %switch.2
200 ; Case i32 2 is dead as well, but this cannot be determined based on
202 define internal i32 @test_ip_range(i32 %x) {
203 ; CHECK-LABEL: @test_ip_range(
204 ; CHECK-NEXT: switch i32 [[X:%.*]], label [[SWITCH_DEFAULT:%.*]] [
205 ; CHECK-NEXT: i32 3, label [[SWITCH_3:%.*]]
206 ; CHECK-NEXT: i32 1, label [[SWITCH_1:%.*]]
207 ; CHECK-NEXT: i32 2, label [[SWITCH_2:%.*]]
208 ; CHECK-NEXT: ], !prof !1
209 ; CHECK: switch.default:
210 ; CHECK-NEXT: ret i32 -1
212 ; CHECK-NEXT: ret i32 1
214 ; CHECK-NEXT: ret i32 2
216 ; CHECK-NEXT: ret i32 3
218 switch i32 %x, label %switch.default [
219 i32 0, label %switch.0
220 i32 1, label %switch.1
221 i32 2, label %switch.2
222 i32 3, label %switch.3
223 ], !prof !{!"branch_weights", i32 1, i32 2, i32 3, i32 4, i32 5}
241 define void @call_test_ip_range() {
242 ; CHECK-LABEL: @call_test_ip_range(
243 ; CHECK-NEXT: [[TMP1:%.*]] = call i32 @test_ip_range(i32 1)
244 ; CHECK-NEXT: [[TMP2:%.*]] = call i32 @test_ip_range(i32 3)
245 ; CHECK-NEXT: ret void
247 call i32 @test_ip_range(i32 1)
248 call i32 @test_ip_range(i32 3)
252 declare void @llvm.assume(i1)
254 ; CHECK: !1 = !{!"branch_weights", i32 1, i32 5, i32 3, i32 4}