1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature
2 ; RUN: opt < %s -passes=ipsccp -S | FileCheck %s
4 ; Constant range for %a is [1, 48) and for %b is [301, 1000)
5 define internal i32 @f1(i32 %a, i32 %b) {
6 ; CHECK-LABEL: define {{[^@]+}}@f1
7 ; CHECK-SAME: (i32 [[A:%.*]], i32 [[B:%.*]]) {
9 ; CHECK-NEXT: ret i32 poison
12 %cmp.a = icmp sgt i32 %a, 300
13 %cmp.b = icmp sgt i32 %b, 300
14 %cmp.a2 = icmp ugt i32 %a, 300
15 %cmp.b2 = icmp ugt i32 %b, 300
17 %a.1 = select i1 %cmp.a, i32 1, i32 2
18 %b.1 = select i1 %cmp.b, i32 1, i32 2
19 %a.2 = select i1 %cmp.a2, i32 1, i32 2
20 %b.2 = select i1 %cmp.b2, i32 1, i32 2
21 %res1 = add i32 %a.1, %b.1
22 %res2 = add i32 %a.2, %b.2
23 %res3 = add i32 %res1, %res2
27 ; Constant range for %x is [47, 302)
28 define internal i32 @f2(i32 %x) {
29 ; CHECK-LABEL: define {{[^@]+}}@f2
30 ; CHECK-SAME: (i32 [[X:%.*]]) {
32 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[X]], 300
33 ; CHECK-NEXT: [[CMP4:%.*]] = icmp ugt i32 [[X]], 300
34 ; CHECK-NEXT: [[RES1:%.*]] = select i1 [[CMP]], i32 1, i32 2
35 ; CHECK-NEXT: [[RES4:%.*]] = select i1 [[CMP4]], i32 3, i32 4
36 ; CHECK-NEXT: [[RES6:%.*]] = add nuw nsw i32 [[RES1]], 3
37 ; CHECK-NEXT: [[RES7:%.*]] = add nuw nsw i32 5, [[RES4]]
38 ; CHECK-NEXT: [[RES:%.*]] = add nuw nsw i32 [[RES6]], 5
39 ; CHECK-NEXT: ret i32 [[RES]]
42 %cmp = icmp sgt i32 %x, 300
43 %cmp2 = icmp ne i32 %x, 10
44 %cmp3 = icmp sge i32 %x, 47
45 %cmp4 = icmp ugt i32 %x, 300
46 %cmp5 = icmp uge i32 %x, 47
47 %res1 = select i1 %cmp, i32 1, i32 2
48 %res2 = select i1 %cmp2, i32 3, i32 4
49 %res3 = select i1 %cmp3, i32 5, i32 6
50 %res4 = select i1 %cmp4, i32 3, i32 4
51 %res5 = select i1 %cmp5, i32 5, i32 6
53 %res6 = add i32 %res1, %res2
54 %res7 = add i32 %res3, %res4
55 %res = add i32 %res6, %res5
59 define i32 @caller1() {
60 ; CHECK-LABEL: define {{[^@]+}}@caller1() {
62 ; CHECK-NEXT: [[CALL1:%.*]] = tail call i32 @f1(i32 1, i32 301)
63 ; CHECK-NEXT: [[CALL2:%.*]] = tail call i32 @f1(i32 47, i32 999)
64 ; CHECK-NEXT: [[CALL3:%.*]] = tail call i32 @f2(i32 47)
65 ; CHECK-NEXT: [[CALL4:%.*]] = tail call i32 @f2(i32 301)
66 ; CHECK-NEXT: [[RES_1:%.*]] = add nuw nsw i32 12, [[CALL3]]
67 ; CHECK-NEXT: [[RES_2:%.*]] = add nuw nsw i32 [[RES_1]], [[CALL4]]
68 ; CHECK-NEXT: ret i32 [[RES_2]]
71 %call1 = tail call i32 @f1(i32 1, i32 301)
72 %call2 = tail call i32 @f1(i32 47, i32 999)
73 %call3 = tail call i32 @f2(i32 47)
74 %call4 = tail call i32 @f2(i32 301)
75 %res.1 = add nsw i32 12, %call3
76 %res.2 = add nsw i32 %res.1, %call4
80 define internal i32 @f3(i32 %x) {
81 ; CHECK-LABEL: define {{[^@]+}}@f3
82 ; CHECK-SAME: (i32 [[X:%.*]]) {
84 ; CHECK-NEXT: ret i32 poison
87 %cmp = icmp sgt i32 %x, 300
88 %res = select i1 %cmp, i32 1, i32 2
92 ; The phi node could be converted in a ConstantRange.
93 define i32 @caller2(i1 %cmp) {
94 ; CHECK-LABEL: define {{[^@]+}}@caller2
95 ; CHECK-SAME: (i1 [[CMP:%.*]]) {
97 ; CHECK-NEXT: br i1 [[CMP]], label [[IF_TRUE:%.*]], label [[END:%.*]]
99 ; CHECK-NEXT: br label [[END]]
101 ; CHECK-NEXT: [[RES:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ 1, [[IF_TRUE]] ]
102 ; CHECK-NEXT: [[CALL1:%.*]] = tail call i32 @f3(i32 [[RES]])
103 ; CHECK-NEXT: ret i32 2
106 br i1 %cmp, label %if.true, label %end
112 %res = phi i32 [ 0, %entry], [ 1, %if.true ]
113 %call1 = tail call i32 @f3(i32 %res)
117 define internal i32 @f4(i32 %x) {
118 ; CHECK-LABEL: define {{[^@]+}}@f4
119 ; CHECK-SAME: (i32 [[X:%.*]]) {
121 ; CHECK-NEXT: ret i32 poison
124 %cmp = icmp sgt i32 %x, 300
125 %res = select i1 %cmp, i32 1, i32 2
129 ; ICmp introduces bounds on ConstantRanges.
130 define i32 @caller3(i32 %x) {
131 ; CHECK-LABEL: define {{[^@]+}}@caller3
132 ; CHECK-SAME: (i32 [[X:%.*]]) {
134 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[X]], 300
135 ; CHECK-NEXT: br i1 [[CMP]], label [[IF_TRUE:%.*]], label [[END:%.*]]
137 ; CHECK-NEXT: [[X_1:%.*]] = tail call i32 @f4(i32 [[X]])
138 ; CHECK-NEXT: br label [[END]]
140 ; CHECK-NEXT: [[RES:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ 1, [[IF_TRUE]] ]
141 ; CHECK-NEXT: ret i32 [[RES]]
144 %cmp = icmp sgt i32 %x, 300
145 br i1 %cmp, label %if.true, label %end
148 %x.1 = tail call i32 @f4(i32 %x)
152 %res = phi i32 [ 0, %entry], [ %x.1, %if.true ]
156 ; Check to make sure we do not attempt to access lattice values in unreachable
158 define i32 @test_unreachable() {
159 ; CHECK-LABEL: define {{[^@]+}}@test_unreachable() {
161 ; CHECK-NEXT: [[TMP0:%.*]] = call i1 @test_unreachable_callee(i32 1)
162 ; CHECK-NEXT: [[TMP1:%.*]] = call i1 @test_unreachable_callee(i32 2)
163 ; CHECK-NEXT: ret i32 1
166 call i1 @test_unreachable_callee(i32 1)
167 call i1 @test_unreachable_callee(i32 2)
171 define internal i1 @test_unreachable_callee(i32 %a) {
172 ; CHECK-LABEL: define {{[^@]+}}@test_unreachable_callee
173 ; CHECK-SAME: (i32 [[A:%.*]]) {
175 ; CHECK-NEXT: ret i1 poison
181 %cmp = icmp eq i32 undef, %a
185 ; Check that we do not attempt to get range info for non-integer types and
187 define double @test_struct({ double, double } %test) {
188 ; CHECK-LABEL: define {{[^@]+}}@test_struct
189 ; CHECK-SAME: ({ double, double } [[TEST:%.*]]) {
190 ; CHECK-NEXT: [[V:%.*]] = extractvalue { double, double } [[TEST]], 0
191 ; CHECK-NEXT: [[R:%.*]] = fmul double [[V]], [[V]]
192 ; CHECK-NEXT: ret double [[R]]
194 %v = extractvalue { double, double } %test, 0
195 %r = fmul double %v, %v
199 ; Constant range for %x is [47, 302)
200 define internal i32 @f5(i32 %x) {
201 ; CHECK-LABEL: define {{[^@]+}}@f5
202 ; CHECK-SAME: (i32 [[X:%.*]]) {
204 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[X]], undef
205 ; CHECK-NEXT: [[CMP2:%.*]] = icmp ne i32 undef, [[X]]
206 ; CHECK-NEXT: [[RES1:%.*]] = select i1 [[CMP]], i32 1, i32 2
207 ; CHECK-NEXT: [[RES2:%.*]] = select i1 [[CMP2]], i32 3, i32 4
208 ; CHECK-NEXT: [[RES:%.*]] = add i32 [[RES1]], [[RES2]]
209 ; CHECK-NEXT: ret i32 [[RES]]
212 %cmp = icmp sgt i32 %x, undef
213 %cmp2 = icmp ne i32 undef, %x
214 %res1 = select i1 %cmp, i32 1, i32 2
215 %res2 = select i1 %cmp2, i32 3, i32 4
217 %res = add i32 %res1, %res2
221 define i32 @caller4() {
222 ; CHECK-LABEL: define {{[^@]+}}@caller4() {
224 ; CHECK-NEXT: [[CALL1:%.*]] = tail call i32 @f5(i32 47)
225 ; CHECK-NEXT: [[CALL2:%.*]] = tail call i32 @f5(i32 301)
226 ; CHECK-NEXT: [[RES:%.*]] = add nsw i32 [[CALL1]], [[CALL2]]
227 ; CHECK-NEXT: ret i32 [[RES]]
230 %call1 = tail call i32 @f5(i32 47)
231 %call2 = tail call i32 @f5(i32 301)
232 %res = add nsw i32 %call1, %call2
236 ; Make sure we do re-evaluate the function after ParamState changes.
237 define internal i32 @recursive_f(i32 %i) {
238 ; CHECK-LABEL: define {{[^@]+}}@recursive_f
239 ; CHECK-SAME: (i32 [[I:%.*]]) {
241 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[I]], 0
242 ; CHECK-NEXT: br i1 [[CMP]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
244 ; CHECK-NEXT: br label [[RETURN:%.*]]
246 ; CHECK-NEXT: [[SUB:%.*]] = sub nuw nsw i32 [[I]], 1
247 ; CHECK-NEXT: [[CALL:%.*]] = call i32 @recursive_f(i32 [[SUB]])
248 ; CHECK-NEXT: [[ADD:%.*]] = add i32 [[I]], [[CALL]]
249 ; CHECK-NEXT: br label [[RETURN]]
251 ; CHECK-NEXT: [[RETVAL_0:%.*]] = phi i32 [ 0, [[IF_THEN]] ], [ [[ADD]], [[IF_ELSE]] ]
252 ; CHECK-NEXT: ret i32 [[RETVAL_0]]
255 %cmp = icmp eq i32 %i, 0
256 br i1 %cmp, label %if.then, label %if.else
258 if.then: ; preds = %entry
261 if.else: ; preds = %entry
262 %sub = sub nsw i32 %i, 1
263 %call = call i32 @recursive_f(i32 %sub)
264 %add = add i32 %i, %call
267 return: ; preds = %if.else, %if.then
268 %retval.0 = phi i32 [ 0, %if.then ], [ %add, %if.else ]
272 define i32 @caller5() {
273 ; CHECK-LABEL: define {{[^@]+}}@caller5() {
275 ; CHECK-NEXT: [[CALL:%.*]] = call i32 @recursive_f(i32 42)
276 ; CHECK-NEXT: ret i32 [[CALL]]
279 %call = call i32 @recursive_f(i32 42)
283 define internal i32 @callee6.1(i32 %i) {
284 ; CHECK-LABEL: define {{[^@]+}}@callee6.1
285 ; CHECK-SAME: (i32 [[I:%.*]]) {
286 ; CHECK-NEXT: [[RES:%.*]] = call i32 @callee6.2(i32 [[I]])
287 ; CHECK-NEXT: ret i32 poison
289 %res = call i32 @callee6.2(i32 %i)
293 define internal i32 @callee6.2(i32 %i) {
294 ; CHECK-LABEL: define {{[^@]+}}@callee6.2
295 ; CHECK-SAME: (i32 [[I:%.*]]) {
296 ; CHECK-NEXT: br label [[IF_THEN:%.*]]
298 ; CHECK-NEXT: ret i32 poison
301 %cmp = icmp ne i32 %i, 0
302 br i1 %cmp, label %if.then, label %if.else
304 if.then: ; preds = %entry
307 if.else: ; preds = %entry
311 define i32 @caller6() {
312 ; CHECK-LABEL: define {{[^@]+}}@caller6() {
313 ; CHECK-NEXT: [[CALL_1:%.*]] = call i32 @callee6.1(i32 30)
314 ; CHECK-NEXT: [[CALL_2:%.*]] = call i32 @callee6.1(i32 43)
315 ; CHECK-NEXT: ret i32 2
317 %call.1 = call i32 @callee6.1(i32 30)
318 %call.2 = call i32 @callee6.1(i32 43)
319 %res = add i32 %call.1, %call.2