1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -instcombine < %s | FileCheck %s
4 define i1 @i32_cast_cmp_oeq_int_0_uitofp(i32 %i) {
5 ; CHECK-LABEL: @i32_cast_cmp_oeq_int_0_uitofp(
6 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[I:%.*]], 0
7 ; CHECK-NEXT: ret i1 [[CMP]]
9 %f = uitofp i32 %i to float
10 %cmp = fcmp oeq float %f, 0.0
14 define i1 @i32_cast_cmp_oeq_int_n0_uitofp(i32 %i) {
15 ; CHECK-LABEL: @i32_cast_cmp_oeq_int_n0_uitofp(
16 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[I:%.*]], 0
17 ; CHECK-NEXT: ret i1 [[CMP]]
19 %f = uitofp i32 %i to float
20 %cmp = fcmp oeq float %f, -0.0
24 define i1 @i32_cast_cmp_oeq_int_0_sitofp(i32 %i) {
25 ; CHECK-LABEL: @i32_cast_cmp_oeq_int_0_sitofp(
26 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[I:%.*]], 0
27 ; CHECK-NEXT: ret i1 [[CMP]]
29 %f = sitofp i32 %i to float
30 %cmp = fcmp oeq float %f, 0.0
34 define i1 @i32_cast_cmp_oeq_int_n0_sitofp(i32 %i) {
35 ; CHECK-LABEL: @i32_cast_cmp_oeq_int_n0_sitofp(
36 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[I:%.*]], 0
37 ; CHECK-NEXT: ret i1 [[CMP]]
39 %f = sitofp i32 %i to float
40 %cmp = fcmp oeq float %f, -0.0
44 define i1 @i32_cast_cmp_one_int_0_uitofp(i32 %i) {
45 ; CHECK-LABEL: @i32_cast_cmp_one_int_0_uitofp(
46 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 [[I:%.*]], 0
47 ; CHECK-NEXT: ret i1 [[CMP]]
49 %f = uitofp i32 %i to float
50 %cmp = fcmp one float %f, 0.0
54 define i1 @i32_cast_cmp_one_int_n0_uitofp(i32 %i) {
55 ; CHECK-LABEL: @i32_cast_cmp_one_int_n0_uitofp(
56 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 [[I:%.*]], 0
57 ; CHECK-NEXT: ret i1 [[CMP]]
59 %f = uitofp i32 %i to float
60 %cmp = fcmp one float %f, -0.0
64 define i1 @i32_cast_cmp_one_int_0_sitofp(i32 %i) {
65 ; CHECK-LABEL: @i32_cast_cmp_one_int_0_sitofp(
66 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 [[I:%.*]], 0
67 ; CHECK-NEXT: ret i1 [[CMP]]
69 %f = sitofp i32 %i to float
70 %cmp = fcmp one float %f, 0.0
74 define i1 @i32_cast_cmp_one_int_n0_sitofp(i32 %i) {
75 ; CHECK-LABEL: @i32_cast_cmp_one_int_n0_sitofp(
76 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 [[I:%.*]], 0
77 ; CHECK-NEXT: ret i1 [[CMP]]
79 %f = sitofp i32 %i to float
80 %cmp = fcmp one float %f, -0.0
84 define i1 @i32_cast_cmp_ueq_int_0_uitofp(i32 %i) {
85 ; CHECK-LABEL: @i32_cast_cmp_ueq_int_0_uitofp(
86 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[I:%.*]], 0
87 ; CHECK-NEXT: ret i1 [[CMP]]
89 %f = uitofp i32 %i to float
90 %cmp = fcmp ueq float %f, 0.0
94 define i1 @i32_cast_cmp_ueq_int_n0_uitofp(i32 %i) {
95 ; CHECK-LABEL: @i32_cast_cmp_ueq_int_n0_uitofp(
96 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[I:%.*]], 0
97 ; CHECK-NEXT: ret i1 [[CMP]]
99 %f = uitofp i32 %i to float
100 %cmp = fcmp ueq float %f, -0.0
104 define i1 @i32_cast_cmp_ueq_int_0_sitofp(i32 %i) {
105 ; CHECK-LABEL: @i32_cast_cmp_ueq_int_0_sitofp(
106 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[I:%.*]], 0
107 ; CHECK-NEXT: ret i1 [[CMP]]
109 %f = sitofp i32 %i to float
110 %cmp = fcmp ueq float %f, 0.0
114 define i1 @i32_cast_cmp_ueq_int_n0_sitofp(i32 %i) {
115 ; CHECK-LABEL: @i32_cast_cmp_ueq_int_n0_sitofp(
116 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[I:%.*]], 0
117 ; CHECK-NEXT: ret i1 [[CMP]]
119 %f = sitofp i32 %i to float
120 %cmp = fcmp ueq float %f, -0.0
124 define i1 @i32_cast_cmp_une_int_0_uitofp(i32 %i) {
125 ; CHECK-LABEL: @i32_cast_cmp_une_int_0_uitofp(
126 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 [[I:%.*]], 0
127 ; CHECK-NEXT: ret i1 [[CMP]]
129 %f = uitofp i32 %i to float
130 %cmp = fcmp une float %f, 0.0
134 define i1 @i32_cast_cmp_une_int_n0_uitofp(i32 %i) {
135 ; CHECK-LABEL: @i32_cast_cmp_une_int_n0_uitofp(
136 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 [[I:%.*]], 0
137 ; CHECK-NEXT: ret i1 [[CMP]]
139 %f = uitofp i32 %i to float
140 %cmp = fcmp une float %f, -0.0
144 define i1 @i32_cast_cmp_une_int_0_sitofp(i32 %i) {
145 ; CHECK-LABEL: @i32_cast_cmp_une_int_0_sitofp(
146 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 [[I:%.*]], 0
147 ; CHECK-NEXT: ret i1 [[CMP]]
149 %f = sitofp i32 %i to float
150 %cmp = fcmp une float %f, 0.0
154 define i1 @i32_cast_cmp_une_int_n0_sitofp(i32 %i) {
155 ; CHECK-LABEL: @i32_cast_cmp_une_int_n0_sitofp(
156 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 [[I:%.*]], 0
157 ; CHECK-NEXT: ret i1 [[CMP]]
159 %f = sitofp i32 %i to float
160 %cmp = fcmp une float %f, -0.0
164 define i1 @i32_cast_cmp_ogt_int_0_uitofp(i32 %i) {
165 ; CHECK-LABEL: @i32_cast_cmp_ogt_int_0_uitofp(
166 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 [[I:%.*]], 0
167 ; CHECK-NEXT: ret i1 [[CMP]]
169 %f = uitofp i32 %i to float
170 %cmp = fcmp ogt float %f, 0.0
174 define i1 @i32_cast_cmp_ogt_int_n0_uitofp(i32 %i) {
175 ; CHECK-LABEL: @i32_cast_cmp_ogt_int_n0_uitofp(
176 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 [[I:%.*]], 0
177 ; CHECK-NEXT: ret i1 [[CMP]]
179 %f = uitofp i32 %i to float
180 %cmp = fcmp ogt float %f, -0.0
184 define i1 @i32_cast_cmp_ogt_int_0_sitofp(i32 %i) {
185 ; CHECK-LABEL: @i32_cast_cmp_ogt_int_0_sitofp(
186 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[I:%.*]], 0
187 ; CHECK-NEXT: ret i1 [[CMP]]
189 %f = sitofp i32 %i to float
190 %cmp = fcmp ogt float %f, 0.0
194 define i1 @i32_cast_cmp_ogt_int_n0_sitofp(i32 %i) {
195 ; CHECK-LABEL: @i32_cast_cmp_ogt_int_n0_sitofp(
196 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[I:%.*]], 0
197 ; CHECK-NEXT: ret i1 [[CMP]]
199 %f = sitofp i32 %i to float
200 %cmp = fcmp ogt float %f, -0.0
204 define i1 @i32_cast_cmp_ole_int_0_uitofp(i32 %i) {
205 ; CHECK-LABEL: @i32_cast_cmp_ole_int_0_uitofp(
206 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[I:%.*]], 0
207 ; CHECK-NEXT: ret i1 [[CMP]]
209 %f = uitofp i32 %i to float
210 %cmp = fcmp ole float %f, 0.0
214 define i1 @i32_cast_cmp_ole_int_0_sitofp(i32 %i) {
215 ; CHECK-LABEL: @i32_cast_cmp_ole_int_0_sitofp(
216 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[I:%.*]], 1
217 ; CHECK-NEXT: ret i1 [[CMP]]
219 %f = sitofp i32 %i to float
220 %cmp = fcmp ole float %f, 0.0
224 define i1 @i32_cast_cmp_olt_int_0_sitofp(i32 %i) {
225 ; CHECK-LABEL: @i32_cast_cmp_olt_int_0_sitofp(
226 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[I:%.*]], 0
227 ; CHECK-NEXT: ret i1 [[CMP]]
229 %f = sitofp i32 %i to float
230 %cmp = fcmp olt float %f, 0.0
234 define i1 @i64_cast_cmp_oeq_int_0_uitofp(i64 %i) {
235 ; CHECK-LABEL: @i64_cast_cmp_oeq_int_0_uitofp(
236 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i64 [[I:%.*]], 0
237 ; CHECK-NEXT: ret i1 [[CMP]]
239 %f = uitofp i64 %i to float
240 %cmp = fcmp oeq float %f, 0.0
244 define i1 @i64_cast_cmp_oeq_int_0_sitofp(i64 %i) {
245 ; CHECK-LABEL: @i64_cast_cmp_oeq_int_0_sitofp(
246 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i64 [[I:%.*]], 0
247 ; CHECK-NEXT: ret i1 [[CMP]]
249 %f = sitofp i64 %i to float
250 %cmp = fcmp oeq float %f, 0.0
254 define i1 @i64_cast_cmp_oeq_int_0_uitofp_half(i64 %i) {
255 ; CHECK-LABEL: @i64_cast_cmp_oeq_int_0_uitofp_half(
256 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i64 [[I:%.*]], 0
257 ; CHECK-NEXT: ret i1 [[CMP]]
259 %f = uitofp i64 %i to half
260 %cmp = fcmp oeq half %f, 0.0
264 define i1 @i64_cast_cmp_oeq_int_0_sitofp_half(i64 %i) {
265 ; CHECK-LABEL: @i64_cast_cmp_oeq_int_0_sitofp_half(
266 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i64 [[I:%.*]], 0
267 ; CHECK-NEXT: ret i1 [[CMP]]
269 %f = sitofp i64 %i to half
270 %cmp = fcmp oeq half %f, 0.0
274 define i1 @i32_cast_cmp_oeq_int_0_uitofp_ppcf128(i32 %i) {
275 ; CHECK-LABEL: @i32_cast_cmp_oeq_int_0_uitofp_ppcf128(
276 ; CHECK-NEXT: [[F:%.*]] = uitofp i32 [[I:%.*]] to ppc_fp128
277 ; CHECK-NEXT: [[CMP:%.*]] = fcmp oeq ppc_fp128 [[F]], 0xM00000000000000000000000000000000
278 ; CHECK-NEXT: ret i1 [[CMP]]
280 %f = uitofp i32 %i to ppc_fp128
281 %cmp = fcmp oeq ppc_fp128 %f, 0xM00000000000000000000000000000000
285 ; Since 0xFFFFFF fits in a float, and one less and
286 ; one more than it also fits without rounding, the
287 ; test can be optimized to an integer compare.
289 define i1 @i32_cast_cmp_oeq_int_i24max_uitofp(i32 %i) {
290 ; CHECK-LABEL: @i32_cast_cmp_oeq_int_i24max_uitofp(
291 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[I:%.*]], 16777215
292 ; CHECK-NEXT: ret i1 [[CMP]]
294 %f = uitofp i32 %i to float
295 %cmp = fcmp oeq float %f, 0x416FFFFFE0000000
299 define i1 @i32_cast_cmp_oeq_int_i24max_sitofp(i32 %i) {
300 ; CHECK-LABEL: @i32_cast_cmp_oeq_int_i24max_sitofp(
301 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[I:%.*]], 16777215
302 ; CHECK-NEXT: ret i1 [[CMP]]
304 %f = sitofp i32 %i to float
305 %cmp = fcmp oeq float %f, 0x416FFFFFE0000000
309 ; Though 0x1000000 fits in a float, one more than it
310 ; would round to it too, hence a single integer comparison
314 define i1 @i32_cast_cmp_oeq_int_i24maxp1_uitofp(i32 %i) {
315 ; CHECK-LABEL: @i32_cast_cmp_oeq_int_i24maxp1_uitofp(
316 ; CHECK-NEXT: [[F:%.*]] = uitofp i32 [[I:%.*]] to float
317 ; CHECK-NEXT: [[CMP:%.*]] = fcmp oeq float [[F]], 0x4170000000000000
318 ; CHECK-NEXT: ret i1 [[CMP]]
320 %f = uitofp i32 %i to float
321 %cmp = fcmp oeq float %f, 0x4170000000000000
326 define i1 @i32_cast_cmp_oeq_int_i24maxp1_sitofp(i32 %i) {
327 ; CHECK-LABEL: @i32_cast_cmp_oeq_int_i24maxp1_sitofp(
328 ; CHECK-NEXT: [[F:%.*]] = sitofp i32 [[I:%.*]] to float
329 ; CHECK-NEXT: [[CMP:%.*]] = fcmp oeq float [[F]], 0x4170000000000000
330 ; CHECK-NEXT: ret i1 [[CMP]]
332 %f = sitofp i32 %i to float
333 %cmp = fcmp oeq float %f, 0x4170000000000000
337 define i1 @i32_cast_cmp_oeq_int_i32umax_uitofp(i32 %i) {
338 ; CHECK-LABEL: @i32_cast_cmp_oeq_int_i32umax_uitofp(
339 ; CHECK-NEXT: [[F:%.*]] = uitofp i32 [[I:%.*]] to float
340 ; CHECK-NEXT: [[CMP:%.*]] = fcmp oeq float [[F]], 0x41F0000000000000
341 ; CHECK-NEXT: ret i1 [[CMP]]
343 %f = uitofp i32 %i to float
344 %cmp = fcmp oeq float %f, 0x41F0000000000000
348 ; 32-bit unsigned integer cannot possibly round up to 1<<33
349 define i1 @i32_cast_cmp_oeq_int_big_uitofp(i32 %i) {
350 ; CHECK-LABEL: @i32_cast_cmp_oeq_int_big_uitofp(
351 ; CHECK-NEXT: ret i1 false
353 %f = uitofp i32 %i to float
354 %cmp = fcmp oeq float %f, 0x4200000000000000
358 ; 32-bit signed integer cannot possibly round up to 1<<32
359 define i1 @i32_cast_cmp_oeq_int_i32umax_sitofp(i32 %i) {
360 ; CHECK-LABEL: @i32_cast_cmp_oeq_int_i32umax_sitofp(
361 ; CHECK-NEXT: ret i1 false
363 %f = sitofp i32 %i to float
364 %cmp = fcmp oeq float %f, 0x41F0000000000000
368 define i1 @i32_cast_cmp_oeq_int_i32imin_sitofp(i32 %i) {
369 ; CHECK-LABEL: @i32_cast_cmp_oeq_int_i32imin_sitofp(
370 ; CHECK-NEXT: [[F:%.*]] = sitofp i32 [[I:%.*]] to float
371 ; CHECK-NEXT: [[CMP:%.*]] = fcmp oeq float [[F]], 0xC1E0000000000000
372 ; CHECK-NEXT: ret i1 [[CMP]]
374 %f = sitofp i32 %i to float
375 %cmp = fcmp oeq float %f, 0xC1E0000000000000
379 define i1 @i32_cast_cmp_oeq_int_i32imax_uitofp(i32 %i) {
380 ; CHECK-LABEL: @i32_cast_cmp_oeq_int_i32imax_uitofp(
381 ; CHECK-NEXT: [[F:%.*]] = uitofp i32 [[I:%.*]] to float
382 ; CHECK-NEXT: [[CMP:%.*]] = fcmp oeq float [[F]], 0x41E0000000000000
383 ; CHECK-NEXT: ret i1 [[CMP]]
385 %f = uitofp i32 %i to float
386 %cmp = fcmp oeq float %f, 0x41E0000000000000
390 define i1 @i32_cast_cmp_oeq_int_i32imax_sitofp(i32 %i) {
391 ; CHECK-LABEL: @i32_cast_cmp_oeq_int_i32imax_sitofp(
392 ; CHECK-NEXT: [[F:%.*]] = sitofp i32 [[I:%.*]] to float
393 ; CHECK-NEXT: [[CMP:%.*]] = fcmp oeq float [[F]], 0x41E0000000000000
394 ; CHECK-NEXT: ret i1 [[CMP]]
396 %f = sitofp i32 %i to float
397 %cmp = fcmp oeq float %f, 0x41E0000000000000
401 ; 32-bit signed integer cannot possibly round to -1<<32
402 define i1 @i32_cast_cmp_oeq_int_negi32umax_sitofp(i32 %i) {
403 ; CHECK-LABEL: @i32_cast_cmp_oeq_int_negi32umax_sitofp(
404 ; CHECK-NEXT: ret i1 false
406 %f = sitofp i32 %i to float
407 %cmp = fcmp oeq float %f, 0xC1F0000000000000
411 define i1 @i32_cast_cmp_oeq_half_uitofp(i32 %i) {
412 ; CHECK-LABEL: @i32_cast_cmp_oeq_half_uitofp(
413 ; CHECK-NEXT: ret i1 false
415 %f = uitofp i32 %i to float
416 %cmp = fcmp oeq float %f, 0.5
420 define i1 @i32_cast_cmp_oeq_half_sitofp(i32 %i) {
421 ; CHECK-LABEL: @i32_cast_cmp_oeq_half_sitofp(
422 ; CHECK-NEXT: ret i1 false
424 %f = sitofp i32 %i to float
425 %cmp = fcmp oeq float %f, 0.5
429 define i1 @i32_cast_cmp_one_half_uitofp(i32 %i) {
430 ; CHECK-LABEL: @i32_cast_cmp_one_half_uitofp(
431 ; CHECK-NEXT: ret i1 true
433 %f = uitofp i32 %i to float
434 %cmp = fcmp one float %f, 0.5
438 define i1 @i32_cast_cmp_one_half_sitofp(i32 %i) {
439 ; CHECK-LABEL: @i32_cast_cmp_one_half_sitofp(
440 ; CHECK-NEXT: ret i1 true
442 %f = sitofp i32 %i to float
443 %cmp = fcmp one float %f, 0.5
447 define i1 @i32_cast_cmp_ueq_half_uitofp(i32 %i) {
448 ; CHECK-LABEL: @i32_cast_cmp_ueq_half_uitofp(
449 ; CHECK-NEXT: ret i1 false
451 %f = uitofp i32 %i to float
452 %cmp = fcmp ueq float %f, 0.5
456 define i1 @i32_cast_cmp_ueq_half_sitofp(i32 %i) {
457 ; CHECK-LABEL: @i32_cast_cmp_ueq_half_sitofp(
458 ; CHECK-NEXT: ret i1 false
460 %f = sitofp i32 %i to float
461 %cmp = fcmp ueq float %f, 0.5
465 define i1 @i32_cast_cmp_une_half_uitofp(i32 %i) {
466 ; CHECK-LABEL: @i32_cast_cmp_une_half_uitofp(
467 ; CHECK-NEXT: ret i1 true
469 %f = uitofp i32 %i to float
470 %cmp = fcmp une float %f, 0.5
474 define i1 @i32_cast_cmp_une_half_sitofp(i32 %i) {
475 ; CHECK-LABEL: @i32_cast_cmp_une_half_sitofp(
476 ; CHECK-NEXT: ret i1 true
478 %f = sitofp i32 %i to float
479 %cmp = fcmp une float %f, 0.5
483 define i1 @i32_cast_cmp_oeq_int_inf_uitofp(i32 %i) {
484 ; CHECK-LABEL: @i32_cast_cmp_oeq_int_inf_uitofp(
485 ; CHECK-NEXT: ret i1 false
487 %f = uitofp i32 %i to float
488 %cmp = fcmp oeq float %f, 0x7FF0000000000000
492 define i1 @i32_cast_cmp_oeq_int_inf_sitofp(i32 %i) {
493 ; CHECK-LABEL: @i32_cast_cmp_oeq_int_inf_sitofp(
494 ; CHECK-NEXT: ret i1 false
496 %f = sitofp i32 %i to float
497 %cmp = fcmp oeq float %f, 0x7FF0000000000000
501 ; An i128 could round to an IEEE single-precision infinity.
502 define i1 @i128_cast_cmp_oeq_int_inf_uitofp(i128 %i) {
503 ; CHECK-LABEL: @i128_cast_cmp_oeq_int_inf_uitofp(
504 ; CHECK-NEXT: [[F:%.*]] = uitofp i128 [[I:%.*]] to float
505 ; CHECK-NEXT: [[CMP:%.*]] = fcmp oeq float [[F]], 0x7FF0000000000000
506 ; CHECK-NEXT: ret i1 [[CMP]]
508 %f = uitofp i128 %i to float
509 %cmp = fcmp oeq float %f, 0x7FF0000000000000