1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -passes=instsimplify < %s | FileCheck %s
4 declare i32 @llvm.fptosi.sat.i32.f64(double)
5 declare i32 @llvm.fptoui.sat.i32.f64(double)
6 declare i32 @llvm.fptosi.sat.i32.f32(float)
7 declare i32 @llvm.fptoui.sat.i32.f32(float)
9 declare <2 x i32> @llvm.fptosi.sat.v2i32.v2f64(<2 x double>)
10 declare <2 x i32> @llvm.fptoui.sat.v2i32.v2f64(<2 x double>)
11 declare <2 x i32> @llvm.fptosi.sat.v2i32.v2f32(<2 x float>)
12 declare <2 x i32> @llvm.fptoui.sat.v2i32.v2f32(<2 x float>)
20 define i32 @fptosi_f64_to_i32_poison() {
21 ; CHECK-LABEL: @fptosi_f64_to_i32_poison(
22 ; CHECK-NEXT: ret i32 0
24 %r = call i32 @llvm.fptosi.sat.i32.f64(double poison)
28 define i32 @fptosi_f64_to_i32_undef() {
29 ; CHECK-LABEL: @fptosi_f64_to_i32_undef(
30 ; CHECK-NEXT: ret i32 0
32 %r = call i32 @llvm.fptosi.sat.i32.f64(double undef)
36 define i32 @fptosi_f64_to_i32_pos_zero() {
37 ; CHECK-LABEL: @fptosi_f64_to_i32_pos_zero(
38 ; CHECK-NEXT: ret i32 0
40 %r = call i32 @llvm.fptosi.sat.i32.f64(double 0.0)
44 define i32 @fptosi_f64_to_i32_neg_zero() {
45 ; CHECK-LABEL: @fptosi_f64_to_i32_neg_zero(
46 ; CHECK-NEXT: ret i32 0
48 %r = call i32 @llvm.fptosi.sat.i32.f64(double -0.0)
52 define i32 @fptosi_f64_to_i32_exact() {
53 ; CHECK-LABEL: @fptosi_f64_to_i32_exact(
54 ; CHECK-NEXT: ret i32 42
56 %r = call i32 @llvm.fptosi.sat.i32.f64(double 42.0)
60 define i32 @fptosi_f64_to_i32_trunc() {
61 ; CHECK-LABEL: @fptosi_f64_to_i32_trunc(
62 ; CHECK-NEXT: ret i32 42
64 %r = call i32 @llvm.fptosi.sat.i32.f64(double 42.9)
68 define i32 @fptosi_f64_to_i32_trunc_neg() {
69 ; CHECK-LABEL: @fptosi_f64_to_i32_trunc_neg(
70 ; CHECK-NEXT: ret i32 -42
72 %r = call i32 @llvm.fptosi.sat.i32.f64(double -42.9)
76 define i32 @fptosi_f64_to_i32_max_minus_1() {
77 ; CHECK-LABEL: @fptosi_f64_to_i32_max_minus_1(
78 ; CHECK-NEXT: ret i32 2147483646
80 %r = call i32 @llvm.fptosi.sat.i32.f64(double 2147483646.0)
84 define i32 @fptosi_f64_to_i32_max() {
85 ; CHECK-LABEL: @fptosi_f64_to_i32_max(
86 ; CHECK-NEXT: ret i32 2147483647
88 %r = call i32 @llvm.fptosi.sat.i32.f64(double 2147483647.0)
92 define i32 @fptosi_f64_to_i32_max_plus_1() {
93 ; CHECK-LABEL: @fptosi_f64_to_i32_max_plus_1(
94 ; CHECK-NEXT: ret i32 2147483647
96 %r = call i32 @llvm.fptosi.sat.i32.f64(double 2147483648.0)
100 define i32 @fptosi_f64_to_i32_min_plus_1() {
101 ; CHECK-LABEL: @fptosi_f64_to_i32_min_plus_1(
102 ; CHECK-NEXT: ret i32 -2147483647
104 %r = call i32 @llvm.fptosi.sat.i32.f64(double -2147483647.0)
108 define i32 @fptosi_f64_to_i32_min() {
109 ; CHECK-LABEL: @fptosi_f64_to_i32_min(
110 ; CHECK-NEXT: ret i32 -2147483648
112 %r = call i32 @llvm.fptosi.sat.i32.f64(double -2147483648.0)
116 define i32 @fptosi_f64_to_i32_min_minus_1() {
117 ; CHECK-LABEL: @fptosi_f64_to_i32_min_minus_1(
118 ; CHECK-NEXT: ret i32 -2147483648
120 %r = call i32 @llvm.fptosi.sat.i32.f64(double -2147483649.0)
124 define i32 @fptosi_f64_to_i32_inf() {
125 ; CHECK-LABEL: @fptosi_f64_to_i32_inf(
126 ; CHECK-NEXT: ret i32 2147483647
128 %r = call i32 @llvm.fptosi.sat.i32.f64(double 0x7ff0000000000000)
132 define i32 @fptosi_f64_to_i32_neg_inf() {
133 ; CHECK-LABEL: @fptosi_f64_to_i32_neg_inf(
134 ; CHECK-NEXT: ret i32 -2147483648
136 %r = call i32 @llvm.fptosi.sat.i32.f64(double 0xfff0000000000000)
140 define i32 @fptosi_f64_to_i32_nan1() {
141 ; CHECK-LABEL: @fptosi_f64_to_i32_nan1(
142 ; CHECK-NEXT: ret i32 0
144 %r = call i32 @llvm.fptosi.sat.i32.f64(double 0x7ff8000000000000)
148 define i32 @fptosi_f64_to_i32_nan2() {
149 ; CHECK-LABEL: @fptosi_f64_to_i32_nan2(
150 ; CHECK-NEXT: ret i32 0
152 %r = call i32 @llvm.fptosi.sat.i32.f64(double 0x7ff4000000000000)
156 define i32 @fptosi_f64_to_i32_nan3() {
157 ; CHECK-LABEL: @fptosi_f64_to_i32_nan3(
158 ; CHECK-NEXT: ret i32 0
160 %r = call i32 @llvm.fptosi.sat.i32.f64(double 0xfff8000000000000)
164 define i32 @fptosi_f64_to_i32_nan4() {
165 ; CHECK-LABEL: @fptosi_f64_to_i32_nan4(
166 ; CHECK-NEXT: ret i32 0
168 %r = call i32 @llvm.fptosi.sat.i32.f64(double 0xfff4000000000000)
172 define <2 x i32> @fptosi_f64_to_i32_vec() {
173 ; CHECK-LABEL: @fptosi_f64_to_i32_vec(
174 ; CHECK-NEXT: ret <2 x i32> <i32 42, i32 -42>
176 %r = call <2 x i32> @llvm.fptosi.sat.v2i32.v2f64(<2 x double> <double 42.9, double -42.9>)
186 define i32 @fptoui_f64_to_i32_poison() {
187 ; CHECK-LABEL: @fptoui_f64_to_i32_poison(
188 ; CHECK-NEXT: ret i32 0
190 %r = call i32 @llvm.fptoui.sat.i32.f64(double poison)
194 define i32 @fptoui_f64_to_i32_undef() {
195 ; CHECK-LABEL: @fptoui_f64_to_i32_undef(
196 ; CHECK-NEXT: ret i32 0
198 %r = call i32 @llvm.fptoui.sat.i32.f64(double undef)
202 define i32 @fptoui_f64_to_i32_pos_zero() {
203 ; CHECK-LABEL: @fptoui_f64_to_i32_pos_zero(
204 ; CHECK-NEXT: ret i32 0
206 %r = call i32 @llvm.fptoui.sat.i32.f64(double 0.0)
210 define i32 @fptoui_f64_to_i32_neg_zero() {
211 ; CHECK-LABEL: @fptoui_f64_to_i32_neg_zero(
212 ; CHECK-NEXT: ret i32 0
214 %r = call i32 @llvm.fptoui.sat.i32.f64(double -0.0)
218 define i32 @fptoui_f64_to_i32_exact() {
219 ; CHECK-LABEL: @fptoui_f64_to_i32_exact(
220 ; CHECK-NEXT: ret i32 42
222 %r = call i32 @llvm.fptoui.sat.i32.f64(double 42.0)
226 define i32 @fptoui_f64_to_i32_trunc() {
227 ; CHECK-LABEL: @fptoui_f64_to_i32_trunc(
228 ; CHECK-NEXT: ret i32 42
230 %r = call i32 @llvm.fptoui.sat.i32.f64(double 42.9)
234 define i32 @fptoui_f64_to_i32_trunc_neg() {
235 ; CHECK-LABEL: @fptoui_f64_to_i32_trunc_neg(
236 ; CHECK-NEXT: ret i32 0
238 %r = call i32 @llvm.fptoui.sat.i32.f64(double -42.9)
242 define i32 @fptoui_f64_to_i32_max_minus_1() {
243 ; CHECK-LABEL: @fptoui_f64_to_i32_max_minus_1(
244 ; CHECK-NEXT: ret i32 -2
246 %r = call i32 @llvm.fptoui.sat.i32.f64(double 4294967294.0)
250 define i32 @fptoui_f64_to_i32_max() {
251 ; CHECK-LABEL: @fptoui_f64_to_i32_max(
252 ; CHECK-NEXT: ret i32 -1
254 %r = call i32 @llvm.fptoui.sat.i32.f64(double 4294967295.0)
258 define i32 @fptoui_f64_to_i32_max_plus_1() {
259 ; CHECK-LABEL: @fptoui_f64_to_i32_max_plus_1(
260 ; CHECK-NEXT: ret i32 -1
262 %r = call i32 @llvm.fptoui.sat.i32.f64(double 4294967296.0)
266 define i32 @fptoui_f64_to_i32_inf() {
267 ; CHECK-LABEL: @fptoui_f64_to_i32_inf(
268 ; CHECK-NEXT: ret i32 -1
270 %r = call i32 @llvm.fptoui.sat.i32.f64(double 0x7ff0000000000000)
274 define i32 @fptoui_f64_to_i32_neg_inf() {
275 ; CHECK-LABEL: @fptoui_f64_to_i32_neg_inf(
276 ; CHECK-NEXT: ret i32 0
278 %r = call i32 @llvm.fptoui.sat.i32.f64(double 0xfff0000000000000)
282 define i32 @fptoui_f64_to_i32_nan1() {
283 ; CHECK-LABEL: @fptoui_f64_to_i32_nan1(
284 ; CHECK-NEXT: ret i32 0
286 %r = call i32 @llvm.fptoui.sat.i32.f64(double 0x7ff8000000000000)
290 define i32 @fptoui_f64_to_i32_nan2() {
291 ; CHECK-LABEL: @fptoui_f64_to_i32_nan2(
292 ; CHECK-NEXT: ret i32 0
294 %r = call i32 @llvm.fptoui.sat.i32.f64(double 0x7ff4000000000000)
298 define i32 @fptoui_f64_to_i32_nan3() {
299 ; CHECK-LABEL: @fptoui_f64_to_i32_nan3(
300 ; CHECK-NEXT: ret i32 0
302 %r = call i32 @llvm.fptoui.sat.i32.f64(double 0xfff8000000000000)
306 define i32 @fptoui_f64_to_i32_nan4() {
307 ; CHECK-LABEL: @fptoui_f64_to_i32_nan4(
308 ; CHECK-NEXT: ret i32 0
310 %r = call i32 @llvm.fptoui.sat.i32.f64(double 0xfff4000000000000)
314 define <2 x i32> @fptoui_f64_to_i32_vec() {
315 ; CHECK-LABEL: @fptoui_f64_to_i32_vec(
316 ; CHECK-NEXT: ret <2 x i32> <i32 42, i32 0>
318 %r = call <2 x i32> @llvm.fptoui.sat.v2i32.v2f64(<2 x double> <double 42.9, double -42.9>)
328 define i32 @fptosi_f32_to_i32_poison() {
329 ; CHECK-LABEL: @fptosi_f32_to_i32_poison(
330 ; CHECK-NEXT: ret i32 0
332 %r = call i32 @llvm.fptosi.sat.i32.f32(float poison)
336 define i32 @fptosi_f32_to_i32_undef() {
337 ; CHECK-LABEL: @fptosi_f32_to_i32_undef(
338 ; CHECK-NEXT: ret i32 0
340 %r = call i32 @llvm.fptosi.sat.i32.f32(float undef)
344 define i32 @fptosi_f32_to_i32_pos_zero() {
345 ; CHECK-LABEL: @fptosi_f32_to_i32_pos_zero(
346 ; CHECK-NEXT: ret i32 0
348 %r = call i32 @llvm.fptosi.sat.i32.f32(float 0.0)
352 define i32 @fptosi_f32_to_i32_neg_zero() {
353 ; CHECK-LABEL: @fptosi_f32_to_i32_neg_zero(
354 ; CHECK-NEXT: ret i32 0
356 %r = call i32 @llvm.fptosi.sat.i32.f32(float -0.0)
360 define i32 @fptosi_f32_to_i32_exact() {
361 ; CHECK-LABEL: @fptosi_f32_to_i32_exact(
362 ; CHECK-NEXT: ret i32 42
364 %r = call i32 @llvm.fptosi.sat.i32.f32(float 42.0)
368 define i32 @fptosi_f32_to_i32_trunc() {
369 ; CHECK-LABEL: @fptosi_f32_to_i32_trunc(
370 ; CHECK-NEXT: ret i32 42
372 %r = call i32 @llvm.fptosi.sat.i32.f32(float 42.5)
376 define i32 @fptosi_f32_to_i32_trunc_neg() {
377 ; CHECK-LABEL: @fptosi_f32_to_i32_trunc_neg(
378 ; CHECK-NEXT: ret i32 -42
380 %r = call i32 @llvm.fptosi.sat.i32.f32(float -42.5)
384 define i32 @fptosi_f32_to_i32_below_max() {
385 ; CHECK-LABEL: @fptosi_f32_to_i32_below_max(
386 ; CHECK-NEXT: ret i32 2147483520
388 %r = call i32 @llvm.fptosi.sat.i32.f32(float 2147483520.0)
392 define i32 @fptosi_f32_to_i32_above_max() {
393 ; CHECK-LABEL: @fptosi_f32_to_i32_above_max(
394 ; CHECK-NEXT: ret i32 2147483647
396 %r = call i32 @llvm.fptosi.sat.i32.f32(float 2147483648.0)
400 define i32 @fptosi_f32_to_i32_above_min() {
401 ; CHECK-LABEL: @fptosi_f32_to_i32_above_min(
402 ; CHECK-NEXT: ret i32 -2147483520
404 %r = call i32 @llvm.fptosi.sat.i32.f32(float -2147483520.0)
408 define i32 @fptosi_f32_to_i32_min() {
409 ; CHECK-LABEL: @fptosi_f32_to_i32_min(
410 ; CHECK-NEXT: ret i32 -2147483648
412 %r = call i32 @llvm.fptosi.sat.i32.f32(float -2147483648.0)
416 define i32 @fptosi_f32_to_i32_below_min() {
417 ; CHECK-LABEL: @fptosi_f32_to_i32_below_min(
418 ; CHECK-NEXT: ret i32 -2147483648
420 %r = call i32 @llvm.fptosi.sat.i32.f32(float -2147483904.0)
424 define i32 @fptosi_f32_to_i32_inf() {
425 ; CHECK-LABEL: @fptosi_f32_to_i32_inf(
426 ; CHECK-NEXT: ret i32 2147483647
428 %r = call i32 @llvm.fptosi.sat.i32.f32(float 0x7ff0000000000000)
432 define i32 @fptosi_f32_to_i32_neg_inf() {
433 ; CHECK-LABEL: @fptosi_f32_to_i32_neg_inf(
434 ; CHECK-NEXT: ret i32 -2147483648
436 %r = call i32 @llvm.fptosi.sat.i32.f32(float 0xfff0000000000000)
440 define i32 @fptosi_f32_to_i32_nan1() {
441 ; CHECK-LABEL: @fptosi_f32_to_i32_nan1(
442 ; CHECK-NEXT: ret i32 0
444 %r = call i32 @llvm.fptosi.sat.i32.f32(float 0x7ff8000000000000)
448 define i32 @fptosi_f32_to_i32_nan2() {
449 ; CHECK-LABEL: @fptosi_f32_to_i32_nan2(
450 ; CHECK-NEXT: ret i32 0
452 %r = call i32 @llvm.fptosi.sat.i32.f32(float 0x7ff4000000000000)
456 define i32 @fptosi_f32_to_i32_nan3() {
457 ; CHECK-LABEL: @fptosi_f32_to_i32_nan3(
458 ; CHECK-NEXT: ret i32 0
460 %r = call i32 @llvm.fptosi.sat.i32.f32(float 0xfff8000000000000)
464 define i32 @fptosi_f32_to_i32_nan4() {
465 ; CHECK-LABEL: @fptosi_f32_to_i32_nan4(
466 ; CHECK-NEXT: ret i32 0
468 %r = call i32 @llvm.fptosi.sat.i32.f32(float 0xfff4000000000000)
472 define <2 x i32> @fptosi_f32_to_i32_vec() {
473 ; CHECK-LABEL: @fptosi_f32_to_i32_vec(
474 ; CHECK-NEXT: ret <2 x i32> <i32 42, i32 -42>
476 %r = call <2 x i32> @llvm.fptosi.sat.v2i32.v2f32(<2 x float> <float 42.5, float -42.5>)
486 define i32 @fptoui_f32_to_i32_poison() {
487 ; CHECK-LABEL: @fptoui_f32_to_i32_poison(
488 ; CHECK-NEXT: ret i32 0
490 %r = call i32 @llvm.fptoui.sat.i32.f32(float poison)
494 define i32 @fptoui_f32_to_i32_undef() {
495 ; CHECK-LABEL: @fptoui_f32_to_i32_undef(
496 ; CHECK-NEXT: ret i32 0
498 %r = call i32 @llvm.fptoui.sat.i32.f32(float undef)
502 define i32 @fptoui_f32_to_i32_pos_zero() {
503 ; CHECK-LABEL: @fptoui_f32_to_i32_pos_zero(
504 ; CHECK-NEXT: ret i32 0
506 %r = call i32 @llvm.fptoui.sat.i32.f32(float 0.0)
510 define i32 @fptoui_f32_to_i32_neg_zero() {
511 ; CHECK-LABEL: @fptoui_f32_to_i32_neg_zero(
512 ; CHECK-NEXT: ret i32 0
514 %r = call i32 @llvm.fptoui.sat.i32.f32(float -0.0)
518 define i32 @fptoui_f32_to_i32_exact() {
519 ; CHECK-LABEL: @fptoui_f32_to_i32_exact(
520 ; CHECK-NEXT: ret i32 42
522 %r = call i32 @llvm.fptoui.sat.i32.f32(float 42.0)
526 define i32 @fptoui_f32_to_i32_trunc() {
527 ; CHECK-LABEL: @fptoui_f32_to_i32_trunc(
528 ; CHECK-NEXT: ret i32 42
530 %r = call i32 @llvm.fptoui.sat.i32.f32(float 42.5)
534 define i32 @fptoui_f32_to_i32_trunc_neg() {
535 ; CHECK-LABEL: @fptoui_f32_to_i32_trunc_neg(
536 ; CHECK-NEXT: ret i32 0
538 %r = call i32 @llvm.fptoui.sat.i32.f32(float -42.5)
542 define i32 @fptoui_f32_to_i32_below_max() {
543 ; CHECK-LABEL: @fptoui_f32_to_i32_below_max(
544 ; CHECK-NEXT: ret i32 -256
546 %r = call i32 @llvm.fptoui.sat.i32.f32(float 4294967040.0)
550 define i32 @fptoui_f32_to_i32_above_max() {
551 ; CHECK-LABEL: @fptoui_f32_to_i32_above_max(
552 ; CHECK-NEXT: ret i32 -1
554 %r = call i32 @llvm.fptoui.sat.i32.f32(float 4294967296.0)
558 define i32 @fptoui_f32_to_i32_inf() {
559 ; CHECK-LABEL: @fptoui_f32_to_i32_inf(
560 ; CHECK-NEXT: ret i32 -1
562 %r = call i32 @llvm.fptoui.sat.i32.f32(float 0x7ff0000000000000)
566 define i32 @fptoui_f32_to_i32_neg_inf() {
567 ; CHECK-LABEL: @fptoui_f32_to_i32_neg_inf(
568 ; CHECK-NEXT: ret i32 0
570 %r = call i32 @llvm.fptoui.sat.i32.f32(float 0xfff0000000000000)
574 define i32 @fptoui_f32_to_i32_nan1() {
575 ; CHECK-LABEL: @fptoui_f32_to_i32_nan1(
576 ; CHECK-NEXT: ret i32 0
578 %r = call i32 @llvm.fptoui.sat.i32.f32(float 0x7ff8000000000000)
582 define i32 @fptoui_f32_to_i32_nan2() {
583 ; CHECK-LABEL: @fptoui_f32_to_i32_nan2(
584 ; CHECK-NEXT: ret i32 0
586 %r = call i32 @llvm.fptoui.sat.i32.f32(float 0x7ff4000000000000)
590 define i32 @fptoui_f32_to_i32_nan3() {
591 ; CHECK-LABEL: @fptoui_f32_to_i32_nan3(
592 ; CHECK-NEXT: ret i32 0
594 %r = call i32 @llvm.fptoui.sat.i32.f32(float 0xfff8000000000000)
598 define i32 @fptoui_f32_to_i32_nan4() {
599 ; CHECK-LABEL: @fptoui_f32_to_i32_nan4(
600 ; CHECK-NEXT: ret i32 0
602 %r = call i32 @llvm.fptoui.sat.i32.f32(float 0xfff4000000000000)
606 define <2 x i32> @fptoui_f32_to_i32_vec() {
607 ; CHECK-LABEL: @fptoui_f32_to_i32_vec(
608 ; CHECK-NEXT: ret <2 x i32> <i32 42, i32 0>
610 %r = call <2 x i32> @llvm.fptoui.sat.v2i32.v2f32(<2 x float> <float 42.5, float -42.5>)