1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4
2 ; RUN: opt -S -passes=ipsccp < %s | FileCheck %s
4 ; Make sure we always consider the default edge executable for a switch
10 ; CHECK-LABEL: define void @test1() {
11 ; CHECK-NEXT: switch i32 undef, label [[D:%.*]] [
14 ; CHECK-NEXT: call void @foo()
15 ; CHECK-NEXT: ret void
17 switch i32 undef, label %d []
23 define i32 @test_duplicate_successors_phi(i1 %c, i32 %x) {
24 ; CHECK-LABEL: define i32 @test_duplicate_successors_phi(
25 ; CHECK-SAME: i1 [[C:%.*]], i32 [[X:%.*]]) {
27 ; CHECK-NEXT: br i1 [[C]], label [[SWITCH:%.*]], label [[END:%.*]]
29 ; CHECK-NEXT: br label [[SWITCH_DEFAULT:%.*]]
30 ; CHECK: switch.default:
31 ; CHECK-NEXT: ret i32 -1
33 ; CHECK-NEXT: ret i32 [[X]]
36 br i1 %c, label %switch, label %end
39 switch i32 -1, label %switch.default [
48 %phi = phi i32 [ %x, %entry ], [ 1, %switch ], [ 1, %switch ]
52 define i32 @test_duplicate_successors_phi_2(i1 %c, i32 %x) {
53 ; CHECK-LABEL: define i32 @test_duplicate_successors_phi_2(
54 ; CHECK-SAME: i1 [[C:%.*]], i32 [[X:%.*]]) {
56 ; CHECK-NEXT: br i1 [[C]], label [[SWITCH:%.*]], label [[END:%.*]]
58 ; CHECK-NEXT: br label [[END]]
60 ; CHECK-NEXT: [[PHI:%.*]] = phi i32 [ [[X]], [[ENTRY:%.*]] ], [ 1, [[SWITCH]] ]
61 ; CHECK-NEXT: ret i32 [[PHI]]
64 br i1 %c, label %switch, label %end
67 switch i32 0, label %switch.default [
76 %phi = phi i32 [ %x, %entry ], [ 1, %switch ], [ 1, %switch ]
80 define i32 @test_duplicate_successors_phi_3(i1 %c1, ptr %p, i32 %y) {
81 ; CHECK-LABEL: define i32 @test_duplicate_successors_phi_3(
82 ; CHECK-SAME: i1 [[C1:%.*]], ptr [[P:%.*]], i32 [[Y:%.*]]) {
84 ; CHECK-NEXT: br i1 [[C1]], label [[SWITCH:%.*]], label [[SWITCH_1:%.*]]
86 ; CHECK-NEXT: [[X:%.*]] = load i32, ptr [[P]], align 4, !range [[RNG0:![0-9]+]]
87 ; CHECK-NEXT: switch i32 [[X]], label [[SWITCH_DEFAULT:%.*]] [
88 ; CHECK-NEXT: i32 0, label [[SWITCH_DEFAULT]]
89 ; CHECK-NEXT: i32 1, label [[SWITCH_0:%.*]]
90 ; CHECK-NEXT: i32 2, label [[SWITCH_0]]
92 ; CHECK: switch.default:
93 ; CHECK-NEXT: ret i32 -1
95 ; CHECK-NEXT: ret i32 0
97 ; CHECK-NEXT: ret i32 [[Y]]
100 br i1 %c1, label %switch, label %switch.1
103 %x = load i32, ptr %p, !range !{i32 0, i32 3}
104 switch i32 %x, label %switch.default [
105 i32 0, label %switch.default
106 i32 1, label %switch.0
107 i32 2, label %switch.0
108 i32 3, label %switch.1
109 i32 4, label %switch.1
119 %phi = phi i32 [ %y, %entry ], [ 0, %switch ], [ 0, %switch ]
123 define i32 @test_local_range(ptr %p) {
124 ; CHECK-LABEL: define range(i32 0, 3) i32 @test_local_range(
125 ; CHECK-SAME: ptr [[P:%.*]]) {
126 ; CHECK-NEXT: [[X:%.*]] = load i32, ptr [[P]], align 4, !range [[RNG0]]
127 ; CHECK-NEXT: switch i32 [[X]], label [[DEFAULT_UNREACHABLE:%.*]] [
128 ; CHECK-NEXT: i32 0, label [[SWITCH_0:%.*]]
129 ; CHECK-NEXT: i32 1, label [[SWITCH_1:%.*]]
130 ; CHECK-NEXT: i32 2, label [[SWITCH_2:%.*]]
132 ; CHECK: default.unreachable:
133 ; CHECK-NEXT: unreachable
135 ; CHECK-NEXT: ret i32 0
137 ; CHECK-NEXT: ret i32 1
139 ; CHECK-NEXT: ret i32 2
141 %x = load i32, ptr %p, !range !{i32 0, i32 3}
142 switch i32 %x, label %switch.default [
143 i32 0, label %switch.0
144 i32 1, label %switch.1
145 i32 2, label %switch.2
146 i32 3, label %switch.3
165 ; TODO: Determine that case i3 is dead, even though the edge is shared?
166 define i32 @test_duplicate_successors(ptr %p) {
167 ; CHECK-LABEL: define range(i32 0, 2) i32 @test_duplicate_successors(
168 ; CHECK-SAME: ptr [[P:%.*]]) {
169 ; CHECK-NEXT: [[X:%.*]] = load i32, ptr [[P]], align 4, !range [[RNG0]]
170 ; CHECK-NEXT: switch i32 [[X]], label [[DEFAULT_UNREACHABLE:%.*]] [
171 ; CHECK-NEXT: i32 0, label [[SWITCH_0:%.*]]
172 ; CHECK-NEXT: i32 1, label [[SWITCH_0]]
173 ; CHECK-NEXT: i32 2, label [[SWITCH_1:%.*]]
174 ; CHECK-NEXT: i32 3, label [[SWITCH_1]]
176 ; CHECK: default.unreachable:
177 ; CHECK-NEXT: unreachable
179 ; CHECK-NEXT: ret i32 0
181 ; CHECK-NEXT: ret i32 1
183 %x = load i32, ptr %p, !range !{i32 0, i32 3}
184 switch i32 %x, label %switch.default [
185 i32 0, label %switch.0
186 i32 1, label %switch.0
187 i32 2, label %switch.1
188 i32 3, label %switch.1
189 i32 4, label %switch.2
190 i32 5, label %switch.2
206 ; Case i32 2 is dead as well, but this cannot be determined based on
208 define internal i32 @test_ip_range(i32 %x) {
209 ; CHECK-LABEL: define internal range(i32 1, 4) i32 @test_ip_range(
210 ; CHECK-SAME: i32 range(i32 1, 4) [[X:%.*]]) {
211 ; CHECK-NEXT: switch i32 [[X]], label [[DEFAULT_UNREACHABLE:%.*]] [
212 ; CHECK-NEXT: i32 3, label [[SWITCH_3:%.*]]
213 ; CHECK-NEXT: i32 1, label [[SWITCH_1:%.*]]
214 ; CHECK-NEXT: i32 2, label [[SWITCH_2:%.*]]
215 ; CHECK-NEXT: ], !prof [[PROF1:![0-9]+]]
216 ; CHECK: default.unreachable:
217 ; CHECK-NEXT: unreachable
219 ; CHECK-NEXT: ret i32 1
221 ; CHECK-NEXT: ret i32 2
223 ; CHECK-NEXT: ret i32 3
225 switch i32 %x, label %switch.default [
226 i32 0, label %switch.0
227 i32 1, label %switch.1
228 i32 2, label %switch.2
229 i32 3, label %switch.3
230 ], !prof !{!"branch_weights", i32 1, i32 2, i32 3, i32 4, i32 5}
248 define void @call_test_ip_range() {
249 ; CHECK-LABEL: define void @call_test_ip_range() {
250 ; CHECK-NEXT: [[TMP1:%.*]] = call i32 @test_ip_range(i32 1)
251 ; CHECK-NEXT: [[TMP2:%.*]] = call i32 @test_ip_range(i32 3)
252 ; CHECK-NEXT: ret void
254 call i32 @test_ip_range(i32 1)
255 call i32 @test_ip_range(i32 3)
259 define i32 @test_switch_range_may_include_undef(i1 %c.1, i1 %c.2, i32 %x) {
260 ; CHECK-LABEL: define range(i32 -1, 21) i32 @test_switch_range_may_include_undef(
261 ; CHECK-SAME: i1 [[C_1:%.*]], i1 [[C_2:%.*]], i32 [[X:%.*]]) {
263 ; CHECK-NEXT: br i1 [[C_1]], label [[THEN_1:%.*]], label [[ELSE_1:%.*]]
265 ; CHECK-NEXT: br i1 [[C_2]], label [[SWITCH:%.*]], label [[ELSE_2:%.*]]
267 ; CHECK-NEXT: br label [[SWITCH]]
269 ; CHECK-NEXT: br label [[SWITCH]]
271 ; CHECK-NEXT: [[P:%.*]] = phi i32 [ 0, [[THEN_1]] ], [ 2, [[ELSE_1]] ], [ undef, [[ELSE_2]] ]
272 ; CHECK-NEXT: switch i32 [[P]], label [[SWITCH_DEFAULT:%.*]] [
273 ; CHECK-NEXT: i32 0, label [[END_1:%.*]]
274 ; CHECK-NEXT: i32 3, label [[END_2:%.*]]
276 ; CHECK: switch.default:
277 ; CHECK-NEXT: ret i32 -1
279 ; CHECK-NEXT: ret i32 10
281 ; CHECK-NEXT: ret i32 20
284 br i1 %c.1, label %then.1, label %else.1
287 br i1 %c.2, label %switch, label %else.2
296 %p = phi i32 [ 0, %then.1 ], [ 2, %else.1 ], [ undef, %else.2 ]
297 switch i32 %p, label %switch.default [
312 define i32 @test_default_unreachable_by_dom_cond(i32 %x) {
313 ; CHECK-LABEL: define i32 @test_default_unreachable_by_dom_cond(
314 ; CHECK-SAME: i32 [[X:%.*]]) {
316 ; CHECK-NEXT: [[OR_COND:%.*]] = icmp ult i32 [[X]], 4
317 ; CHECK-NEXT: br i1 [[OR_COND]], label [[IF_THEN:%.*]], label [[RETURN:%.*]]
319 ; CHECK-NEXT: switch i32 [[X]], label [[DEFAULT_UNREACHABLE:%.*]] [
320 ; CHECK-NEXT: i32 0, label [[SW_BB:%.*]]
321 ; CHECK-NEXT: i32 1, label [[SW_BB2:%.*]]
322 ; CHECK-NEXT: i32 2, label [[SW_BB4:%.*]]
323 ; CHECK-NEXT: i32 3, label [[SW_BB6:%.*]]
326 ; CHECK-NEXT: [[CALL:%.*]] = tail call i32 @g(i32 2)
327 ; CHECK-NEXT: br label [[RETURN]]
329 ; CHECK-NEXT: [[CALL3:%.*]] = tail call i32 @g(i32 3)
330 ; CHECK-NEXT: br label [[RETURN]]
332 ; CHECK-NEXT: [[CALL5:%.*]] = tail call i32 @g(i32 4)
333 ; CHECK-NEXT: br label [[RETURN]]
335 ; CHECK-NEXT: [[CALL7:%.*]] = tail call i32 @g(i32 5)
336 ; CHECK-NEXT: br label [[RETURN]]
337 ; CHECK: default.unreachable:
338 ; CHECK-NEXT: unreachable
340 ; CHECK-NEXT: [[RETVAL_0:%.*]] = phi i32 [ [[CALL7]], [[SW_BB6]] ], [ [[CALL5]], [[SW_BB4]] ], [ [[CALL3]], [[SW_BB2]] ], [ [[CALL]], [[SW_BB]] ], [ -23, [[ENTRY:%.*]] ]
341 ; CHECK-NEXT: ret i32 [[RETVAL_0]]
344 %or.cond = icmp ult i32 %x, 4
345 br i1 %or.cond, label %if.then, label %return
348 switch i32 %x, label %sw.epilog [
356 %call = tail call i32 @g(i32 2)
360 %call3 = tail call i32 @g(i32 3)
364 %call5 = tail call i32 @g(i32 4)
368 %call7 = tail call i32 @g(i32 5)
376 %retval.0 = phi i32 [ %call7, %sw.bb6 ], [ %call5, %sw.bb4 ], [ %call3, %sw.bb2 ], [ %call, %sw.bb ], [ -23, %sw.epilog ], [ -23, %entry ]
380 declare void @llvm.assume(i1)
383 ; CHECK: [[RNG0]] = !{i32 0, i32 3}
384 ; CHECK: [[PROF1]] = !{!"branch_weights", i32 1, i32 5, i32 3, i32 4}