1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=ipsccp -S | FileCheck %s
5 define internal i1 @f.trunc(i32 %x) {
6 ; CHECK-LABEL: @f.trunc(
7 ; CHECK-NEXT: [[T_1:%.*]] = trunc i32 [[X:%.*]] to i16
8 ; CHECK-NEXT: [[C_2:%.*]] = icmp sgt i16 [[T_1]], 299
9 ; CHECK-NEXT: [[C_4:%.*]] = icmp slt i16 [[T_1]], 101
10 ; CHECK-NEXT: [[RES_1:%.*]] = add nuw nsw i1 false, [[C_2]]
11 ; CHECK-NEXT: [[RES_2:%.*]] = add nuw nsw i1 [[RES_1]], false
12 ; CHECK-NEXT: [[RES_3:%.*]] = add i1 [[RES_2]], [[C_4]]
13 ; CHECK-NEXT: [[T_2:%.*]] = trunc i32 [[X]] to i8
14 ; CHECK-NEXT: [[C_5:%.*]] = icmp sgt i8 [[T_2]], 44
15 ; CHECK-NEXT: [[C_6:%.*]] = icmp sgt i8 [[T_2]], 43
16 ; CHECK-NEXT: [[C_7:%.*]] = icmp slt i8 [[T_2]], 100
17 ; CHECK-NEXT: [[C_8:%.*]] = icmp slt i8 [[T_2]], 101
18 ; CHECK-NEXT: [[RES_4:%.*]] = add i1 [[RES_3]], [[C_5]]
19 ; CHECK-NEXT: [[RES_5:%.*]] = add i1 [[RES_4]], [[C_6]]
20 ; CHECK-NEXT: [[RES_6:%.*]] = add i1 [[RES_5]], [[C_7]]
21 ; CHECK-NEXT: [[RES_7:%.*]] = add i1 [[RES_6]], [[C_8]]
22 ; CHECK-NEXT: ret i1 [[RES_7]]
25 %t.1 = trunc i32 %x to i16
26 %c.1 = icmp sgt i16 %t.1, 300
27 %c.2 = icmp sgt i16 %t.1, 299
28 %c.3 = icmp slt i16 %t.1, 100
29 %c.4 = icmp slt i16 %t.1, 101
30 %res.1 = add i1 %c.1, %c.2
31 %res.2 = add i1 %res.1, %c.3
32 %res.3 = add i1 %res.2, %c.4
33 %t.2 = trunc i32 %x to i8
34 %c.5 = icmp sgt i8 %t.2, 300
35 %c.6 = icmp sgt i8 %t.2, 299
36 %c.7 = icmp slt i8 %t.2, 100
37 %c.8 = icmp slt i8 %t.2, 101
38 %res.4 = add i1 %res.3, %c.5
39 %res.5 = add i1 %res.4, %c.6
40 %res.6 = add i1 %res.5, %c.7
41 %res.7 = add i1 %res.6, %c.8
45 define i1 @caller1() {
46 ; CHECK-LABEL: @caller1(
47 ; CHECK-NEXT: [[CALL_1:%.*]] = tail call i1 @f.trunc(i32 100)
48 ; CHECK-NEXT: [[CALL_2:%.*]] = tail call i1 @f.trunc(i32 300)
49 ; CHECK-NEXT: [[RES:%.*]] = and i1 [[CALL_1]], [[CALL_2]]
50 ; CHECK-NEXT: ret i1 [[RES]]
52 %call.1 = tail call i1 @f.trunc(i32 100)
53 %call.2 = tail call i1 @f.trunc(i32 300)
54 %res = and i1 %call.1, %call.2
60 define internal i1 @f.zext(i32 %x, i32 %y) {
61 ; CHECK-LABEL: @f.zext(
62 ; CHECK-NEXT: [[T_1:%.*]] = zext nneg i32 [[X:%.*]] to i64
63 ; CHECK-NEXT: [[C_2:%.*]] = icmp sgt i64 [[T_1]], 299
64 ; CHECK-NEXT: [[C_4:%.*]] = icmp slt i64 [[T_1]], 101
65 ; CHECK-NEXT: [[RES_1:%.*]] = add nuw nsw i1 false, [[C_2]]
66 ; CHECK-NEXT: [[RES_2:%.*]] = add nuw nsw i1 [[RES_1]], false
67 ; CHECK-NEXT: [[RES_3:%.*]] = add i1 [[RES_2]], [[C_4]]
68 ; CHECK-NEXT: [[T_2:%.*]] = zext i32 [[Y:%.*]] to i64
69 ; CHECK-NEXT: [[C_5:%.*]] = icmp sgt i64 [[T_2]], 300
70 ; CHECK-NEXT: [[C_6:%.*]] = icmp sgt i64 [[T_2]], 299
71 ; CHECK-NEXT: [[C_8:%.*]] = icmp slt i64 [[T_2]], 1
72 ; CHECK-NEXT: [[RES_4:%.*]] = add i1 [[RES_3]], [[C_5]]
73 ; CHECK-NEXT: [[RES_5:%.*]] = add i1 [[RES_4]], [[C_6]]
74 ; CHECK-NEXT: [[RES_6:%.*]] = add nuw nsw i1 [[RES_5]], false
75 ; CHECK-NEXT: [[RES_7:%.*]] = add i1 [[RES_6]], [[C_8]]
76 ; CHECK-NEXT: ret i1 [[RES_7]]
79 %t.1 = zext i32 %x to i64
80 %c.1 = icmp sgt i64 %t.1, 300
81 %c.2 = icmp sgt i64 %t.1, 299
82 %c.3 = icmp slt i64 %t.1, 100
83 %c.4 = icmp slt i64 %t.1, 101
84 %res.1 = add i1 %c.1, %c.2
85 %res.2 = add i1 %res.1, %c.3
86 %res.3 = add i1 %res.2, %c.4
87 %t.2 = zext i32 %y to i64
88 %c.5 = icmp sgt i64 %t.2, 300
89 %c.6 = icmp sgt i64 %t.2, 299
90 %c.7 = icmp slt i64 %t.2, 0
91 %c.8 = icmp slt i64 %t.2, 1
92 %res.4 = add i1 %res.3, %c.5
93 %res.5 = add i1 %res.4, %c.6
94 %res.6 = add i1 %res.5, %c.7
95 %res.7 = add i1 %res.6, %c.8
99 define i1 @caller.zext() {
100 ; CHECK-LABEL: @caller.zext(
101 ; CHECK-NEXT: [[CALL_1:%.*]] = tail call i1 @f.zext(i32 100, i32 -120)
102 ; CHECK-NEXT: [[CALL_2:%.*]] = tail call i1 @f.zext(i32 300, i32 900)
103 ; CHECK-NEXT: [[RES:%.*]] = and i1 [[CALL_1]], [[CALL_2]]
104 ; CHECK-NEXT: ret i1 [[RES]]
106 %call.1 = tail call i1 @f.zext(i32 100, i32 -120)
107 %call.2 = tail call i1 @f.zext(i32 300, i32 900)
108 %res = and i1 %call.1, %call.2
113 define internal i1 @f.sext(i32 %x, i32 %y) {
114 ; CHECK-LABEL: @f.sext(
115 ; CHECK-NEXT: [[T_1:%.*]] = zext nneg i32 [[X:%.*]] to i64
116 ; CHECK-NEXT: [[C_2:%.*]] = icmp sgt i64 [[T_1]], 299
117 ; CHECK-NEXT: [[C_4:%.*]] = icmp slt i64 [[T_1]], 101
118 ; CHECK-NEXT: [[RES_1:%.*]] = add nuw nsw i1 false, [[C_2]]
119 ; CHECK-NEXT: [[RES_2:%.*]] = add nuw nsw i1 [[RES_1]], false
120 ; CHECK-NEXT: [[RES_3:%.*]] = add i1 [[RES_2]], [[C_4]]
121 ; CHECK-NEXT: [[T_2:%.*]] = sext i32 [[Y:%.*]] to i64
122 ; CHECK-NEXT: [[C_6:%.*]] = icmp sgt i64 [[T_2]], 899
123 ; CHECK-NEXT: [[C_8:%.*]] = icmp slt i64 [[T_2]], -119
124 ; CHECK-NEXT: [[RES_4:%.*]] = add nuw nsw i1 [[RES_3]], false
125 ; CHECK-NEXT: [[RES_5:%.*]] = add i1 [[RES_4]], [[C_6]]
126 ; CHECK-NEXT: [[RES_6:%.*]] = add nuw nsw i1 [[RES_5]], false
127 ; CHECK-NEXT: [[RES_7:%.*]] = add i1 [[RES_6]], [[C_8]]
128 ; CHECK-NEXT: ret i1 [[RES_7]]
130 %t.1 = sext i32 %x to i64
131 %c.1 = icmp sgt i64 %t.1, 300
132 %c.2 = icmp sgt i64 %t.1, 299
133 %c.3 = icmp slt i64 %t.1, 100
134 %c.4 = icmp slt i64 %t.1, 101
135 %res.1 = add i1 %c.1, %c.2
136 %res.2 = add i1 %res.1, %c.3
137 %res.3 = add i1 %res.2, %c.4
138 %t.2 = sext i32 %y to i64
139 %c.5 = icmp sgt i64 %t.2, 900
140 %c.6 = icmp sgt i64 %t.2, 899
141 %c.7 = icmp slt i64 %t.2, -120
142 %c.8 = icmp slt i64 %t.2, -119
143 %res.4 = add i1 %res.3, %c.5
144 %res.5 = add i1 %res.4, %c.6
145 %res.6 = add i1 %res.5, %c.7
146 %res.7 = add i1 %res.6, %c.8
150 define i1 @caller.sext() {
151 ; CHECK-LABEL: @caller.sext(
152 ; CHECK-NEXT: [[CALL_1:%.*]] = tail call i1 @f.sext(i32 100, i32 -120)
153 ; CHECK-NEXT: [[CALL_2:%.*]] = tail call i1 @f.sext(i32 300, i32 900)
154 ; CHECK-NEXT: [[RES:%.*]] = and i1 [[CALL_1]], [[CALL_2]]
155 ; CHECK-NEXT: ret i1 [[RES]]
157 %call.1 = tail call i1 @f.sext(i32 100, i32 -120)
158 %call.2 = tail call i1 @f.sext(i32 300, i32 900)
159 %res = and i1 %call.1, %call.2
163 ; There's nothing we can do besides going to the full range or overdefined.
164 define internal i1 @f.fptosi(i32 %x) {
165 ; CHECK-LABEL: @f.fptosi(
166 ; CHECK-NEXT: [[TO_DOUBLE:%.*]] = sitofp i32 [[X:%.*]] to double
167 ; CHECK-NEXT: [[ADD:%.*]] = fadd double 0.000000e+00, [[TO_DOUBLE]]
168 ; CHECK-NEXT: [[TO_I32:%.*]] = fptosi double [[ADD]] to i32
169 ; CHECK-NEXT: [[C_1:%.*]] = icmp sgt i32 [[TO_I32]], 300
170 ; CHECK-NEXT: [[C_2:%.*]] = icmp sgt i32 [[TO_I32]], 299
171 ; CHECK-NEXT: [[C_3:%.*]] = icmp slt i32 [[TO_I32]], 100
172 ; CHECK-NEXT: [[C_4:%.*]] = icmp slt i32 [[TO_I32]], 101
173 ; CHECK-NEXT: [[RES_1:%.*]] = add i1 [[C_1]], [[C_2]]
174 ; CHECK-NEXT: [[RES_2:%.*]] = add i1 [[RES_1]], [[C_3]]
175 ; CHECK-NEXT: [[RES_3:%.*]] = add i1 [[RES_2]], [[C_4]]
176 ; CHECK-NEXT: ret i1 [[RES_3]]
178 %to.double = sitofp i32 %x to double
179 %add = fadd double 0.000000e+00, %to.double
180 %to.i32 = fptosi double %add to i32
181 %c.1 = icmp sgt i32 %to.i32, 300
182 %c.2 = icmp sgt i32 %to.i32, 299
183 %c.3 = icmp slt i32 %to.i32, 100
184 %c.4 = icmp slt i32 %to.i32, 101
185 %res.1 = add i1 %c.1, %c.2
186 %res.2 = add i1 %res.1, %c.3
187 %res.3 = add i1 %res.2, %c.4
191 define i1 @caller.fptosi() {
192 ; CHECK-LABEL: @caller.fptosi(
193 ; CHECK-NEXT: [[CALL_1:%.*]] = tail call i1 @f.fptosi(i32 100)
194 ; CHECK-NEXT: [[CALL_2:%.*]] = tail call i1 @f.fptosi(i32 300)
195 ; CHECK-NEXT: [[RES:%.*]] = and i1 [[CALL_1]], [[CALL_2]]
196 ; CHECK-NEXT: ret i1 [[RES]]
198 %call.1 = tail call i1 @f.fptosi(i32 100)
199 %call.2 = tail call i1 @f.fptosi(i32 300)
200 %res = and i1 %call.1, %call.2
204 ; There's nothing we can do besides going to the full range or overdefined.
205 define internal i1 @f.fpext(i16 %x) {
206 ; CHECK-LABEL: @f.fpext(
207 ; CHECK-NEXT: [[TO_FLOAT:%.*]] = sitofp i16 [[X:%.*]] to float
208 ; CHECK-NEXT: [[TO_DOUBLE:%.*]] = fpext float [[TO_FLOAT]] to double
209 ; CHECK-NEXT: [[TO_I64:%.*]] = fptoui float [[TO_FLOAT]] to i64
210 ; CHECK-NEXT: [[C_1:%.*]] = icmp sgt i64 [[TO_I64]], 300
211 ; CHECK-NEXT: [[C_2:%.*]] = icmp sgt i64 [[TO_I64]], 299
212 ; CHECK-NEXT: [[C_3:%.*]] = icmp slt i64 [[TO_I64]], 100
213 ; CHECK-NEXT: [[C_4:%.*]] = icmp slt i64 [[TO_I64]], 101
214 ; CHECK-NEXT: [[RES_1:%.*]] = add i1 [[C_1]], [[C_2]]
215 ; CHECK-NEXT: [[RES_2:%.*]] = add i1 [[RES_1]], [[C_3]]
216 ; CHECK-NEXT: [[RES_3:%.*]] = add i1 [[RES_2]], [[C_4]]
217 ; CHECK-NEXT: ret i1 [[RES_3]]
219 %to.float = sitofp i16 %x to float
220 %to.double = fpext float %to.float to double
221 %to.i64= fptoui float %to.float to i64
222 %c.1 = icmp sgt i64 %to.i64, 300
223 %c.2 = icmp sgt i64 %to.i64, 299
224 %c.3 = icmp slt i64 %to.i64, 100
225 %c.4 = icmp slt i64 %to.i64, 101
226 %res.1 = add i1 %c.1, %c.2
227 %res.2 = add i1 %res.1, %c.3
228 %res.3 = add i1 %res.2, %c.4
232 ; There's nothing we can do besides going to the full range or overdefined.
233 define i1 @caller.fpext() {
234 ; CHECK-LABEL: @caller.fpext(
235 ; CHECK-NEXT: [[CALL_1:%.*]] = tail call i1 @f.fpext(i16 100)
236 ; CHECK-NEXT: [[CALL_2:%.*]] = tail call i1 @f.fpext(i16 300)
237 ; CHECK-NEXT: [[RES:%.*]] = and i1 [[CALL_1]], [[CALL_2]]
238 ; CHECK-NEXT: ret i1 [[RES]]
240 %call.1 = tail call i1 @f.fpext(i16 100)
241 %call.2 = tail call i1 @f.fpext(i16 300)
242 %res = and i1 %call.1, %call.2
246 ; There's nothing we can do besides going to the full range or overdefined.
247 define internal i1 @f.inttoptr.ptrtoint(i64 %x) {
248 ; CHECK-LABEL: @f.inttoptr.ptrtoint(
249 ; CHECK-NEXT: [[TO_PTR:%.*]] = inttoptr i64 [[X:%.*]] to ptr
250 ; CHECK-NEXT: [[TO_I64:%.*]] = ptrtoint ptr [[TO_PTR]] to i64
251 ; CHECK-NEXT: [[C_1:%.*]] = icmp sgt i64 [[TO_I64]], 300
252 ; CHECK-NEXT: [[C_2:%.*]] = icmp sgt i64 [[TO_I64]], 299
253 ; CHECK-NEXT: [[C_3:%.*]] = icmp slt i64 [[TO_I64]], 100
254 ; CHECK-NEXT: [[C_4:%.*]] = icmp slt i64 [[TO_I64]], 101
255 ; CHECK-NEXT: [[RES_1:%.*]] = add i1 [[C_1]], [[C_2]]
256 ; CHECK-NEXT: [[RES_2:%.*]] = add i1 [[RES_1]], [[C_3]]
257 ; CHECK-NEXT: [[RES_3:%.*]] = add i1 [[RES_2]], [[C_4]]
258 ; CHECK-NEXT: ret i1 [[RES_3]]
260 %to.ptr = inttoptr i64 %x to ptr
261 %to.i64 = ptrtoint ptr %to.ptr to i64
262 %c.1 = icmp sgt i64 %to.i64, 300
263 %c.2 = icmp sgt i64 %to.i64, 299
264 %c.3 = icmp slt i64 %to.i64, 100
265 %c.4 = icmp slt i64 %to.i64, 101
266 %res.1 = add i1 %c.1, %c.2
267 %res.2 = add i1 %res.1, %c.3
268 %res.3 = add i1 %res.2, %c.4
272 define i1 @caller.inttoptr.ptrtoint() {
273 ; CHECK-LABEL: @caller.inttoptr.ptrtoint(
274 ; CHECK-NEXT: [[CALL_1:%.*]] = tail call i1 @f.inttoptr.ptrtoint(i64 100)
275 ; CHECK-NEXT: [[CALL_2:%.*]] = tail call i1 @f.inttoptr.ptrtoint(i64 300)
276 ; CHECK-NEXT: [[RES:%.*]] = and i1 [[CALL_1]], [[CALL_2]]
277 ; CHECK-NEXT: ret i1 [[RES]]
279 %call.1 = tail call i1 @f.inttoptr.ptrtoint(i64 100)
280 %call.2 = tail call i1 @f.inttoptr.ptrtoint(i64 300)
281 %res = and i1 %call.1, %call.2
285 ; Make sure we do not create constant ranges for int to fp casts.
286 define i1 @int_range_to_double_cast(i32 %a) {
287 ; CHECK-LABEL: @int_range_to_double_cast(
288 ; CHECK-NEXT: [[R:%.*]] = and i32 [[A:%.*]], 255
289 ; CHECK-NEXT: [[T4:%.*]] = sitofp i32 [[R]] to double
290 ; CHECK-NEXT: [[T10:%.*]] = fadd double 0.000000e+00, [[T4]]
291 ; CHECK-NEXT: [[T11:%.*]] = fcmp olt double [[T4]], [[T10]]
292 ; CHECK-NEXT: ret i1 [[T11]]
295 %t4 = sitofp i32 %r to double
296 %t10 = fadd double 0.000000e+00, %t4
297 %t11 = fcmp olt double %t4, %t10
301 ; Make sure we do not use ranges to propagate info from vectors.
302 define i16 @vector_binop_and_cast() {
303 ; CHECK-LABEL: @vector_binop_and_cast(
305 ; CHECK-NEXT: [[VECINIT7:%.*]] = insertelement <8 x i16> <i16 undef, i16 1, i16 2, i16 3, i16 4, i16 5, i16 6, i16 7>, i16 undef, i32 0
306 ; CHECK-NEXT: [[REM:%.*]] = srem <8 x i16> <i16 2, i16 2, i16 2, i16 2, i16 2, i16 2, i16 2, i16 2>, [[VECINIT7]]
307 ; CHECK-NEXT: [[TMP0:%.*]] = bitcast <8 x i16> [[REM]] to i128
308 ; CHECK-NEXT: [[TMP1:%.*]] = trunc i128 [[TMP0]] to i16
309 ; CHECK-NEXT: ret i16 [[TMP1]]
312 %vecinit7 = insertelement <8 x i16> <i16 undef, i16 1, i16 2, i16 3, i16 4, i16 5, i16 6, i16 7>, i16 undef, i32 0
313 %rem = srem <8 x i16> <i16 2, i16 2, i16 2, i16 2, i16 2, i16 2, i16 2, i16 2>, %vecinit7
314 %0 = bitcast <8 x i16> %rem to i128
315 %1 = trunc i128 %0 to i16
319 define internal i64 @f.sext_to_zext(i32 %t) {
320 ; CHECK-LABEL: @f.sext_to_zext(
321 ; CHECK-NEXT: [[A:%.*]] = zext nneg i32 [[T:%.*]] to i64
322 ; CHECK-NEXT: ret i64 [[A]]
324 %a = sext i32 %t to i64
328 define i64 @caller.sext_to_zext(i32 %i) {
329 ; CHECK-LABEL: @caller.sext_to_zext(
330 ; CHECK-NEXT: [[CMP:%.*]] = icmp sle i32 [[I:%.*]], 9
331 ; CHECK-NEXT: [[CONV:%.*]] = zext i1 [[CMP]] to i32
332 ; CHECK-NEXT: [[T:%.*]] = call i64 @f.sext_to_zext(i32 [[CONV]])
333 ; CHECK-NEXT: ret i64 [[T]]
335 %cmp = icmp sle i32 %i, 9
336 %conv = zext i1 %cmp to i32
337 %t = call i64 @f.sext_to_zext(i32 %conv)