1 ; RUN: opt < %s -ipsccp -S | FileCheck %s
3 ; Constant range for %a is [1, 48) and for %b is [301, 1000)
6 define internal i32 @f1(i32 %a, i32 %b) {
8 %cmp.a = icmp sgt i32 %a, 300
9 %cmp.b = icmp sgt i32 %b, 300
10 %cmp.a2 = icmp ugt i32 %a, 300
11 %cmp.b2 = icmp ugt i32 %b, 300
13 %a.1 = select i1 %cmp.a, i32 1, i32 2
14 %b.1 = select i1 %cmp.b, i32 1, i32 2
15 %a.2 = select i1 %cmp.a2, i32 1, i32 2
16 %b.2 = select i1 %cmp.b2, i32 1, i32 2
17 %res1 = add i32 %a.1, %b.1
18 %res2 = add i32 %a.2, %b.2
19 %res3 = add i32 %res1, %res2
23 ; Constant range for %x is [47, 302)
25 ; CHECK: %cmp = icmp sgt i32 %x, 300
26 ; CHECK: %res1 = select i1 %cmp, i32 1, i32 2
27 ; CHECK-NEXT: %res4 = select i1 %cmp4, i32 3, i32 4
28 ; CHECK-NEXT: %res6 = add i32 %res1, 3
29 ; CHECK-NEXT: %res7 = add i32 5, %res4
30 ; CHECK-NEXT: %res = add i32 %res6, 5
31 ; CHECK-NEXT: ret i32 %res
32 define internal i32 @f2(i32 %x) {
34 %cmp = icmp sgt i32 %x, 300
35 %cmp2 = icmp ne i32 %x, 10
36 %cmp3 = icmp sge i32 %x, 47
37 %cmp4 = icmp ugt i32 %x, 300
38 %cmp5 = icmp uge i32 %x, 47
39 %res1 = select i1 %cmp, i32 1, i32 2
40 %res2 = select i1 %cmp2, i32 3, i32 4
41 %res3 = select i1 %cmp3, i32 5, i32 6
42 %res4 = select i1 %cmp4, i32 3, i32 4
43 %res5 = select i1 %cmp5, i32 5, i32 6
45 %res6 = add i32 %res1, %res2
46 %res7 = add i32 %res3, %res4
47 %res = add i32 %res6, %res5
51 define i32 @caller1() {
53 %call1 = tail call i32 @f1(i32 1, i32 301)
54 %call2 = tail call i32 @f1(i32 47, i32 999)
55 %call3 = tail call i32 @f2(i32 47)
56 %call4 = tail call i32 @f2(i32 301)
57 %res.1 = add nsw i32 12, %call3
58 %res.2 = add nsw i32 %res.1, %call4
64 ; CHECK: ret i32 undef
65 define internal i32 @f3(i32 %x) {
67 %cmp = icmp sgt i32 %x, 300
68 %res = select i1 %cmp, i32 1, i32 2
72 ; The phi node could be converted in a ConstantRange.
73 define i32 @caller2(i1 %cmp) {
75 br i1 %cmp, label %if.true, label %end
81 %res = phi i32 [ 0, %entry], [ 1, %if.true ]
82 %call1 = tail call i32 @f3(i32 %res)
87 ; CHECK: ret i32 undef
88 define internal i32 @f4(i32 %x) {
90 %cmp = icmp sgt i32 %x, 300
91 %res = select i1 %cmp, i32 1, i32 2
95 ; ICmp introduces bounds on ConstantRanges.
96 define i32 @caller3(i32 %x) {
97 ; CHECK-LABEL: define i32 @caller3(i32 %x)
99 ; CHECK-NEXT: %res = phi i32 [ 0, %entry ], [ 1, %if.true ]
100 ; CHECK-NEXT: ret i32 %res
103 %cmp = icmp sgt i32 %x, 300
104 br i1 %cmp, label %if.true, label %end
107 %x.1 = tail call i32 @f4(i32 %x)
111 %res = phi i32 [ 0, %entry], [ %x.1, %if.true ]
115 ; Check to make sure we do not attempt to access lattice values in unreachable
117 define i32 @test_unreachable() {
119 call i1 @test_unreachable_callee(i32 1)
120 call i1 @test_unreachable_callee(i32 2)
124 define internal i1 @test_unreachable_callee(i32 %a) {
129 %cmp = icmp eq i32 undef, %a
133 ; Check that we do not attempt to get range info for non-integer types and
135 define double @test_struct({ double, double } %test) {
136 %v = extractvalue { double, double } %test, 0
137 %r = fmul double %v, %v
141 ; Constant range for %x is [47, 302)
144 ; CHECK-NEXT: %cmp = icmp sgt i32 %x, undef
145 ; CHECK-NEXT: %cmp2 = icmp ne i32 undef, %x
146 ; CHECK-NEXT: %res1 = select i1 %cmp, i32 1, i32 2
147 ; CHECK-NEXT: %res2 = select i1 %cmp2, i32 3, i32 4
148 ; CHECK-NEXT: %res = add i32 %res1, %res2
149 ; CHECK-NEXT: ret i32 %res
150 define internal i32 @f5(i32 %x) {
152 %cmp = icmp sgt i32 %x, undef
153 %cmp2 = icmp ne i32 undef, %x
154 %res1 = select i1 %cmp, i32 1, i32 2
155 %res2 = select i1 %cmp2, i32 3, i32 4
157 %res = add i32 %res1, %res2
161 define i32 @caller4() {
163 %call1 = tail call i32 @f5(i32 47)
164 %call2 = tail call i32 @f5(i32 301)
165 %res = add nsw i32 %call1, %call2
169 ; Make sure we do re-evaluate the function after ParamState changes.
170 ; CHECK-LABEL: @recursive_f
171 ; CHECK-LABEL: entry:
172 ; CHECK: %cmp = icmp eq i32 %i, 0
173 ; CHECK-NEXT: br i1 %cmp, label %if.then, label %if.else
174 define internal i32 @recursive_f(i32 %i) {
176 %cmp = icmp eq i32 %i, 0
177 br i1 %cmp, label %if.then, label %if.else
179 if.then: ; preds = %entry
182 if.else: ; preds = %entry
183 %sub = sub nsw i32 %i, 1
184 %call = call i32 @recursive_f(i32 %sub)
185 %add = add i32 %i, %call
188 return: ; preds = %if.else, %if.then
189 %retval.0 = phi i32 [ 0, %if.then ], [ %add, %if.else ]
193 ; CHECK-LABEL: @caller5
194 ; CHECK: %call = call i32 @recursive_f(i32 42)
195 ; CHECK-NEXT: ret i32 %call
196 define i32 @caller5() {
198 %call = call i32 @recursive_f(i32 42)
202 define internal i32 @callee6.1(i32 %i) {
203 ; CHECK-LABEL: define internal i32 @callee6.1(
204 ; CHECK-NEXT: %res = call i32 @callee6.2(i32 %i)
205 ; CHECK-NEXT: ret i32 undef
207 %res = call i32 @callee6.2(i32 %i)
211 define internal i32 @callee6.2(i32 %i) {
212 ; CHECK-LABEL: define internal i32 @callee6.2(i32 %i) {
213 ; CHECK-NEXT: br label %if.then
215 ; CHECK-LABEL: if.then:
216 ; CHECK-NEXT: ret i32 undef
218 %cmp = icmp ne i32 %i, 0
219 br i1 %cmp, label %if.then, label %if.else
221 if.then: ; preds = %entry
224 if.else: ; preds = %entry
228 define i32 @caller6() {
229 ; CHECK-LABEL: define i32 @caller6() {
230 ; CHECK-NEXT: %call.1 = call i32 @callee6.1(i32 30)
231 ; CHECK-NEXT: %call.2 = call i32 @callee6.1(i32 43)
232 ; CHECK-NEXT: ret i32 2
234 %call.1 = call i32 @callee6.1(i32 30)
235 %call.2 = call i32 @callee6.1(i32 43)
236 %res = add i32 %call.1, %call.2