1 ; RUN: opt -S -instcombine < %s | FileCheck %s
3 ; CHECK-LABEL: @i32_cast_cmp_oeq_int_0_uitofp(
4 ; CHECK-NEXT: icmp eq i32 %i, 0
6 define i1 @i32_cast_cmp_oeq_int_0_uitofp(i32 %i) {
7 %f = uitofp i32 %i to float
8 %cmp = fcmp oeq float %f, 0.0
12 ; CHECK-LABEL: @i32_cast_cmp_oeq_int_n0_uitofp(
13 ; CHECK-NEXT: icmp eq i32 %i, 0
15 define i1 @i32_cast_cmp_oeq_int_n0_uitofp(i32 %i) {
16 %f = uitofp i32 %i to float
17 %cmp = fcmp oeq float %f, -0.0
21 ; CHECK-LABEL: @i32_cast_cmp_oeq_int_0_sitofp(
22 ; CHECK-NEXT: icmp eq i32 %i, 0
24 define i1 @i32_cast_cmp_oeq_int_0_sitofp(i32 %i) {
25 %f = sitofp i32 %i to float
26 %cmp = fcmp oeq float %f, 0.0
30 ; CHECK-LABEL: @i32_cast_cmp_oeq_int_n0_sitofp(
31 ; CHECK-NEXT: icmp eq i32 %i, 0
33 define i1 @i32_cast_cmp_oeq_int_n0_sitofp(i32 %i) {
34 %f = sitofp i32 %i to float
35 %cmp = fcmp oeq float %f, -0.0
39 ; CHECK-LABEL: @i32_cast_cmp_one_int_0_uitofp(
40 ; CHECK-NEXT: icmp ne i32 %i, 0
42 define i1 @i32_cast_cmp_one_int_0_uitofp(i32 %i) {
43 %f = uitofp i32 %i to float
44 %cmp = fcmp one float %f, 0.0
48 ; CHECK-LABEL: @i32_cast_cmp_one_int_n0_uitofp(
49 ; CHECK-NEXT: icmp ne i32 %i, 0
51 define i1 @i32_cast_cmp_one_int_n0_uitofp(i32 %i) {
52 %f = uitofp i32 %i to float
53 %cmp = fcmp one float %f, -0.0
57 ; CHECK-LABEL: @i32_cast_cmp_one_int_0_sitofp(
58 ; CHECK-NEXT: icmp ne i32 %i, 0
60 define i1 @i32_cast_cmp_one_int_0_sitofp(i32 %i) {
61 %f = sitofp i32 %i to float
62 %cmp = fcmp one float %f, 0.0
66 ; CHECK-LABEL: @i32_cast_cmp_one_int_n0_sitofp(
67 ; CHECK-NEXT: icmp ne i32 %i, 0
69 define i1 @i32_cast_cmp_one_int_n0_sitofp(i32 %i) {
70 %f = sitofp i32 %i to float
71 %cmp = fcmp one float %f, -0.0
75 ; CHECK-LABEL: @i32_cast_cmp_ueq_int_0_uitofp(
76 ; CHECK-NEXT: icmp eq i32 %i, 0
78 define i1 @i32_cast_cmp_ueq_int_0_uitofp(i32 %i) {
79 %f = uitofp i32 %i to float
80 %cmp = fcmp ueq float %f, 0.0
84 ; CHECK-LABEL: @i32_cast_cmp_ueq_int_n0_uitofp(
85 ; CHECK-NEXT: icmp eq i32 %i, 0
87 define i1 @i32_cast_cmp_ueq_int_n0_uitofp(i32 %i) {
88 %f = uitofp i32 %i to float
89 %cmp = fcmp ueq float %f, -0.0
93 ; CHECK-LABEL: @i32_cast_cmp_ueq_int_0_sitofp(
94 ; CHECK-NEXT: icmp eq i32 %i, 0
96 define i1 @i32_cast_cmp_ueq_int_0_sitofp(i32 %i) {
97 %f = sitofp i32 %i to float
98 %cmp = fcmp ueq float %f, 0.0
102 ; CHECK-LABEL: @i32_cast_cmp_ueq_int_n0_sitofp(
103 ; CHECK-NEXT: icmp eq i32 %i, 0
105 define i1 @i32_cast_cmp_ueq_int_n0_sitofp(i32 %i) {
106 %f = sitofp i32 %i to float
107 %cmp = fcmp ueq float %f, -0.0
111 ; CHECK-LABEL: @i32_cast_cmp_une_int_0_uitofp(
112 ; CHECK-NEXT: icmp ne i32 %i, 0
114 define i1 @i32_cast_cmp_une_int_0_uitofp(i32 %i) {
115 %f = uitofp i32 %i to float
116 %cmp = fcmp une float %f, 0.0
120 ; CHECK-LABEL: @i32_cast_cmp_une_int_n0_uitofp(
121 ; CHECK-NEXT: icmp ne i32 %i, 0
123 define i1 @i32_cast_cmp_une_int_n0_uitofp(i32 %i) {
124 %f = uitofp i32 %i to float
125 %cmp = fcmp une float %f, -0.0
129 ; CHECK-LABEL: @i32_cast_cmp_une_int_0_sitofp(
130 ; CHECK-NEXT: icmp ne i32 %i, 0
132 define i1 @i32_cast_cmp_une_int_0_sitofp(i32 %i) {
133 %f = sitofp i32 %i to float
134 %cmp = fcmp une float %f, 0.0
138 ; CHECK-LABEL: @i32_cast_cmp_une_int_n0_sitofp(
139 ; CHECK-NEXT: icmp ne i32 %i, 0
141 define i1 @i32_cast_cmp_une_int_n0_sitofp(i32 %i) {
142 %f = sitofp i32 %i to float
143 %cmp = fcmp une float %f, -0.0
147 ; CHECK-LABEL: @i32_cast_cmp_ogt_int_0_uitofp(
148 ; CHECK: icmp ne i32 %i, 0
150 define i1 @i32_cast_cmp_ogt_int_0_uitofp(i32 %i) {
151 %f = uitofp i32 %i to float
152 %cmp = fcmp ogt float %f, 0.0
156 ; CHECK-LABEL: @i32_cast_cmp_ogt_int_n0_uitofp(
157 ; CHECK: icmp ne i32 %i, 0
159 define i1 @i32_cast_cmp_ogt_int_n0_uitofp(i32 %i) {
160 %f = uitofp i32 %i to float
161 %cmp = fcmp ogt float %f, -0.0
165 ; CHECK-LABEL: @i32_cast_cmp_ogt_int_0_sitofp(
166 ; CHECK: icmp sgt i32 %i, 0
168 define i1 @i32_cast_cmp_ogt_int_0_sitofp(i32 %i) {
169 %f = sitofp i32 %i to float
170 %cmp = fcmp ogt float %f, 0.0
174 ; CHECK-LABEL: @i32_cast_cmp_ogt_int_n0_sitofp(
175 ; CHECK: icmp sgt i32 %i, 0
177 define i1 @i32_cast_cmp_ogt_int_n0_sitofp(i32 %i) {
178 %f = sitofp i32 %i to float
179 %cmp = fcmp ogt float %f, -0.0
183 ; CHECK-LABEL: @i32_cast_cmp_ole_int_0_uitofp(
184 ; CHECK: icmp eq i32 %i, 0
186 define i1 @i32_cast_cmp_ole_int_0_uitofp(i32 %i) {
187 %f = uitofp i32 %i to float
188 %cmp = fcmp ole float %f, 0.0
192 ; CHECK-LABEL: @i32_cast_cmp_ole_int_0_sitofp(
193 ; CHECK: icmp slt i32 %i, 1
195 define i1 @i32_cast_cmp_ole_int_0_sitofp(i32 %i) {
196 %f = sitofp i32 %i to float
197 %cmp = fcmp ole float %f, 0.0
201 ; CHECK-LABEL: @i32_cast_cmp_olt_int_0_uitofp(
202 ; CHECK: ret i1 false
203 define i1 @i32_cast_cmp_olt_int_0_uitofp(i32 %i) {
204 %f = uitofp i32 %i to float
205 %cmp = fcmp olt float %f, 0.0
209 ; CHECK-LABEL: @i32_cast_cmp_olt_int_0_sitofp(
210 ; CHECK: icmp slt i32 %i, 0
212 define i1 @i32_cast_cmp_olt_int_0_sitofp(i32 %i) {
213 %f = sitofp i32 %i to float
214 %cmp = fcmp olt float %f, 0.0
218 ; CHECK-LABEL: @i64_cast_cmp_oeq_int_0_uitofp(
219 ; CHECK-NEXT: icmp eq i64 %i, 0
221 define i1 @i64_cast_cmp_oeq_int_0_uitofp(i64 %i) {
222 %f = uitofp i64 %i to float
223 %cmp = fcmp oeq float %f, 0.0
227 ; CHECK-LABEL: @i64_cast_cmp_oeq_int_0_sitofp(
228 ; CHECK-NEXT: icmp eq i64 %i, 0
230 define i1 @i64_cast_cmp_oeq_int_0_sitofp(i64 %i) {
231 %f = sitofp i64 %i to float
232 %cmp = fcmp oeq float %f, 0.0
236 ; CHECK-LABEL: @i64_cast_cmp_oeq_int_0_uitofp_half(
237 ; CHECK-NEXT: icmp eq i64 %i, 0
239 define i1 @i64_cast_cmp_oeq_int_0_uitofp_half(i64 %i) {
240 %f = uitofp i64 %i to half
241 %cmp = fcmp oeq half %f, 0.0
245 ; CHECK-LABEL: @i64_cast_cmp_oeq_int_0_sitofp_half(
246 ; CHECK-NEXT: icmp eq i64 %i, 0
248 define i1 @i64_cast_cmp_oeq_int_0_sitofp_half(i64 %i) {
249 %f = sitofp i64 %i to half
250 %cmp = fcmp oeq half %f, 0.0
254 ; CHECK-LABEL: @i32_cast_cmp_oeq_int_0_uitofp_ppcf128(
258 define i1 @i32_cast_cmp_oeq_int_0_uitofp_ppcf128(i32 %i) {
259 %f = uitofp i32 %i to ppc_fp128
260 %cmp = fcmp oeq ppc_fp128 %f, 0xM00000000000000000000000000000000
264 ; Since 0xFFFFFF fits in a float, and one less and
265 ; one more than it also fits without rounding, the
266 ; test can be optimized to an integer compare.
268 ; CHECK-LABEL: @i32_cast_cmp_oeq_int_i24max_uitofp(
269 ; CHECK: icmp eq i32 %i, 16777215
271 define i1 @i32_cast_cmp_oeq_int_i24max_uitofp(i32 %i) {
272 %f = uitofp i32 %i to float
273 %cmp = fcmp oeq float %f, 0x416FFFFFE0000000
277 ; CHECK-LABEL: @i32_cast_cmp_oeq_int_i24max_sitofp(
278 ; CHECK: icmp eq i32 %i, 16777215
280 define i1 @i32_cast_cmp_oeq_int_i24max_sitofp(i32 %i) {
281 %f = sitofp i32 %i to float
282 %cmp = fcmp oeq float %f, 0x416FFFFFE0000000
286 ; Though 0x1000000 fits in a float, one more than it
287 ; would round to it too, hence a single integer comparison
290 ; CHECK-LABEL: @i32_cast_cmp_oeq_int_i24maxp1_uitofp(
294 ; XCHECK: icmp eq i32 %i, 16777216
296 define i1 @i32_cast_cmp_oeq_int_i24maxp1_uitofp(i32 %i) {
297 %f = uitofp i32 %i to float
298 %cmp = fcmp oeq float %f, 0x4170000000000000
302 ; CHECK-LABEL: @i32_cast_cmp_oeq_int_i24maxp1_sitofp(
306 ; XCHECK: icmp eq i32 %i, 16777216
308 define i1 @i32_cast_cmp_oeq_int_i24maxp1_sitofp(i32 %i) {
309 %f = sitofp i32 %i to float
310 %cmp = fcmp oeq float %f, 0x4170000000000000
314 ; CHECK-LABEL: @i32_cast_cmp_oeq_int_i32umax_uitofp(
318 define i1 @i32_cast_cmp_oeq_int_i32umax_uitofp(i32 %i) {
319 %f = uitofp i32 %i to float
320 %cmp = fcmp oeq float %f, 0x41F0000000000000
324 ; 32-bit unsigned integer cannot possibly round up to 1<<33
325 ; CHECK-LABEL: @i32_cast_cmp_oeq_int_big_uitofp(
326 ; CHECK-NEXT: ret i1 false
327 define i1 @i32_cast_cmp_oeq_int_big_uitofp(i32 %i) {
328 %f = uitofp i32 %i to float
329 %cmp = fcmp oeq float %f, 0x4200000000000000
333 ; 32-bit signed integer cannot possibly round up to 1<<32
334 ; CHECK-LABEL: @i32_cast_cmp_oeq_int_i32umax_sitofp(
335 ; CHECK-NEXT: ret i1 false
336 define i1 @i32_cast_cmp_oeq_int_i32umax_sitofp(i32 %i) {
337 %f = sitofp i32 %i to float
338 %cmp = fcmp oeq float %f, 0x41F0000000000000
342 ; CHECK-LABEL: @i32_cast_cmp_oeq_int_i32imin_uitofp(
346 define i1 @i32_cast_cmp_oeq_int_i32imin_uitofp(i32 %i) {
347 %f = uitofp i32 %i to float
348 %cmp = fcmp oeq float %f, 0xC1E0000000000000
352 ; CHECK-LABEL: @i32_cast_cmp_oeq_int_i32imin_sitofp(
356 define i1 @i32_cast_cmp_oeq_int_i32imin_sitofp(i32 %i) {
357 %f = sitofp i32 %i to float
358 %cmp = fcmp oeq float %f, 0xC1E0000000000000
362 ; CHECK-LABEL: @i32_cast_cmp_oeq_int_i32imax_uitofp(
366 define i1 @i32_cast_cmp_oeq_int_i32imax_uitofp(i32 %i) {
367 %f = uitofp i32 %i to float
368 %cmp = fcmp oeq float %f, 0x41E0000000000000
372 ; CHECK-LABEL: @i32_cast_cmp_oeq_int_i32imax_sitofp(
376 define i1 @i32_cast_cmp_oeq_int_i32imax_sitofp(i32 %i) {
377 %f = sitofp i32 %i to float
378 %cmp = fcmp oeq float %f, 0x41E0000000000000
382 ; CHECK-LABEL: @i32_cast_cmp_oeq_int_negi32umax_uitofp(
386 define i1 @i32_cast_cmp_oeq_int_negi32umax_uitofp(i32 %i) {
387 %f = uitofp i32 %i to float
388 %cmp = fcmp oeq float %f, 0xC1F0000000000000
392 ; 32-bit signed integer cannot possibly round to -1<<32
393 ; CHECK-LABEL: @i32_cast_cmp_oeq_int_negi32umax_sitofp(
394 ; CHECK-NEXT: ret i1 false
395 define i1 @i32_cast_cmp_oeq_int_negi32umax_sitofp(i32 %i) {
396 %f = sitofp i32 %i to float
397 %cmp = fcmp oeq float %f, 0xC1F0000000000000
401 ; CHECK-LABEL: @i32_cast_cmp_oeq_half_uitofp(
402 ; CHECK: ret i1 false
403 define i1 @i32_cast_cmp_oeq_half_uitofp(i32 %i) {
404 %f = uitofp i32 %i to float
405 %cmp = fcmp oeq float %f, 0.5
409 ; CHECK-LABEL: @i32_cast_cmp_oeq_half_sitofp(
410 ; CHECK: ret i1 false
411 define i1 @i32_cast_cmp_oeq_half_sitofp(i32 %i) {
412 %f = sitofp i32 %i to float
413 %cmp = fcmp oeq float %f, 0.5
417 ; CHECK-LABEL: @i32_cast_cmp_one_half_uitofp(
419 define i1 @i32_cast_cmp_one_half_uitofp(i32 %i) {
420 %f = uitofp i32 %i to float
421 %cmp = fcmp one float %f, 0.5
425 ; CHECK-LABEL: @i32_cast_cmp_one_half_sitofp(
427 define i1 @i32_cast_cmp_one_half_sitofp(i32 %i) {
428 %f = sitofp i32 %i to float
429 %cmp = fcmp one float %f, 0.5
433 ; CHECK-LABEL: @i32_cast_cmp_ueq_half_uitofp(
434 ; CHECK: ret i1 false
435 define i1 @i32_cast_cmp_ueq_half_uitofp(i32 %i) {
436 %f = uitofp i32 %i to float
437 %cmp = fcmp ueq float %f, 0.5
441 ; CHECK-LABEL: @i32_cast_cmp_ueq_half_sitofp(
442 ; CHECK: ret i1 false
443 define i1 @i32_cast_cmp_ueq_half_sitofp(i32 %i) {
444 %f = sitofp i32 %i to float
445 %cmp = fcmp ueq float %f, 0.5
449 ; CHECK-LABEL: @i32_cast_cmp_une_half_uitofp(
451 define i1 @i32_cast_cmp_une_half_uitofp(i32 %i) {
452 %f = uitofp i32 %i to float
453 %cmp = fcmp une float %f, 0.5
457 ; CHECK-LABEL: @i32_cast_cmp_une_half_sitofp(
459 define i1 @i32_cast_cmp_une_half_sitofp(i32 %i) {
460 %f = sitofp i32 %i to float
461 %cmp = fcmp une float %f, 0.5
465 ; CHECK-LABEL: @i32_cast_cmp_oeq_int_inf_uitofp(
466 ; CHECK-NEXT: ret i1 false
467 define i1 @i32_cast_cmp_oeq_int_inf_uitofp(i32 %i) {
468 %f = uitofp i32 %i to float
469 %cmp = fcmp oeq float %f, 0x7FF0000000000000
473 ; CHECK-LABEL: @i32_cast_cmp_oeq_int_inf_sitofp(
474 ; CHECK-NEXT: ret i1 false
475 define i1 @i32_cast_cmp_oeq_int_inf_sitofp(i32 %i) {
476 %f = sitofp i32 %i to float
477 %cmp = fcmp oeq float %f, 0x7FF0000000000000
481 ; An i128 could round to an IEEE single-precision infinity.
482 ; CHECK-LABEL: @i128_cast_cmp_oeq_int_inf_uitofp(
486 define i1 @i128_cast_cmp_oeq_int_inf_uitofp(i128 %i) {
487 %f = uitofp i128 %i to float
488 %cmp = fcmp oeq float %f, 0x7FF0000000000000