1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4
2 ; RUN: opt < %s -passes=correlated-propagation -S | FileCheck %s
4 define i32 @test_unreachable_default(i32 noundef %num) {
5 ; CHECK-LABEL: define i32 @test_unreachable_default(
6 ; CHECK-SAME: i32 noundef [[NUM:%.*]]) {
8 ; CHECK-NEXT: [[SUB:%.*]] = add i32 [[NUM]], -120
9 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i32 [[SUB]], 3
10 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 2
11 ; CHECK-NEXT: switch i32 [[COND]], label [[DEFAULT_UNREACHABLE:%.*]] [
12 ; CHECK-NEXT: i32 0, label [[SW_BB:%.*]]
13 ; CHECK-NEXT: i32 1, label [[SW_BB2:%.*]]
14 ; CHECK-NEXT: i32 2, label [[SW_BB4:%.*]]
17 ; CHECK-NEXT: [[CALL:%.*]] = call i32 @call0()
18 ; CHECK-NEXT: br label [[CLEANUP:%.*]]
20 ; CHECK-NEXT: [[CALL3:%.*]] = call i32 @call1()
21 ; CHECK-NEXT: br label [[CLEANUP]]
23 ; CHECK-NEXT: [[CALL5:%.*]] = call i32 @call2()
24 ; CHECK-NEXT: br label [[CLEANUP]]
25 ; CHECK: default.unreachable:
26 ; CHECK-NEXT: unreachable
28 ; CHECK-NEXT: [[CALL6:%.*]] = call i32 @call3()
29 ; CHECK-NEXT: br label [[CLEANUP]]
31 ; CHECK-NEXT: [[RETVAL_0:%.*]] = phi i32 [ [[CALL6]], [[SW_DEFAULT:%.*]] ], [ [[CALL5]], [[SW_BB4]] ], [ [[CALL3]], [[SW_BB2]] ], [ [[CALL]], [[SW_BB]] ]
32 ; CHECK-NEXT: ret i32 [[RETVAL_0]]
35 %sub = add i32 %num, -120
36 %cmp = icmp ult i32 %sub, 3
37 %cond = select i1 %cmp, i32 %sub, i32 2
38 switch i32 %cond, label %sw.default [
45 %call = call i32 @call0()
49 %call3 = call i32 @call1()
53 %call5 = call i32 @call2()
57 %call6 = call i32 @call3()
61 %retval.0 = phi i32 [ %call6, %sw.default ], [ %call5, %sw.bb4 ], [ %call3, %sw.bb2 ], [ %call, %sw.bb ]
65 define i32 @test_unreachable_default_shared_edge(i32 noundef %num) {
66 ; CHECK-LABEL: define i32 @test_unreachable_default_shared_edge(
67 ; CHECK-SAME: i32 noundef [[NUM:%.*]]) {
69 ; CHECK-NEXT: [[SUB:%.*]] = add i32 [[NUM]], -120
70 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i32 [[SUB]], 3
71 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 2
72 ; CHECK-NEXT: switch i32 [[COND]], label [[DEFAULT_UNREACHABLE:%.*]] [
73 ; CHECK-NEXT: i32 0, label [[SW_BB:%.*]]
74 ; CHECK-NEXT: i32 1, label [[SW_BB2:%.*]]
75 ; CHECK-NEXT: i32 2, label [[SW_BB4:%.*]]
78 ; CHECK-NEXT: [[CALL:%.*]] = call i32 @call0()
79 ; CHECK-NEXT: br label [[CLEANUP:%.*]]
81 ; CHECK-NEXT: [[CALL3:%.*]] = call i32 @call1()
82 ; CHECK-NEXT: br label [[CLEANUP]]
83 ; CHECK: default.unreachable:
84 ; CHECK-NEXT: unreachable
86 ; CHECK-NEXT: [[CALL5:%.*]] = call i32 @call4(i32 [[SUB]])
87 ; CHECK-NEXT: br label [[CLEANUP]]
89 ; CHECK-NEXT: [[RETVAL_0:%.*]] = phi i32 [ [[CALL5]], [[SW_BB4]] ], [ [[CALL3]], [[SW_BB2]] ], [ [[CALL]], [[SW_BB]] ]
90 ; CHECK-NEXT: ret i32 [[RETVAL_0]]
93 %sub = add i32 %num, -120
94 %cmp = icmp ult i32 %sub, 3
95 %cond = select i1 %cmp, i32 %sub, i32 2
96 switch i32 %cond, label %sw.bb4 [
103 %call = call i32 @call0()
107 %call3 = call i32 @call1()
111 %val = phi i32 [ %sub, %entry ], [ %sub, %entry ]
112 %call5 = call i32 @call4(i32 %val)
116 %retval.0 = phi i32 [ %call5, %sw.bb4 ], [ %call3, %sw.bb2 ], [ %call, %sw.bb ]
122 define i32 @test_reachable_default(i32 noundef %num) {
123 ; CHECK-LABEL: define i32 @test_reachable_default(
124 ; CHECK-SAME: i32 noundef [[NUM:%.*]]) {
126 ; CHECK-NEXT: [[SUB:%.*]] = add i32 [[NUM]], -120
127 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i32 [[SUB]], 3
128 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 4
129 ; CHECK-NEXT: switch i32 [[COND]], label [[SW_DEFAULT:%.*]] [
130 ; CHECK-NEXT: i32 0, label [[SW_BB:%.*]]
131 ; CHECK-NEXT: i32 1, label [[SW_BB2:%.*]]
132 ; CHECK-NEXT: i32 2, label [[SW_BB4:%.*]]
135 ; CHECK-NEXT: [[CALL:%.*]] = call i32 @call0()
136 ; CHECK-NEXT: br label [[CLEANUP:%.*]]
138 ; CHECK-NEXT: [[CALL3:%.*]] = call i32 @call1()
139 ; CHECK-NEXT: br label [[CLEANUP]]
141 ; CHECK-NEXT: [[CALL5:%.*]] = call i32 @call2()
142 ; CHECK-NEXT: br label [[CLEANUP]]
144 ; CHECK-NEXT: [[CALL6:%.*]] = call i32 @call3()
145 ; CHECK-NEXT: br label [[CLEANUP]]
147 ; CHECK-NEXT: [[RETVAL_0:%.*]] = phi i32 [ [[CALL6]], [[SW_DEFAULT]] ], [ [[CALL5]], [[SW_BB4]] ], [ [[CALL3]], [[SW_BB2]] ], [ [[CALL]], [[SW_BB]] ]
148 ; CHECK-NEXT: ret i32 [[RETVAL_0]]
151 %sub = add i32 %num, -120
152 %cmp = icmp ult i32 %sub, 3
153 %cond = select i1 %cmp, i32 %sub, i32 4
154 switch i32 %cond, label %sw.default [
161 %call = call i32 @call0()
165 %call3 = call i32 @call1()
169 %call5 = call i32 @call2()
173 %call6 = call i32 @call3()
177 %retval.0 = phi i32 [ %call6, %sw.default ], [ %call5, %sw.bb4 ], [ %call3, %sw.bb2 ], [ %call, %sw.bb ]
181 define i32 @test_unreachable_default_cond_may_be_undef(i32 %num) {
182 ; CHECK-LABEL: define i32 @test_unreachable_default_cond_may_be_undef(
183 ; CHECK-SAME: i32 [[NUM:%.*]]) {
185 ; CHECK-NEXT: [[SUB:%.*]] = add i32 [[NUM]], -120
186 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i32 [[SUB]], 3
187 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 2
188 ; CHECK-NEXT: switch i32 [[COND]], label [[SW_DEFAULT:%.*]] [
189 ; CHECK-NEXT: i32 0, label [[SW_BB:%.*]]
190 ; CHECK-NEXT: i32 1, label [[SW_BB2:%.*]]
191 ; CHECK-NEXT: i32 2, label [[SW_BB4:%.*]]
194 ; CHECK-NEXT: [[CALL:%.*]] = call i32 @call0()
195 ; CHECK-NEXT: br label [[CLEANUP:%.*]]
197 ; CHECK-NEXT: [[CALL3:%.*]] = call i32 @call1()
198 ; CHECK-NEXT: br label [[CLEANUP]]
200 ; CHECK-NEXT: [[CALL5:%.*]] = call i32 @call2()
201 ; CHECK-NEXT: br label [[CLEANUP]]
203 ; CHECK-NEXT: [[CALL6:%.*]] = call i32 @call3()
204 ; CHECK-NEXT: br label [[CLEANUP]]
206 ; CHECK-NEXT: [[RETVAL_0:%.*]] = phi i32 [ [[CALL6]], [[SW_DEFAULT]] ], [ [[CALL5]], [[SW_BB4]] ], [ [[CALL3]], [[SW_BB2]] ], [ [[CALL]], [[SW_BB]] ]
207 ; CHECK-NEXT: ret i32 [[RETVAL_0]]
210 %sub = add i32 %num, -120
211 %cmp = icmp ult i32 %sub, 3
212 %cond = select i1 %cmp, i32 %sub, i32 2
213 switch i32 %cond, label %sw.default [
220 %call = call i32 @call0()
224 %call3 = call i32 @call1()
228 %call5 = call i32 @call2()
232 %call6 = call i32 @call3()
236 %retval.0 = phi i32 [ %call6, %sw.default ], [ %call5, %sw.bb4 ], [ %call3, %sw.bb2 ], [ %call, %sw.bb ]
240 define i32 @test_default_is_already_unreachable(i32 %num) {
241 ; CHECK-LABEL: define i32 @test_default_is_already_unreachable(
242 ; CHECK-SAME: i32 [[NUM:%.*]]) {
244 ; CHECK-NEXT: [[SUB:%.*]] = add i32 [[NUM]], -120
245 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i32 [[SUB]], 3
246 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 2
247 ; CHECK-NEXT: switch i32 [[COND]], label [[SW_DEFAULT:%.*]] [
248 ; CHECK-NEXT: i32 0, label [[SW_BB:%.*]]
249 ; CHECK-NEXT: i32 1, label [[SW_BB2:%.*]]
250 ; CHECK-NEXT: i32 2, label [[SW_BB4:%.*]]
253 ; CHECK-NEXT: [[CALL:%.*]] = call i32 @call0()
254 ; CHECK-NEXT: br label [[CLEANUP:%.*]]
256 ; CHECK-NEXT: [[CALL3:%.*]] = call i32 @call1()
257 ; CHECK-NEXT: br label [[CLEANUP]]
259 ; CHECK-NEXT: [[CALL5:%.*]] = call i32 @call2()
260 ; CHECK-NEXT: br label [[CLEANUP]]
262 ; CHECK-NEXT: unreachable
264 ; CHECK-NEXT: [[RETVAL_0:%.*]] = phi i32 [ [[CALL5]], [[SW_BB4]] ], [ [[CALL3]], [[SW_BB2]] ], [ [[CALL]], [[SW_BB]] ]
265 ; CHECK-NEXT: ret i32 [[RETVAL_0]]
268 %sub = add i32 %num, -120
269 %cmp = icmp ult i32 %sub, 3
270 %cond = select i1 %cmp, i32 %sub, i32 2
271 switch i32 %cond, label %sw.default [
278 %call = call i32 @call0()
282 %call3 = call i32 @call1()
286 %call5 = call i32 @call2()
293 %retval.0 = phi i32 [ %call5, %sw.bb4 ], [ %call3, %sw.bb2 ], [ %call, %sw.bb ]
301 declare i32 @call4(i32)