| ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6 |
| ; RUN: opt -passes=instcombine -S < %s | FileCheck %s |
| |
| @flt_nan = constant float 0x7FF8000000000000, align 4 |
| @flt_pos_min_subnormal = constant float 0x36A0000000000000, align 4 |
| @flt_pos_min_normal = constant float 0x3810000000000000, align 4 |
| @flt_pos_max = constant float 0x47EFFFFFE0000000, align 4 |
| @flt_pos_infinity = constant float 0x7FF0000000000000, align 4 |
| @flt_neg_min_subnormal = constant float 0xB6A0000000000000, align 4 |
| @flt_neg_min_normal = constant float 0xB810000000000000, align 4 |
| @flt_neg_max = constant float 0xC7EFFFFFE0000000, align 4 |
| @flt_neg_infinity = constant float 0xFFF0000000000000, align 4 |
| @dbl_nan = constant double 0x7FF8000000000000, align 8 |
| @dbl_snan = constant double 0x7FF0000000000001, align 8 |
| @dbl_pos_min_subnormal = constant double 4.940660e-324, align 8 |
| @dbl_pos_min_normal = constant double 0x10000000000000, align 8 |
| @dbl_pos_max = constant double 0x7FEFFFFFFFFFFFFF, align 8 |
| @dbl_pos_infinity = constant double 0x7FF0000000000000, align 8 |
| @dbl_neg_min_subnormal = constant double -4.940660e-324, align 8 |
| @dbl_neg_min_normal = constant double 0x8010000000000000, align 8 |
| @dbl_neg_max = constant double 0xFFEFFFFFFFFFFFFF, align 8 |
| @dbl_neg_infinity = constant double 0xFFF0000000000000, align 8 |
| |
| define double @nextafter_up_direction() { |
| ; CHECK-LABEL: define double @nextafter_up_direction() { |
| ; CHECK-NEXT: ret double f0x3FF0000000000001 |
| ; |
| %next = call double @nextafter(double 1.0, double 2.0) |
| ret double %next |
| } |
| |
| define float @nextafterf_up_direction() { |
| ; CHECK-LABEL: define float @nextafterf_up_direction() { |
| ; CHECK-NEXT: ret float f0x3F800001 |
| ; |
| %next = call float @nextafterf(float 1.0, float 2.0) |
| ret float %next |
| } |
| |
| define double @nextafter_down_direction() { |
| ; CHECK-LABEL: define double @nextafter_down_direction() { |
| ; CHECK-NEXT: ret double f0x3FEFFFFFFFFFFFFF |
| ; |
| %next = call double @nextafter(double 1.0, double 0.0) |
| ret double %next |
| } |
| |
| define float @nextafterf_down_direction() { |
| ; CHECK-LABEL: define float @nextafterf_down_direction() { |
| ; CHECK-NEXT: ret float f0x3F7FFFFF |
| ; |
| %next = call float @nextafterf(float 1.0, float 0.0) |
| ret float %next |
| } |
| |
| define double @nextafter_equal_args() { |
| ; CHECK-LABEL: define double @nextafter_equal_args() { |
| ; CHECK-NEXT: ret double 1.000000e+00 |
| ; |
| %next = call double @nextafter(double 1.0, double 1.0) |
| ret double %next |
| } |
| |
| define float @nextafterf_equal_args() { |
| ; CHECK-LABEL: define float @nextafterf_equal_args() { |
| ; CHECK-NEXT: ret float 1.000000e+00 |
| ; |
| %next = call float @nextafterf(float 1.0, float 1.0) |
| ret float %next |
| } |
| |
| define double @nextafter_pos_zero_neg_zero() { |
| ; CHECK-LABEL: define double @nextafter_pos_zero_neg_zero() { |
| ; CHECK-NEXT: ret double -0.000000e+00 |
| ; |
| %next = call double @nextafter(double 0.0, double -0.0) |
| ret double %next |
| } |
| |
| define float @nextafterf_pos_zero_neg_zero() { |
| ; CHECK-LABEL: define float @nextafterf_pos_zero_neg_zero() { |
| ; CHECK-NEXT: ret float -0.000000e+00 |
| ; |
| %next = call float @nextafterf(float 0.0, float -0.0) |
| ret float %next |
| } |
| |
| define double @nextafter_neg_zero_pos_zero() { |
| ; CHECK-LABEL: define double @nextafter_neg_zero_pos_zero() { |
| ; CHECK-NEXT: ret double 0.000000e+00 |
| ; |
| %next = call double @nextafter(double -0.0, double 0.0) |
| ret double %next |
| } |
| |
| define float @nextafterf_neg_zero_pos_zero() { |
| ; CHECK-LABEL: define float @nextafterf_neg_zero_pos_zero() { |
| ; CHECK-NEXT: ret float 0.000000e+00 |
| ; |
| %next = call float @nextafterf(float -0.0, float 0.0) |
| ret float %next |
| } |
| |
| define double @nextafter_nan_with_payload() { |
| ; CHECK-LABEL: define double @nextafter_nan_with_payload() { |
| ; CHECK-NEXT: ret double +nan(0x1) |
| ; |
| %tmp1 = load i64, ptr @dbl_nan |
| %tmp2 = or i64 %tmp1, 1 |
| %nan_with_payload = bitcast i64 %tmp2 to double |
| %next = call double @nextafter(double %nan_with_payload, double 1.0) |
| ret double %next |
| } |
| |
| define double @nextafter_nan_with_payload_2() { |
| ; CHECK-LABEL: define double @nextafter_nan_with_payload_2() { |
| ; CHECK-NEXT: ret double +nan(0x1) |
| ; |
| %tmp1 = load i64, ptr @dbl_nan |
| %tmp2 = or i64 %tmp1, 1 |
| %nan_with_payload = bitcast i64 %tmp2 to double |
| %next = call double @nextafter(double 1.0, double %nan_with_payload) |
| ret double %next |
| } |
| |
| define double @nextafter_snan() { |
| ; CHECK-LABEL: define double @nextafter_snan() { |
| ; CHECK-NEXT: ret double +qnan |
| ; |
| %arg1 = load double, ptr @dbl_snan |
| %next = call double @nextafter(double %arg1, double 1.0) |
| ret double %next |
| } |
| |
| define double @nextafter_snan_2() { |
| ; CHECK-LABEL: define double @nextafter_snan_2() { |
| ; CHECK-NEXT: [[NEXT:%.*]] = call double @nextafter(double 1.000000e+00, double +snan(0x1)) |
| ; CHECK-NEXT: ret double [[NEXT]] |
| ; |
| %arg2 = load double, ptr @dbl_snan |
| %next = call double @nextafter(double 1.0, double %arg2) |
| ret double %next |
| } |
| |
| define float @nextafterf_nan_with_payload() { |
| ; CHECK-LABEL: define float @nextafterf_nan_with_payload() { |
| ; CHECK-NEXT: ret float +nan(0x1) |
| ; |
| %tmp1 = load i32, ptr @flt_nan |
| %tmp2 = or i32 %tmp1, 1 |
| %nan_with_payload = bitcast i32 %tmp2 to float |
| %next = call float @nextafterf(float %nan_with_payload, float 1.0) |
| ret float %next |
| } |
| |
| define double @nextafter_pos_overflow () { |
| ; CHECK-LABEL: define double @nextafter_pos_overflow() { |
| ; CHECK-NEXT: ret double +inf |
| ; |
| %arg1 = load double, ptr @dbl_pos_max |
| %arg2 = load double, ptr @dbl_pos_infinity |
| %next = call double @nextafter(double %arg1, double %arg2) |
| ret double %next |
| } |
| |
| define float @nextafterf_pos_overflow() { |
| ; CHECK-LABEL: define float @nextafterf_pos_overflow() { |
| ; CHECK-NEXT: ret float +inf |
| ; |
| %arg1 = load float, ptr @flt_pos_max |
| %arg2 = load float, ptr @flt_pos_infinity |
| %next = call float @nextafterf(float %arg1, float %arg2) |
| ret float %next |
| } |
| |
| define double @nextafter_neg_overflow() { |
| ; CHECK-LABEL: define double @nextafter_neg_overflow() { |
| ; CHECK-NEXT: ret double -inf |
| ; |
| %arg1 = load double, ptr @dbl_neg_max |
| %arg2 = load double, ptr @dbl_neg_infinity |
| %next = call double @nextafter(double %arg1, double %arg2) |
| ret double %next |
| } |
| |
| define float @nextafterf_neg_overflow() { |
| ; CHECK-LABEL: define float @nextafterf_neg_overflow() { |
| ; CHECK-NEXT: ret float -inf |
| ; |
| %arg1 = load float, ptr @flt_neg_max |
| %arg2 = load float, ptr @flt_neg_infinity |
| %next = call float @nextafterf(float %arg1, float %arg2) |
| ret float %next |
| } |
| |
| define double @nextafter_zero_from_above() { |
| ; CHECK-LABEL: define double @nextafter_zero_from_above() { |
| ; CHECK-NEXT: [[NEXT:%.*]] = call double @nextafter(double 4.940660e-324, double 0.000000e+00) |
| ; CHECK-NEXT: ret double [[NEXT]] |
| ; |
| %arg = load double, ptr @dbl_pos_min_subnormal |
| %next = call double @nextafter(double %arg, double 0.0) |
| ret double %next |
| } |
| |
| define float @nextafterf_zero_from_above() { |
| ; CHECK-LABEL: define float @nextafterf_zero_from_above() { |
| ; CHECK-NEXT: [[NEXT:%.*]] = call float @nextafterf(float 1.401300e-45, float 0.000000e+00) |
| ; CHECK-NEXT: ret float [[NEXT]] |
| ; |
| %arg = load float, ptr @flt_pos_min_subnormal |
| %next = call float @nextafterf(float %arg, float 0.0) |
| ret float %next |
| } |
| |
| define double @nextafter_zero_from_below() { |
| ; CHECK-LABEL: define double @nextafter_zero_from_below() { |
| ; CHECK-NEXT: [[NEXT:%.*]] = call double @nextafter(double -4.940660e-324, double 0.000000e+00) |
| ; CHECK-NEXT: ret double [[NEXT]] |
| ; |
| %arg = load double, ptr @dbl_neg_min_subnormal |
| %next = call double @nextafter(double %arg, double 0.0) |
| ret double %next |
| } |
| |
| define float @nextafterf_zero_from_below() { |
| ; CHECK-LABEL: define float @nextafterf_zero_from_below() { |
| ; CHECK-NEXT: [[NEXT:%.*]] = call float @nextafterf(float -1.401300e-45, float 0.000000e+00) |
| ; CHECK-NEXT: ret float [[NEXT]] |
| ; |
| %arg = load float, ptr @flt_neg_min_subnormal |
| %next = call float @nextafterf(float %arg, float 0.0) |
| ret float %next |
| } |
| |
| define double @nextafter_subnormal() { |
| ; CHECK-LABEL: define double @nextafter_subnormal() { |
| ; CHECK-NEXT: [[NEXT:%.*]] = call double @nextafter(double 4.940660e-324, double +inf) |
| ; CHECK-NEXT: ret double [[NEXT]] |
| ; |
| %subnormal = load double, ptr @dbl_pos_min_subnormal |
| %infinity = load double, ptr @dbl_pos_infinity |
| %next = call double @nextafter(double %subnormal, double %infinity) |
| ret double %next |
| } |
| |
| define float @nextafterf_subnormal() { |
| ; CHECK-LABEL: define float @nextafterf_subnormal() { |
| ; CHECK-NEXT: [[NEXT:%.*]] = call float @nextafterf(float 1.401300e-45, float +inf) |
| ; CHECK-NEXT: ret float [[NEXT]] |
| ; |
| %subnormal = load float, ptr @flt_pos_min_subnormal |
| %infinity = load float, ptr @flt_pos_infinity |
| %next = call float @nextafterf(float %subnormal, float %infinity) |
| ret float %next |
| } |
| |
| define double @nextafter_poison() { |
| ; CHECK-LABEL: define double @nextafter_poison() { |
| ; CHECK-NEXT: [[NEXT:%.*]] = call double @nextafter(double poison, double 1.000000e+00) |
| ; CHECK-NEXT: ret double [[NEXT]] |
| ; |
| %next = call double @nextafter(double poison, double 1.0) |
| ret double %next |
| } |
| |
| define double @nextafterf_poison() { |
| ; CHECK-LABEL: define double @nextafterf_poison() { |
| ; CHECK-NEXT: [[NEXT:%.*]] = call double @nextafterf(float poison, float 1.000000e+00) |
| ; CHECK-NEXT: ret double [[NEXT]] |
| ; |
| %next = call double @nextafterf(float poison, float 1.0) |
| ret double %next |
| } |
| |
| define double @nextafter_subnormal_readnone() { |
| ; CHECK-LABEL: define double @nextafter_subnormal_readnone() { |
| ; CHECK-NEXT: [[NEXT:%.*]] = call double @nextafter(double 4.940660e-324, double +inf) #[[ATTR1:[0-9]+]] |
| ; CHECK-NEXT: ret double [[NEXT]] |
| ; |
| %subnormal = load double, ptr @dbl_pos_min_subnormal |
| %infinity = load double, ptr @dbl_pos_infinity |
| %next = call double @nextafter(double %subnormal, double %infinity) readnone |
| ret double %next |
| } |
| |
| define float @nextafterf_subnormal_readnone() { |
| ; CHECK-LABEL: define float @nextafterf_subnormal_readnone() { |
| ; CHECK-NEXT: [[NEXT:%.*]] = call float @nextafterf(float 1.401300e-45, float +inf) #[[ATTR1]] |
| ; CHECK-NEXT: ret float [[NEXT]] |
| ; |
| %subnormal = load float, ptr @flt_pos_min_subnormal |
| %infinity = load float, ptr @flt_pos_infinity |
| %next = call float @nextafterf(float %subnormal, float %infinity) readnone |
| ret float %next |
| } |
| |
| declare double @nextafter(double, double) #0 |
| declare float @nextafterf(float, float) #0 |
| attributes #0 = { willreturn memory(errnomem: write) } |