[llvm] [ConstantFolding] Constant fold nextafter and nexttoward (PR #168794)

Sayan Sivakumaran via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 19 15:51:57 PST 2025


https://github.com/sivakusayan updated https://github.com/llvm/llvm-project/pull/168794

>From 0fef7b853777f02c0747e4d47854f2025c7bef92 Mon Sep 17 00:00:00 2001
From: Sayan Sivakumaran <sivakusayan at gmail.com>
Date: Wed, 19 Nov 2025 16:36:15 -0600
Subject: [PATCH 1/2] Precommit tests

---
 .../InstCombine/constant-fold-nextafter.ll    | 234 ++++++++++++++++
 .../constant-fold-nexttoward-fp128.ll         | 251 ++++++++++++++++++
 .../constant-fold-nexttoward-ppc-fp128.ll     | 117 ++++++++
 .../constant-fold-nexttoward-x86-fp80.ll      | 117 ++++++++
 .../InstCombine/floating-point-constants.ll   |  48 ++++
 5 files changed, 767 insertions(+)
 create mode 100644 llvm/test/Transforms/InstCombine/constant-fold-nextafter.ll
 create mode 100644 llvm/test/Transforms/InstCombine/constant-fold-nexttoward-fp128.ll
 create mode 100644 llvm/test/Transforms/InstCombine/constant-fold-nexttoward-ppc-fp128.ll
 create mode 100644 llvm/test/Transforms/InstCombine/constant-fold-nexttoward-x86-fp80.ll
 create mode 100644 llvm/test/Transforms/InstCombine/floating-point-constants.ll

diff --git a/llvm/test/Transforms/InstCombine/constant-fold-nextafter.ll b/llvm/test/Transforms/InstCombine/constant-fold-nextafter.ll
new file mode 100644
index 0000000000000..08607b18dcffc
--- /dev/null
+++ b/llvm/test/Transforms/InstCombine/constant-fold-nextafter.ll
@@ -0,0 +1,234 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
+; RUN: cat %S/floating-point-constants.ll %s | opt -passes=instcombine -S | FileCheck %s
+
+declare double @nextafter(double, double) #0
+declare float @nextafterf(float, float) #0
+
+attributes #0 = { willreturn memory(errnomem: write) }
+
+define double @nextafter_up_direction() {
+; CHECK-LABEL: define double @nextafter_up_direction() {
+; CHECK-NEXT:    [[NEXT:%.*]] = call double @nextafter(double 1.000000e+00, double 2.000000e+00)
+; CHECK-NEXT:    ret double [[NEXT]]
+;
+  %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:    [[NEXT:%.*]] = call float @nextafterf(float 1.000000e+00, float 2.000000e+00)
+; CHECK-NEXT:    ret float [[NEXT]]
+;
+  %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:    [[NEXT:%.*]] = call double @nextafter(double 1.000000e+00, double 0.000000e+00)
+; CHECK-NEXT:    ret double [[NEXT]]
+;
+  %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:    [[NEXT:%.*]] = call float @nextafterf(float 1.000000e+00, float 0.000000e+00)
+; CHECK-NEXT:    ret float [[NEXT]]
+;
+  %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:    [[NEXT:%.*]] = call double @nextafter(double 1.000000e+00, double 1.000000e+00)
+; CHECK-NEXT:    ret double [[NEXT]]
+;
+  %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:    [[NEXT:%.*]] = call float @nextafterf(float 1.000000e+00, float 1.000000e+00)
+; CHECK-NEXT:    ret float [[NEXT]]
+;
+  %next = call float @nextafterf(float 1.0, float 1.0)
+  ret float %next
+}
+
+define double @nextafter_nan_with_payload() {
+; CHECK-LABEL: define double @nextafter_nan_with_payload() {
+; CHECK-NEXT:    [[NEXT:%.*]] = call double @nextafter(double 0x7FF8000000000001, double 1.000000e+00)
+; CHECK-NEXT:    ret double [[NEXT]]
+;
+  %nan = load double, double* @dbl_nan
+  %tmp1 = bitcast double %nan to i64
+  %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 float @nextafterf_nan_with_payload() {
+; CHECK-LABEL: define float @nextafterf_nan_with_payload() {
+; CHECK-NEXT:    [[NEXT:%.*]] = call float @nextafterf(float 0x7FF8000020000000, float 1.000000e+00)
+; CHECK-NEXT:    ret float [[NEXT]]
+;
+  %nan = load float, float* @flt_nan
+  %tmp1 = bitcast float %nan to i32
+  %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:    [[NEXT:%.*]] = call double @nextafter(double 0x7FEFFFFFFFFFFFFF, double 0x7FF0000000000000)
+; CHECK-NEXT:    ret double [[NEXT]]
+;
+  %arg1 = load double, double* @dbl_pos_max
+  %arg2 = load double, double* @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:    [[NEXT:%.*]] = call float @nextafterf(float 0x47EFFFFFE0000000, float 0x7FF0000000000000)
+; CHECK-NEXT:    ret float [[NEXT]]
+;
+  %arg1 = load float, float* @flt_pos_max
+  %arg2 = load float, float* @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:    [[NEXT:%.*]] = call double @nextafter(double 0xFFEFFFFFFFFFFFFF, double 0xFFF0000000000000)
+; CHECK-NEXT:    ret double [[NEXT]]
+;
+  %arg1 = load double, double* @dbl_neg_max
+  %arg2 = load double, double* @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:    [[NEXT:%.*]] = call float @nextafterf(float 0xC7EFFFFFE0000000, float 0xFFF0000000000000)
+; CHECK-NEXT:    ret float [[NEXT]]
+;
+  %arg1 = load float, float* @flt_neg_max
+  %arg2 = load float, float* @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, double* @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 0x36A0000000000000, float 0.000000e+00)
+; CHECK-NEXT:    ret float [[NEXT]]
+;
+  %arg = load float, float* @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, double* @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 0xB6A0000000000000, float 0.000000e+00)
+; CHECK-NEXT:    ret float [[NEXT]]
+;
+  %arg = load float, float* @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 0x7FF0000000000000)
+; CHECK-NEXT:    ret double [[NEXT]]
+;
+  %subnormal = load double, double* @dbl_pos_min_subnormal
+  %infinity = load double, double* @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 0x36A0000000000000, float 0x7FF0000000000000)
+; CHECK-NEXT:    ret float [[NEXT]]
+;
+  %subnormal = load float, float* @flt_pos_min_subnormal
+  %infinity = load float, float* @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 0x7FF0000000000000) #[[ATTR1:[0-9]+]]
+; CHECK-NEXT:    ret double [[NEXT]]
+;
+  %subnormal = load double, double* @dbl_pos_min_subnormal
+  %infinity = load double, double* @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 0x36A0000000000000, float 0x7FF0000000000000) #[[ATTR1]]
+; CHECK-NEXT:    ret float [[NEXT]]
+;
+  %subnormal = load float, float* @flt_pos_min_subnormal
+  %infinity = load float, float* @flt_pos_infinity
+  %next = call float @nextafterf(float %subnormal, float %infinity) readnone
+  ret float %next
+}
diff --git a/llvm/test/Transforms/InstCombine/constant-fold-nexttoward-fp128.ll b/llvm/test/Transforms/InstCombine/constant-fold-nexttoward-fp128.ll
new file mode 100644
index 0000000000000..b84a0b51a8917
--- /dev/null
+++ b/llvm/test/Transforms/InstCombine/constant-fold-nexttoward-fp128.ll
@@ -0,0 +1,251 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
+; RUN: cat %S/floating-point-constants.ll %s | opt -passes=instcombine -S | FileCheck %s
+
+declare double @nexttoward(double, fp128) #0
+declare float @nexttowardf(float, fp128) #0
+
+attributes #0 = { willreturn memory(errnomem: write) }
+
+define double @nexttoward_up_direction() {
+; CHECK-LABEL: define double @nexttoward_up_direction() {
+; CHECK-NEXT:    [[NEXT:%.*]] = call double @nexttoward(double 1.000000e+00, fp128 0xL00000000000000004000000000000000)
+; CHECK-NEXT:    ret double [[NEXT]]
+;
+  %arg = fpext double 2.0 to fp128
+  %next = call double @nexttoward(double 1.0, fp128 %arg)
+  ret double %next
+}
+
+define float @nexttowardf_up_direction() {
+; CHECK-LABEL: define float @nexttowardf_up_direction() {
+; CHECK-NEXT:    [[NEXT:%.*]] = call float @nexttowardf(float 1.000000e+00, fp128 0xL00000000000000004000000000000000)
+; CHECK-NEXT:    ret float [[NEXT]]
+;
+  %arg = fpext float 2.0 to fp128
+  %next = call float @nexttowardf(float 1.0, fp128 %arg)
+  ret float %next
+}
+
+define double @nexttoward_down_direction() {
+; CHECK-LABEL: define double @nexttoward_down_direction() {
+; CHECK-NEXT:    [[NEXT:%.*]] = call double @nexttoward(double 1.000000e+00, fp128 0xL00000000000000000000000000000000)
+; CHECK-NEXT:    ret double [[NEXT]]
+;
+  %arg = fpext double 0.0 to fp128
+  %next = call double @nexttoward(double 1.0, fp128 %arg)
+  ret double %next
+}
+
+define float @nexttowardf_down_direction() {
+; CHECK-LABEL: define float @nexttowardf_down_direction() {
+; CHECK-NEXT:    [[NEXT:%.*]] = call float @nexttowardf(float 1.000000e+00, fp128 0xL00000000000000000000000000000000)
+; CHECK-NEXT:    ret float [[NEXT]]
+;
+  %arg = fpext float 0.0 to fp128
+  %next = call float @nexttowardf(float 1.0, fp128 %arg)
+  ret float %next
+}
+
+define double @nexttoward_equal_args() {
+; CHECK-LABEL: define double @nexttoward_equal_args() {
+; CHECK-NEXT:    [[NEXT:%.*]] = call double @nexttoward(double 1.000000e+00, fp128 0xL00000000000000003FFF000000000000)
+; CHECK-NEXT:    ret double [[NEXT]]
+;
+  %arg = fpext double 1.0 to fp128
+  %next = call double @nexttoward(double 1.0, fp128 %arg)
+  ret double %next
+}
+
+define float @nexttowardf_equal_args() {
+; CHECK-LABEL: define float @nexttowardf_equal_args() {
+; CHECK-NEXT:    [[NEXT:%.*]] = call float @nexttowardf(float 1.000000e+00, fp128 0xL00000000000000003FFF000000000000)
+; CHECK-NEXT:    ret float [[NEXT]]
+;
+  %arg = fpext float 1.0 to fp128
+  %next = call float @nexttowardf(float 1.0, fp128 %arg)
+  ret float %next
+}
+
+define double @nexttoward_nan_with_payload() {
+; CHECK-LABEL: define double @nexttoward_nan_with_payload() {
+; CHECK-NEXT:    [[NEXT:%.*]] = call double @nexttoward(double 0x7FF8000000000001, fp128 0xL00000000000000003FFF000000000000)
+; CHECK-NEXT:    ret double [[NEXT]]
+;
+  %nan = load double, double* @dbl_nan
+  %tmp1 = bitcast double %nan to i64
+  %tmp2 = or i64 %tmp1, 1
+  %nan_with_payload = bitcast i64 %tmp2 to double
+  %dummy_arg = fpext double 1.0 to fp128
+  %next = call double @nexttoward(double %nan_with_payload, fp128 %dummy_arg)
+  ret double %next
+}
+
+define float @nexttowardf_nan_with_payload() {
+; CHECK-LABEL: define float @nexttowardf_nan_with_payload() {
+; CHECK-NEXT:    [[NEXT:%.*]] = call float @nexttowardf(float 0x7FF8000020000000, fp128 0xL00000000000000003FFF000000000000)
+; CHECK-NEXT:    ret float [[NEXT]]
+;
+  %nan = load float, float* @flt_nan
+  %tmp1 = bitcast float %nan to i32
+  %tmp2 = or i32 %tmp1, 1
+  %nan_with_payload = bitcast i32 %tmp2 to float
+  %dummy_arg = fpext float 1.0 to fp128
+  %next = call float @nexttowardf(float %nan_with_payload, fp128 %dummy_arg)
+  ret float %next
+}
+
+define double @nexttoward_pos_overflow() {
+; CHECK-LABEL: define double @nexttoward_pos_overflow() {
+; CHECK-NEXT:    [[NEXT:%.*]] = call double @nexttoward(double 0x7FEFFFFFFFFFFFFF, fp128 0xL00000000000000007FFF000000000000)
+; CHECK-NEXT:    ret double [[NEXT]]
+;
+  %pos_max = load double, double* @dbl_pos_max
+  %pos_inf = load double, double* @dbl_pos_infinity
+  %ext_pos_inf = fpext double %pos_inf to fp128
+  %next = call double @nexttoward(double %pos_max, fp128 %ext_pos_inf)
+  ret double %next
+}
+
+define float @nexttowardf_pos_overflow () {
+; CHECK-LABEL: define float @nexttowardf_pos_overflow() {
+; CHECK-NEXT:    [[NEXT:%.*]] = call float @nexttowardf(float 0x47EFFFFFE0000000, fp128 0xL00000000000000007FFF000000000000)
+; CHECK-NEXT:    ret float [[NEXT]]
+;
+  %pos_max = load float, float* @flt_pos_max
+  %pos_inf = load float, float* @flt_pos_infinity
+  %ext_pos_inf = fpext float %pos_inf to fp128
+  %next = call float @nexttowardf(float %pos_max, fp128 %ext_pos_inf)
+  ret float %next
+}
+
+define double @nexttoward_neg_overflow() {
+; CHECK-LABEL: define double @nexttoward_neg_overflow() {
+; CHECK-NEXT:    [[NEXT:%.*]] = call double @nexttoward(double 0xFFEFFFFFFFFFFFFF, fp128 0xL0000000000000000FFFF000000000000)
+; CHECK-NEXT:    ret double [[NEXT]]
+;
+  %neg_max = load double, double* @dbl_neg_max
+  %neg_inf = load double, double* @dbl_neg_infinity
+  %ext_neg_inf = fpext double %neg_inf to fp128
+  %next = call double @nexttoward(double %neg_max, fp128 %ext_neg_inf)
+  ret double %next
+}
+
+define float @nexttowardf_neg_overflow() {
+; CHECK-LABEL: define float @nexttowardf_neg_overflow() {
+; CHECK-NEXT:    [[NEXT:%.*]] = call float @nexttowardf(float 0xC7EFFFFFE0000000, fp128 0xL0000000000000000FFFF000000000000)
+; CHECK-NEXT:    ret float [[NEXT]]
+;
+  %neg_max = load float, float* @flt_neg_max
+  %neg_inf = load float, float* @flt_neg_infinity
+  %ext_neg_inf = fpext float %neg_inf to fp128
+  %next = call float @nexttowardf(float %neg_max, fp128 %ext_neg_inf)
+  ret float %next
+}
+
+define double @nexttoward_zero_from_above() {
+; CHECK-LABEL: define double @nexttoward_zero_from_above() {
+; CHECK-NEXT:    [[NEXT:%.*]] = call double @nexttoward(double 4.940660e-324, fp128 0xL00000000000000000000000000000000)
+; CHECK-NEXT:    ret double [[NEXT]]
+;
+  %subnormal = load double, double* @dbl_pos_min_subnormal
+  %zero = fpext double 0.0 to fp128
+  %next = call double @nexttoward(double %subnormal, fp128 %zero)
+  ret double %next
+}
+
+define float @nexttowardf_zero_from_above() {
+; CHECK-LABEL: define float @nexttowardf_zero_from_above() {
+; CHECK-NEXT:    [[NEXT:%.*]] = call float @nexttowardf(float 0x36A0000000000000, fp128 0xL00000000000000000000000000000000)
+; CHECK-NEXT:    ret float [[NEXT]]
+;
+  %min_subnormal = load float, float* @flt_pos_min_subnormal
+  %zero = fpext float 0.0 to fp128
+  %next = call float @nexttowardf(float %min_subnormal, fp128 %zero)
+  ret float %next
+}
+
+define double @nexttoward_zero_from_below() {
+; CHECK-LABEL: define double @nexttoward_zero_from_below() {
+; CHECK-NEXT:    [[NEXT:%.*]] = call double @nexttoward(double -4.940660e-324, fp128 0xL00000000000000000000000000000000)
+; CHECK-NEXT:    ret double [[NEXT]]
+;
+  %subnormal = load double, double* @dbl_neg_min_subnormal
+  %zero = fpext double 0.0 to fp128
+  %next = call double @nexttoward(double %subnormal, fp128 %zero)
+  ret double %next
+}
+
+define float @nexttowardf_zero_from_below() {
+; CHECK-LABEL: define float @nexttowardf_zero_from_below() {
+; CHECK-NEXT:    [[NEXT:%.*]] = call float @nexttowardf(float 0xB6A0000000000000, fp128 0xL00000000000000000000000000000000)
+; CHECK-NEXT:    ret float [[NEXT]]
+;
+  %min_subnormal = load float, float* @flt_neg_min_subnormal
+  %zero = fpext float 0.0 to fp128
+  %next = call float @nexttowardf(float %min_subnormal, fp128 %zero)
+  ret float %next
+}
+
+define double @nexttoward_subnormal() {
+; CHECK-LABEL: define double @nexttoward_subnormal() {
+; CHECK-NEXT:    [[NEXT:%.*]] = call double @nexttoward(double 4.940660e-324, fp128 0xL00000000000000003FFF000000000000)
+; CHECK-NEXT:    ret double [[NEXT]]
+;
+  %subnormal = load double, double* @dbl_pos_min_subnormal
+  %target = fpext double 1.0 to fp128
+  %next = call double @nexttoward(double %subnormal, fp128 %target)
+  ret double %next
+}
+
+define float @nexttowardf_subnormal() {
+; CHECK-LABEL: define float @nexttowardf_subnormal() {
+; CHECK-NEXT:    [[NEXT:%.*]] = call float @nexttowardf(float 0x36A0000000000000, fp128 0xL00000000000000003FFF000000000000)
+; CHECK-NEXT:    ret float [[NEXT]]
+;
+  %subnormal = load float, float* @flt_pos_min_subnormal
+  %target = fpext float 1.0 to fp128
+  %next = call float @nexttowardf(float %subnormal, fp128 %target)
+  ret float %next
+}
+
+define double @nexttoward_poison() {
+; CHECK-LABEL: define double @nexttoward_poison() {
+; CHECK-NEXT:    [[NEXT:%.*]] = call double @nexttoward(double poison, fp128 0xL00000000000000003FFF000000000000)
+; CHECK-NEXT:    ret double [[NEXT]]
+;
+  %dummy_arg = fpext double 1.0 to fp128
+  %next = call double @nexttoward(double poison, fp128 %dummy_arg)
+  ret double %next
+}
+
+define float @nexttowardf_poison() {
+; CHECK-LABEL: define float @nexttowardf_poison() {
+; CHECK-NEXT:    [[NEXT:%.*]] = call float @nexttowardf(float poison, fp128 0xL00000000000000003FFF000000000000)
+; CHECK-NEXT:    ret float [[NEXT]]
+;
+  %dummy_arg = fpext double 1.0 to fp128
+  %next = call float @nexttowardf(float poison, fp128 %dummy_arg)
+  ret float %next
+}
+
+define double @nexttoward_subnormal_readnone() {
+; CHECK-LABEL: define double @nexttoward_subnormal_readnone() {
+; CHECK-NEXT:    [[NEXT:%.*]] = call double @nexttoward(double 4.940660e-324, fp128 0xL00000000000000003FFF000000000000) #[[ATTR1:[0-9]+]]
+; CHECK-NEXT:    ret double [[NEXT]]
+;
+  %subnormal = load double, double* @dbl_pos_min_subnormal
+  %target = fpext double 1.0 to fp128
+  %next = call double @nexttoward(double %subnormal, fp128 %target) readnone
+  ret double %next
+}
+
+define float @nexttowardf_subnormal_readnone() {
+; CHECK-LABEL: define float @nexttowardf_subnormal_readnone() {
+; CHECK-NEXT:    [[NEXT:%.*]] = call float @nexttowardf(float 0x36A0000000000000, fp128 0xL00000000000000003FFF000000000000) #[[ATTR1]]
+; CHECK-NEXT:    ret float [[NEXT]]
+;
+  %subnormal = load float, float* @flt_pos_min_subnormal
+  %target = fpext float 1.0 to fp128
+  %next = call float @nexttowardf(float %subnormal, fp128 %target) readnone
+  ret float %next
+}
diff --git a/llvm/test/Transforms/InstCombine/constant-fold-nexttoward-ppc-fp128.ll b/llvm/test/Transforms/InstCombine/constant-fold-nexttoward-ppc-fp128.ll
new file mode 100644
index 0000000000000..cfb1db14676b0
--- /dev/null
+++ b/llvm/test/Transforms/InstCombine/constant-fold-nexttoward-ppc-fp128.ll
@@ -0,0 +1,117 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
+; RUN: cat %S/floating-point-constants.ll %s | opt -passes=instcombine -S | FileCheck %s
+
+declare double @nexttoward(double, ppc_fp128) #0
+declare float @nexttowardf(float, ppc_fp128) #0
+
+attributes #0 = { willreturn memory(errnomem: write) }
+
+define double @nexttoward_up_direction() {
+; CHECK-LABEL: define double @nexttoward_up_direction() {
+; CHECK-NEXT:    [[NEXT:%.*]] = call double @nexttoward(double 1.000000e+00, ppc_fp128 0xM40000000000000000000000000000000)
+; CHECK-NEXT:    ret double [[NEXT]]
+;
+  %arg = fpext double 2.0 to ppc_fp128
+  %next = call double @nexttoward(double 1.0, ppc_fp128 %arg)
+  ret double %next
+}
+
+define float @nexttowardf_up_direction() {
+; CHECK-LABEL: define float @nexttowardf_up_direction() {
+; CHECK-NEXT:    [[NEXT:%.*]] = call float @nexttowardf(float 1.000000e+00, ppc_fp128 0xM40000000000000000000000000000000)
+; CHECK-NEXT:    ret float [[NEXT]]
+;
+  %arg = fpext float 2.0 to ppc_fp128
+  %next = call float @nexttowardf(float 1.0, ppc_fp128 %arg)
+  ret float %next
+}
+
+define double @nexttoward_down_direction() {
+; CHECK-LABEL: define double @nexttoward_down_direction() {
+; CHECK-NEXT:    [[NEXT:%.*]] = call double @nexttoward(double 1.000000e+00, ppc_fp128 0xM00000000000000000000000000000000)
+; CHECK-NEXT:    ret double [[NEXT]]
+;
+  %arg = fpext double 0.0 to ppc_fp128
+  %next = call double @nexttoward(double 1.0, ppc_fp128 %arg)
+  ret double %next
+}
+
+define float @nexttowardf_down_direction() {
+; CHECK-LABEL: define float @nexttowardf_down_direction() {
+; CHECK-NEXT:    [[NEXT:%.*]] = call float @nexttowardf(float 1.000000e+00, ppc_fp128 0xM00000000000000000000000000000000)
+; CHECK-NEXT:    ret float [[NEXT]]
+;
+  %arg = fpext float 0.0 to ppc_fp128
+  %next = call float @nexttowardf(float 1.0, ppc_fp128 %arg)
+  ret float %next
+}
+
+define double @nexttoward_pos_overflow() {
+; CHECK-LABEL: define double @nexttoward_pos_overflow() {
+; CHECK-NEXT:    [[NEXT:%.*]] = call double @nexttoward(double 0x7FEFFFFFFFFFFFFF, ppc_fp128 0xM7FF00000000000000000000000000000)
+; CHECK-NEXT:    ret double [[NEXT]]
+;
+  %pos_max = load double, double* @dbl_pos_max
+  %pos_inf = load double, double* @dbl_pos_infinity
+  %ext_pos_inf = fpext double %pos_inf to ppc_fp128
+  %next = call double @nexttoward(double %pos_max, ppc_fp128 %ext_pos_inf)
+  ret double %next
+}
+
+define float @nexttowardf_pos_overflow () {
+; CHECK-LABEL: define float @nexttowardf_pos_overflow() {
+; CHECK-NEXT:    [[NEXT:%.*]] = call float @nexttowardf(float 0x47EFFFFFE0000000, ppc_fp128 0xM7FF00000000000000000000000000000)
+; CHECK-NEXT:    ret float [[NEXT]]
+;
+  %pos_max = load float, float* @flt_pos_max
+  %pos_inf = load float, float* @flt_pos_infinity
+  %ext_pos_inf = fpext float %pos_inf to ppc_fp128
+  %next = call float @nexttowardf(float %pos_max, ppc_fp128 %ext_pos_inf)
+  ret float %next
+}
+
+define double @nexttoward_neg_overflow() {
+; CHECK-LABEL: define double @nexttoward_neg_overflow() {
+; CHECK-NEXT:    [[NEXT:%.*]] = call double @nexttoward(double 0xFFEFFFFFFFFFFFFF, ppc_fp128 0xMFFF00000000000000000000000000000)
+; CHECK-NEXT:    ret double [[NEXT]]
+;
+  %neg_max = load double, double* @dbl_neg_max
+  %neg_inf = load double, double* @dbl_neg_infinity
+  %ext_neg_inf = fpext double %neg_inf to ppc_fp128
+  %next = call double @nexttoward(double %neg_max, ppc_fp128 %ext_neg_inf)
+  ret double %next
+}
+
+define float @nexttowardf_neg_overflow() {
+; CHECK-LABEL: define float @nexttowardf_neg_overflow() {
+; CHECK-NEXT:    [[NEXT:%.*]] = call float @nexttowardf(float 0xC7EFFFFFE0000000, ppc_fp128 0xMFFF00000000000000000000000000000)
+; CHECK-NEXT:    ret float [[NEXT]]
+;
+  %neg_max = load float, float* @flt_neg_max
+  %neg_inf = load float, float* @flt_neg_infinity
+  %ext_neg_inf = fpext float %neg_inf to ppc_fp128
+  %next = call float @nexttowardf(float %neg_max, ppc_fp128 %ext_neg_inf)
+  ret float %next
+}
+
+define double @nexttoward_subnormal() {
+; CHECK-LABEL: define double @nexttoward_subnormal() {
+; CHECK-NEXT:    [[NEXT:%.*]] = call double @nexttoward(double 4.940660e-324, ppc_fp128 0xM3FF00000000000000000000000000000)
+; CHECK-NEXT:    ret double [[NEXT]]
+;
+  %subnormal = load double, double* @dbl_pos_min_subnormal
+  %target = fpext double 1.0 to ppc_fp128
+  %next = call double @nexttoward(double %subnormal, ppc_fp128 %target)
+  ret double %next
+}
+
+define float @nexttowardf_subnormal() {
+; CHECK-LABEL: define float @nexttowardf_subnormal() {
+; CHECK-NEXT:    [[NEXT:%.*]] = call float @nexttowardf(float 0x36A0000000000000, ppc_fp128 0xM3FF00000000000000000000000000000)
+; CHECK-NEXT:    ret float [[NEXT]]
+;
+  %subnormal = load float, float* @flt_pos_min_subnormal
+  %target = fpext float 1.0 to ppc_fp128
+  %next = call float @nexttowardf(float %subnormal, ppc_fp128 %target)
+  ret float %next
+}
diff --git a/llvm/test/Transforms/InstCombine/constant-fold-nexttoward-x86-fp80.ll b/llvm/test/Transforms/InstCombine/constant-fold-nexttoward-x86-fp80.ll
new file mode 100644
index 0000000000000..7cbdad338f0e9
--- /dev/null
+++ b/llvm/test/Transforms/InstCombine/constant-fold-nexttoward-x86-fp80.ll
@@ -0,0 +1,117 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
+; RUN: cat %S/floating-point-constants.ll %s | opt -passes=instcombine -S | FileCheck %s
+
+declare double @nexttoward(double, x86_fp80) #0
+declare float @nexttowardf(float, x86_fp80) #0
+
+attributes #0 = { willreturn memory(errnomem: write) }
+
+define double @nexttoward_up_direction() {
+; CHECK-LABEL: define double @nexttoward_up_direction() {
+; CHECK-NEXT:    [[NEXT:%.*]] = call double @nexttoward(double 1.000000e+00, x86_fp80 0xK40008000000000000000)
+; CHECK-NEXT:    ret double [[NEXT]]
+;
+  %arg = fpext double 2.0 to x86_fp80
+  %next = call double @nexttoward(double 1.0, x86_fp80 %arg)
+  ret double %next
+}
+
+define float @nexttowardf_up_direction() {
+; CHECK-LABEL: define float @nexttowardf_up_direction() {
+; CHECK-NEXT:    [[NEXT:%.*]] = call float @nexttowardf(float 1.000000e+00, x86_fp80 0xK40008000000000000000)
+; CHECK-NEXT:    ret float [[NEXT]]
+;
+  %arg = fpext float 2.0 to x86_fp80
+  %next = call float @nexttowardf(float 1.0, x86_fp80 %arg)
+  ret float %next
+}
+
+define double @nexttoward_down_direction() {
+; CHECK-LABEL: define double @nexttoward_down_direction() {
+; CHECK-NEXT:    [[NEXT:%.*]] = call double @nexttoward(double 1.000000e+00, x86_fp80 0xK00000000000000000000)
+; CHECK-NEXT:    ret double [[NEXT]]
+;
+  %arg = fpext double 0.0 to x86_fp80
+  %next = call double @nexttoward(double 1.0, x86_fp80 %arg)
+  ret double %next
+}
+
+define float @nexttowardf_down_direction() {
+; CHECK-LABEL: define float @nexttowardf_down_direction() {
+; CHECK-NEXT:    [[NEXT:%.*]] = call float @nexttowardf(float 1.000000e+00, x86_fp80 0xK00000000000000000000)
+; CHECK-NEXT:    ret float [[NEXT]]
+;
+  %arg = fpext float 0.0 to x86_fp80
+  %next = call float @nexttowardf(float 1.0, x86_fp80 %arg)
+  ret float %next
+}
+
+define double @nexttoward_pos_overflow () {
+; CHECK-LABEL: define double @nexttoward_pos_overflow() {
+; CHECK-NEXT:    [[NEXT:%.*]] = call double @nexttoward(double 0x7FEFFFFFFFFFFFFF, x86_fp80 0xK7FFF8000000000000000)
+; CHECK-NEXT:    ret double [[NEXT]]
+;
+  %pos_max = load double, double* @dbl_pos_max
+  %pos_inf = load double, double* @dbl_pos_infinity
+  %ext_pos_inf = fpext double %pos_inf to x86_fp80
+  %next = call double @nexttoward(double %pos_max, x86_fp80 %ext_pos_inf)
+  ret double %next
+}
+
+define float @nexttowardf_pos_overflow() {
+; CHECK-LABEL: define float @nexttowardf_pos_overflow() {
+; CHECK-NEXT:    [[NEXT:%.*]] = call float @nexttowardf(float 0x47EFFFFFE0000000, x86_fp80 0xK7FFF8000000000000000)
+; CHECK-NEXT:    ret float [[NEXT]]
+;
+  %pos_max = load float, float* @flt_pos_max
+  %pos_inf = load float, float* @flt_pos_infinity
+  %ext_pos_inf = fpext float %pos_inf to x86_fp80
+  %next = call float @nexttowardf(float %pos_max, x86_fp80 %ext_pos_inf)
+  ret float %next
+}
+
+define double @nexttoward_neg_overflow() {
+; CHECK-LABEL: define double @nexttoward_neg_overflow() {
+; CHECK-NEXT:    [[NEXT:%.*]] = call double @nexttoward(double 0xFFEFFFFFFFFFFFFF, x86_fp80 0xKFFFF8000000000000000)
+; CHECK-NEXT:    ret double [[NEXT]]
+;
+  %neg_max = load double, double* @dbl_neg_max
+  %neg_inf = load double, double* @dbl_neg_infinity
+  %ext_neg_inf = fpext double %neg_inf to x86_fp80
+  %next = call double @nexttoward(double %neg_max, x86_fp80 %ext_neg_inf)
+  ret double %next
+}
+
+define float @nexttowardf_neg_overflow() {
+; CHECK-LABEL: define float @nexttowardf_neg_overflow() {
+; CHECK-NEXT:    [[NEXT:%.*]] = call float @nexttowardf(float 0xC7EFFFFFE0000000, x86_fp80 0xKFFFF8000000000000000)
+; CHECK-NEXT:    ret float [[NEXT]]
+;
+  %neg_max = load float, float* @flt_neg_max
+  %neg_inf = load float, float* @flt_neg_infinity
+  %ext_neg_inf = fpext float %neg_inf to x86_fp80
+  %next = call float @nexttowardf(float %neg_max, x86_fp80 %ext_neg_inf)
+  ret float %next
+}
+
+define double @nexttoward_subnormal() {
+; CHECK-LABEL: define double @nexttoward_subnormal() {
+; CHECK-NEXT:    [[NEXT:%.*]] = call double @nexttoward(double 4.940660e-324, x86_fp80 0xK3FFF8000000000000000)
+; CHECK-NEXT:    ret double [[NEXT]]
+;
+  %subnormal = load double, double* @dbl_pos_min_subnormal
+  %target = fpext double 1.0 to x86_fp80
+  %next = call double @nexttoward(double %subnormal, x86_fp80 %target)
+  ret double %next
+}
+
+define float @nexttowardf_subnormal() {
+; CHECK-LABEL: define float @nexttowardf_subnormal() {
+; CHECK-NEXT:    [[NEXT:%.*]] = call float @nexttowardf(float 0x36A0000000000000, x86_fp80 0xK3FFF8000000000000000)
+; CHECK-NEXT:    ret float [[NEXT]]
+;
+  %subnormal = load float, float* @flt_pos_min_subnormal
+  %target = fpext float 1.0 to x86_fp80
+  %next = call float @nexttowardf(float %subnormal, x86_fp80 %target)
+  ret float %next
+}
diff --git a/llvm/test/Transforms/InstCombine/floating-point-constants.ll b/llvm/test/Transforms/InstCombine/floating-point-constants.ll
new file mode 100644
index 0000000000000..5d135b0aaebaa
--- /dev/null
+++ b/llvm/test/Transforms/InstCombine/floating-point-constants.ll
@@ -0,0 +1,48 @@
+; RUN: true
+; Constants for edge case float testing.
+
+; Generated with:
+; clang -S -emit-llvm floating-point-constants.c
+;
+; // floating-point-constants.c
+; #include <math.h>
+; #include <float.h>
+;
+; const float flt_nan = NAN;
+; const float flt_pos_min_subnormal = FLT_TRUE_MIN;
+; const float flt_pos_min_normal = FLT_MIN;
+; const float flt_pos_max = FLT_MAX;
+; const float flt_pos_infinity = INFINITY;
+; const float flt_neg_min_subnormal = -FLT_TRUE_MIN;
+; const float flt_neg_min_normal = -FLT_MIN;
+; const float flt_neg_max = -FLT_MAX;
+; const float flt_neg_infinity = -INFINITY;
+;
+; const double dbl_nan = NAN;
+; const double dbl_pos_min_subnormal = DBL_TRUE_MIN;
+; const double dbl_pos_min_normal = DBL_MIN;
+; const double dbl_pos_max = DBL_MAX;
+; const double dbl_pos_infinity = INFINITY;
+; const double dbl_neg_min_subnormal = -DBL_TRUE_MIN;
+; const double dbl_neg_min_normal = -DBL_MIN;
+; const double dbl_neg_max = -DBL_MAX;
+; const double dbl_neg_infinity = -INFINITY;
+
+ at flt_nan = dso_local constant float 0x7FF8000000000000, align 4
+ at flt_pos_min_subnormal = dso_local constant float 0x36A0000000000000, align 4
+ at flt_pos_min_normal = dso_local constant float 0x3810000000000000, align 4
+ at flt_pos_max = dso_local constant float 0x47EFFFFFE0000000, align 4
+ at flt_pos_infinity = dso_local constant float 0x7FF0000000000000, align 4
+ at flt_neg_min_subnormal = dso_local constant float 0xB6A0000000000000, align 4
+ at flt_neg_min_normal = dso_local constant float 0xB810000000000000, align 4
+ at flt_neg_max = dso_local constant float 0xC7EFFFFFE0000000, align 4
+ at flt_neg_infinity = dso_local constant float 0xFFF0000000000000, align 4
+ at dbl_nan = dso_local constant double 0x7FF8000000000000, align 8
+ at dbl_pos_min_subnormal = dso_local constant double 4.940660e-324, align 8
+ at dbl_pos_min_normal = dso_local constant double 0x10000000000000, align 8
+ at dbl_pos_max = dso_local constant double 0x7FEFFFFFFFFFFFFF, align 8
+ at dbl_pos_infinity = dso_local constant double 0x7FF0000000000000, align 8
+ at dbl_neg_min_subnormal = dso_local constant double -4.940660e-324, align 8
+ at dbl_neg_min_normal = dso_local constant double 0x8010000000000000, align 8
+ at dbl_neg_max = dso_local constant double 0xFFEFFFFFFFFFFFFF, align 8
+ at dbl_neg_infinity = dso_local constant double 0xFFF0000000000000, align 8

>From ea98d6ba43d83acfec5ead29d970af44c8c50bd1 Mon Sep 17 00:00:00 2001
From: Sayan Sivakumaran <sivakusayan at gmail.com>
Date: Wed, 19 Nov 2025 16:50:26 -0600
Subject: [PATCH 2/2] Constant fold nextafter and nexttoward

---
 llvm/lib/Analysis/ConstantFolding.cpp         | 69 ++++++++++++++++++-
 .../InstCombine/constant-fold-nextafter.ll    | 48 ++++++-------
 .../constant-fold-nexttoward-fp128.ll         | 48 ++++++-------
 .../constant-fold-nexttoward-ppc-fp128.ll     | 24 +++----
 .../constant-fold-nexttoward-x86-fp80.ll      | 24 +++----
 5 files changed, 128 insertions(+), 85 deletions(-)

diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp
index 4bece85d3cfbf..e0aaea2569334 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -2008,7 +2008,9 @@ bool llvm::canConstantFoldCallTo(const CallBase *Call, const Function *F) {
            Name == "log10f" || Name == "logb" || Name == "logbf" ||
            Name == "log1p" || Name == "log1pf";
   case 'n':
-    return Name == "nearbyint" || Name == "nearbyintf";
+    return Name == "nearbyint" || Name == "nearbyintf" || Name == "nextafter" ||
+           Name == "nextafterf" || Name == "nexttoward" ||
+           Name == "nexttowardf";
   case 'p':
     return Name == "pow" || Name == "powf";
   case 'r':
@@ -3174,6 +3176,53 @@ static Constant *evaluateCompare(const APFloat &Op1, const APFloat &Op2,
   return nullptr;
 }
 
+/// Returns the first NaN in the operand list if it exists, preserving the NaN
+/// payload if possible. Returns nullptr if no NaNs are in the list.
+static Constant *TryConstantFoldNaN(ArrayRef<APFloat> Operands,
+                                    const Type *RetTy) {
+  assert(RetTy != nullptr);
+  for (const APFloat &Op : Operands) {
+    if (Op.isNaN()) {
+      bool Unused;
+      APFloat Ret(Op);
+      Ret.convert(RetTy->getFltSemantics(), detail::rmNearestTiesToEven,
+                  &Unused);
+      return ConstantFP::get(RetTy->getContext(), Ret);
+    }
+  }
+  return nullptr;
+}
+
+static Constant *ConstantFoldNextToward(const APFloat &Op0, const APFloat &Op1,
+                                        const Type *RetTy,
+                                        bool *WouldSetErrno) {
+  assert(RetTy != nullptr);
+  *WouldSetErrno = false;
+
+  Constant *RetNaN = TryConstantFoldNaN({Op0, Op1}, RetTy);
+  if (RetNaN != nullptr) {
+    return RetNaN;
+  }
+
+  // Recall that the second argument of nexttoward is always a long double,
+  // so we may need to promote the first argument for comparisons to be valid.
+  bool LosesInfo;
+  APFloat PromotedOp0(Op0);
+  PromotedOp0.convert(Op1.getSemantics(), detail::rmNearestTiesToEven,
+                      &LosesInfo);
+  assert(!LosesInfo && "Unexpected lossy promotion");
+
+  if (PromotedOp0 == Op1)
+    return ConstantFP::get(RetTy->getContext(), Op0);
+
+  APFloat Next(Op0);
+  Next.next(/*nextDown=*/PromotedOp0 > Op1);
+  const bool DidOverflow = !Op0.isInfinity() && Next.isInfinity();
+  *WouldSetErrno = Next.isZero() || Next.isDenormal() || DidOverflow;
+
+  return ConstantFP::get(RetTy->getContext(), Next);
+}
+
 static Constant *ConstantFoldLibCall2(StringRef Name, Type *Ty,
                                       ArrayRef<Constant *> Operands,
                                       const TargetLibraryInfo *TLI) {
@@ -3233,6 +3282,14 @@ static Constant *ConstantFoldLibCall2(StringRef Name, Type *Ty,
     if (TLI->has(Func))
       return ConstantFoldBinaryFP(atan2, Op1V, Op2V, Ty);
     break;
+  case LibFunc_nextafter:
+  case LibFunc_nextafterf:
+  case LibFunc_nexttoward:
+  case LibFunc_nexttowardf:
+    if (TLI->has(Func)) {
+      bool Unused;
+      return ConstantFoldNextToward(Op1V, Op2V, Ty, &Unused);
+    }
   }
 
   return nullptr;
@@ -4685,6 +4742,16 @@ bool llvm::isMathLibCallNoop(const CallBase *Call,
         // may occur, so allow for that possibility.
         return !Op0.isZero() || !Op1.isZero();
 
+      case LibFunc_nextafter:
+      case LibFunc_nextafterf:
+      case LibFunc_nextafterl:
+      case LibFunc_nexttoward:
+      case LibFunc_nexttowardf:
+      case LibFunc_nexttowardl: {
+        bool WouldSetErrno;
+        ConstantFoldNextToward(Op0, Op1, F->getReturnType(), &WouldSetErrno);
+        return !WouldSetErrno;
+      }
       default:
         break;
       }
diff --git a/llvm/test/Transforms/InstCombine/constant-fold-nextafter.ll b/llvm/test/Transforms/InstCombine/constant-fold-nextafter.ll
index 08607b18dcffc..1650a71d872b5 100644
--- a/llvm/test/Transforms/InstCombine/constant-fold-nextafter.ll
+++ b/llvm/test/Transforms/InstCombine/constant-fold-nextafter.ll
@@ -8,8 +8,7 @@ attributes #0 = { willreturn memory(errnomem: write) }
 
 define double @nextafter_up_direction() {
 ; CHECK-LABEL: define double @nextafter_up_direction() {
-; CHECK-NEXT:    [[NEXT:%.*]] = call double @nextafter(double 1.000000e+00, double 2.000000e+00)
-; CHECK-NEXT:    ret double [[NEXT]]
+; CHECK-NEXT:    ret double 0x3FF0000000000001
 ;
   %next = call double @nextafter(double 1.0, double 2.0)
   ret double %next
@@ -17,8 +16,7 @@ define double @nextafter_up_direction() {
 
 define float @nextafterf_up_direction() {
 ; CHECK-LABEL: define float @nextafterf_up_direction() {
-; CHECK-NEXT:    [[NEXT:%.*]] = call float @nextafterf(float 1.000000e+00, float 2.000000e+00)
-; CHECK-NEXT:    ret float [[NEXT]]
+; CHECK-NEXT:    ret float 0x3FF0000020000000
 ;
   %next = call float @nextafterf(float 1.0, float 2.0)
   ret float %next
@@ -26,8 +24,7 @@ define float @nextafterf_up_direction() {
 
 define double @nextafter_down_direction() {
 ; CHECK-LABEL: define double @nextafter_down_direction() {
-; CHECK-NEXT:    [[NEXT:%.*]] = call double @nextafter(double 1.000000e+00, double 0.000000e+00)
-; CHECK-NEXT:    ret double [[NEXT]]
+; CHECK-NEXT:    ret double 0x3FEFFFFFFFFFFFFF
 ;
   %next = call double @nextafter(double 1.0, double 0.0)
   ret double %next
@@ -35,8 +32,7 @@ define double @nextafter_down_direction() {
 
 define float @nextafterf_down_direction() {
 ; CHECK-LABEL: define float @nextafterf_down_direction() {
-; CHECK-NEXT:    [[NEXT:%.*]] = call float @nextafterf(float 1.000000e+00, float 0.000000e+00)
-; CHECK-NEXT:    ret float [[NEXT]]
+; CHECK-NEXT:    ret float 0x3FEFFFFFE0000000
 ;
   %next = call float @nextafterf(float 1.0, float 0.0)
   ret float %next
@@ -44,8 +40,7 @@ define float @nextafterf_down_direction() {
 
 define double @nextafter_equal_args() {
 ; CHECK-LABEL: define double @nextafter_equal_args() {
-; CHECK-NEXT:    [[NEXT:%.*]] = call double @nextafter(double 1.000000e+00, double 1.000000e+00)
-; CHECK-NEXT:    ret double [[NEXT]]
+; CHECK-NEXT:    ret double 1.000000e+00
 ;
   %next = call double @nextafter(double 1.0, double 1.0)
   ret double %next
@@ -53,8 +48,7 @@ define double @nextafter_equal_args() {
 
 define float @nextafterf_equal_args() {
 ; CHECK-LABEL: define float @nextafterf_equal_args() {
-; CHECK-NEXT:    [[NEXT:%.*]] = call float @nextafterf(float 1.000000e+00, float 1.000000e+00)
-; CHECK-NEXT:    ret float [[NEXT]]
+; CHECK-NEXT:    ret float 1.000000e+00
 ;
   %next = call float @nextafterf(float 1.0, float 1.0)
   ret float %next
@@ -62,8 +56,7 @@ define float @nextafterf_equal_args() {
 
 define double @nextafter_nan_with_payload() {
 ; CHECK-LABEL: define double @nextafter_nan_with_payload() {
-; CHECK-NEXT:    [[NEXT:%.*]] = call double @nextafter(double 0x7FF8000000000001, double 1.000000e+00)
-; CHECK-NEXT:    ret double [[NEXT]]
+; CHECK-NEXT:    ret double 0x7FF8000000000001
 ;
   %nan = load double, double* @dbl_nan
   %tmp1 = bitcast double %nan to i64
@@ -76,8 +69,7 @@ define double @nextafter_nan_with_payload() {
 
 define float @nextafterf_nan_with_payload() {
 ; CHECK-LABEL: define float @nextafterf_nan_with_payload() {
-; CHECK-NEXT:    [[NEXT:%.*]] = call float @nextafterf(float 0x7FF8000020000000, float 1.000000e+00)
-; CHECK-NEXT:    ret float [[NEXT]]
+; CHECK-NEXT:    ret float 0x7FF8000020000000
 ;
   %nan = load float, float* @flt_nan
   %tmp1 = bitcast float %nan to i32
@@ -90,7 +82,7 @@ define float @nextafterf_nan_with_payload() {
 define double @nextafter_pos_overflow () {
 ; CHECK-LABEL: define double @nextafter_pos_overflow() {
 ; CHECK-NEXT:    [[NEXT:%.*]] = call double @nextafter(double 0x7FEFFFFFFFFFFFFF, double 0x7FF0000000000000)
-; CHECK-NEXT:    ret double [[NEXT]]
+; CHECK-NEXT:    ret double 0x7FF0000000000000
 ;
   %arg1 = load double, double* @dbl_pos_max
   %arg2 = load double, double* @dbl_pos_infinity
@@ -101,7 +93,7 @@ define double @nextafter_pos_overflow () {
 define float @nextafterf_pos_overflow() {
 ; CHECK-LABEL: define float @nextafterf_pos_overflow() {
 ; CHECK-NEXT:    [[NEXT:%.*]] = call float @nextafterf(float 0x47EFFFFFE0000000, float 0x7FF0000000000000)
-; CHECK-NEXT:    ret float [[NEXT]]
+; CHECK-NEXT:    ret float 0x7FF0000000000000
 ;
   %arg1 = load float, float* @flt_pos_max
   %arg2 = load float, float* @flt_pos_infinity
@@ -112,7 +104,7 @@ define float @nextafterf_pos_overflow() {
 define double @nextafter_neg_overflow() {
 ; CHECK-LABEL: define double @nextafter_neg_overflow() {
 ; CHECK-NEXT:    [[NEXT:%.*]] = call double @nextafter(double 0xFFEFFFFFFFFFFFFF, double 0xFFF0000000000000)
-; CHECK-NEXT:    ret double [[NEXT]]
+; CHECK-NEXT:    ret double 0xFFF0000000000000
 ;
   %arg1 = load double, double* @dbl_neg_max
   %arg2 = load double, double* @dbl_neg_infinity
@@ -123,7 +115,7 @@ define double @nextafter_neg_overflow() {
 define float @nextafterf_neg_overflow() {
 ; CHECK-LABEL: define float @nextafterf_neg_overflow() {
 ; CHECK-NEXT:    [[NEXT:%.*]] = call float @nextafterf(float 0xC7EFFFFFE0000000, float 0xFFF0000000000000)
-; CHECK-NEXT:    ret float [[NEXT]]
+; CHECK-NEXT:    ret float 0xFFF0000000000000
 ;
   %arg1 = load float, float* @flt_neg_max
   %arg2 = load float, float* @flt_neg_infinity
@@ -134,7 +126,7 @@ define float @nextafterf_neg_overflow() {
 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]]
+; CHECK-NEXT:    ret double 0.000000e+00
 ;
   %arg = load double, double* @dbl_pos_min_subnormal
   %next = call double @nextafter(double %arg, double 0.0)
@@ -144,7 +136,7 @@ define double @nextafter_zero_from_above() {
 define float @nextafterf_zero_from_above() {
 ; CHECK-LABEL: define float @nextafterf_zero_from_above() {
 ; CHECK-NEXT:    [[NEXT:%.*]] = call float @nextafterf(float 0x36A0000000000000, float 0.000000e+00)
-; CHECK-NEXT:    ret float [[NEXT]]
+; CHECK-NEXT:    ret float 0.000000e+00
 ;
   %arg = load float, float* @flt_pos_min_subnormal
   %next = call float @nextafterf(float %arg, float 0.0)
@@ -154,7 +146,7 @@ define float @nextafterf_zero_from_above() {
 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]]
+; CHECK-NEXT:    ret double -0.000000e+00
 ;
   %arg = load double, double* @dbl_neg_min_subnormal
   %next = call double @nextafter(double %arg, double 0.0)
@@ -164,7 +156,7 @@ define double @nextafter_zero_from_below() {
 define float @nextafterf_zero_from_below() {
 ; CHECK-LABEL: define float @nextafterf_zero_from_below() {
 ; CHECK-NEXT:    [[NEXT:%.*]] = call float @nextafterf(float 0xB6A0000000000000, float 0.000000e+00)
-; CHECK-NEXT:    ret float [[NEXT]]
+; CHECK-NEXT:    ret float -0.000000e+00
 ;
   %arg = load float, float* @flt_neg_min_subnormal
   %next = call float @nextafterf(float %arg, float 0.0)
@@ -174,7 +166,7 @@ define float @nextafterf_zero_from_below() {
 define double @nextafter_subnormal() {
 ; CHECK-LABEL: define double @nextafter_subnormal() {
 ; CHECK-NEXT:    [[NEXT:%.*]] = call double @nextafter(double 4.940660e-324, double 0x7FF0000000000000)
-; CHECK-NEXT:    ret double [[NEXT]]
+; CHECK-NEXT:    ret double 9.881310e-324
 ;
   %subnormal = load double, double* @dbl_pos_min_subnormal
   %infinity = load double, double* @dbl_pos_infinity
@@ -185,7 +177,7 @@ define double @nextafter_subnormal() {
 define float @nextafterf_subnormal() {
 ; CHECK-LABEL: define float @nextafterf_subnormal() {
 ; CHECK-NEXT:    [[NEXT:%.*]] = call float @nextafterf(float 0x36A0000000000000, float 0x7FF0000000000000)
-; CHECK-NEXT:    ret float [[NEXT]]
+; CHECK-NEXT:    ret float 0x36B0000000000000
 ;
   %subnormal = load float, float* @flt_pos_min_subnormal
   %infinity = load float, float* @flt_pos_infinity
@@ -214,7 +206,7 @@ define double @nextafterf_poison() {
 define double @nextafter_subnormal_readnone() {
 ; CHECK-LABEL: define double @nextafter_subnormal_readnone() {
 ; CHECK-NEXT:    [[NEXT:%.*]] = call double @nextafter(double 4.940660e-324, double 0x7FF0000000000000) #[[ATTR1:[0-9]+]]
-; CHECK-NEXT:    ret double [[NEXT]]
+; CHECK-NEXT:    ret double 9.881310e-324
 ;
   %subnormal = load double, double* @dbl_pos_min_subnormal
   %infinity = load double, double* @dbl_pos_infinity
@@ -225,7 +217,7 @@ define double @nextafter_subnormal_readnone() {
 define float @nextafterf_subnormal_readnone() {
 ; CHECK-LABEL: define float @nextafterf_subnormal_readnone() {
 ; CHECK-NEXT:    [[NEXT:%.*]] = call float @nextafterf(float 0x36A0000000000000, float 0x7FF0000000000000) #[[ATTR1]]
-; CHECK-NEXT:    ret float [[NEXT]]
+; CHECK-NEXT:    ret float 0x36B0000000000000
 ;
   %subnormal = load float, float* @flt_pos_min_subnormal
   %infinity = load float, float* @flt_pos_infinity
diff --git a/llvm/test/Transforms/InstCombine/constant-fold-nexttoward-fp128.ll b/llvm/test/Transforms/InstCombine/constant-fold-nexttoward-fp128.ll
index b84a0b51a8917..577ea0c1b3fba 100644
--- a/llvm/test/Transforms/InstCombine/constant-fold-nexttoward-fp128.ll
+++ b/llvm/test/Transforms/InstCombine/constant-fold-nexttoward-fp128.ll
@@ -8,8 +8,7 @@ attributes #0 = { willreturn memory(errnomem: write) }
 
 define double @nexttoward_up_direction() {
 ; CHECK-LABEL: define double @nexttoward_up_direction() {
-; CHECK-NEXT:    [[NEXT:%.*]] = call double @nexttoward(double 1.000000e+00, fp128 0xL00000000000000004000000000000000)
-; CHECK-NEXT:    ret double [[NEXT]]
+; CHECK-NEXT:    ret double 0x3FF0000000000001
 ;
   %arg = fpext double 2.0 to fp128
   %next = call double @nexttoward(double 1.0, fp128 %arg)
@@ -18,8 +17,7 @@ define double @nexttoward_up_direction() {
 
 define float @nexttowardf_up_direction() {
 ; CHECK-LABEL: define float @nexttowardf_up_direction() {
-; CHECK-NEXT:    [[NEXT:%.*]] = call float @nexttowardf(float 1.000000e+00, fp128 0xL00000000000000004000000000000000)
-; CHECK-NEXT:    ret float [[NEXT]]
+; CHECK-NEXT:    ret float 0x3FF0000020000000
 ;
   %arg = fpext float 2.0 to fp128
   %next = call float @nexttowardf(float 1.0, fp128 %arg)
@@ -28,8 +26,7 @@ define float @nexttowardf_up_direction() {
 
 define double @nexttoward_down_direction() {
 ; CHECK-LABEL: define double @nexttoward_down_direction() {
-; CHECK-NEXT:    [[NEXT:%.*]] = call double @nexttoward(double 1.000000e+00, fp128 0xL00000000000000000000000000000000)
-; CHECK-NEXT:    ret double [[NEXT]]
+; CHECK-NEXT:    ret double 0x3FEFFFFFFFFFFFFF
 ;
   %arg = fpext double 0.0 to fp128
   %next = call double @nexttoward(double 1.0, fp128 %arg)
@@ -38,8 +35,7 @@ define double @nexttoward_down_direction() {
 
 define float @nexttowardf_down_direction() {
 ; CHECK-LABEL: define float @nexttowardf_down_direction() {
-; CHECK-NEXT:    [[NEXT:%.*]] = call float @nexttowardf(float 1.000000e+00, fp128 0xL00000000000000000000000000000000)
-; CHECK-NEXT:    ret float [[NEXT]]
+; CHECK-NEXT:    ret float 0x3FEFFFFFE0000000
 ;
   %arg = fpext float 0.0 to fp128
   %next = call float @nexttowardf(float 1.0, fp128 %arg)
@@ -48,8 +44,7 @@ define float @nexttowardf_down_direction() {
 
 define double @nexttoward_equal_args() {
 ; CHECK-LABEL: define double @nexttoward_equal_args() {
-; CHECK-NEXT:    [[NEXT:%.*]] = call double @nexttoward(double 1.000000e+00, fp128 0xL00000000000000003FFF000000000000)
-; CHECK-NEXT:    ret double [[NEXT]]
+; CHECK-NEXT:    ret double 1.000000e+00
 ;
   %arg = fpext double 1.0 to fp128
   %next = call double @nexttoward(double 1.0, fp128 %arg)
@@ -58,8 +53,7 @@ define double @nexttoward_equal_args() {
 
 define float @nexttowardf_equal_args() {
 ; CHECK-LABEL: define float @nexttowardf_equal_args() {
-; CHECK-NEXT:    [[NEXT:%.*]] = call float @nexttowardf(float 1.000000e+00, fp128 0xL00000000000000003FFF000000000000)
-; CHECK-NEXT:    ret float [[NEXT]]
+; CHECK-NEXT:    ret float 1.000000e+00
 ;
   %arg = fpext float 1.0 to fp128
   %next = call float @nexttowardf(float 1.0, fp128 %arg)
@@ -68,8 +62,7 @@ define float @nexttowardf_equal_args() {
 
 define double @nexttoward_nan_with_payload() {
 ; CHECK-LABEL: define double @nexttoward_nan_with_payload() {
-; CHECK-NEXT:    [[NEXT:%.*]] = call double @nexttoward(double 0x7FF8000000000001, fp128 0xL00000000000000003FFF000000000000)
-; CHECK-NEXT:    ret double [[NEXT]]
+; CHECK-NEXT:    ret double 0x7FF8000000000001
 ;
   %nan = load double, double* @dbl_nan
   %tmp1 = bitcast double %nan to i64
@@ -82,8 +75,7 @@ define double @nexttoward_nan_with_payload() {
 
 define float @nexttowardf_nan_with_payload() {
 ; CHECK-LABEL: define float @nexttowardf_nan_with_payload() {
-; CHECK-NEXT:    [[NEXT:%.*]] = call float @nexttowardf(float 0x7FF8000020000000, fp128 0xL00000000000000003FFF000000000000)
-; CHECK-NEXT:    ret float [[NEXT]]
+; CHECK-NEXT:    ret float 0x7FF8000020000000
 ;
   %nan = load float, float* @flt_nan
   %tmp1 = bitcast float %nan to i32
@@ -97,7 +89,7 @@ define float @nexttowardf_nan_with_payload() {
 define double @nexttoward_pos_overflow() {
 ; CHECK-LABEL: define double @nexttoward_pos_overflow() {
 ; CHECK-NEXT:    [[NEXT:%.*]] = call double @nexttoward(double 0x7FEFFFFFFFFFFFFF, fp128 0xL00000000000000007FFF000000000000)
-; CHECK-NEXT:    ret double [[NEXT]]
+; CHECK-NEXT:    ret double 0x7FF0000000000000
 ;
   %pos_max = load double, double* @dbl_pos_max
   %pos_inf = load double, double* @dbl_pos_infinity
@@ -109,7 +101,7 @@ define double @nexttoward_pos_overflow() {
 define float @nexttowardf_pos_overflow () {
 ; CHECK-LABEL: define float @nexttowardf_pos_overflow() {
 ; CHECK-NEXT:    [[NEXT:%.*]] = call float @nexttowardf(float 0x47EFFFFFE0000000, fp128 0xL00000000000000007FFF000000000000)
-; CHECK-NEXT:    ret float [[NEXT]]
+; CHECK-NEXT:    ret float 0x7FF0000000000000
 ;
   %pos_max = load float, float* @flt_pos_max
   %pos_inf = load float, float* @flt_pos_infinity
@@ -121,7 +113,7 @@ define float @nexttowardf_pos_overflow () {
 define double @nexttoward_neg_overflow() {
 ; CHECK-LABEL: define double @nexttoward_neg_overflow() {
 ; CHECK-NEXT:    [[NEXT:%.*]] = call double @nexttoward(double 0xFFEFFFFFFFFFFFFF, fp128 0xL0000000000000000FFFF000000000000)
-; CHECK-NEXT:    ret double [[NEXT]]
+; CHECK-NEXT:    ret double 0xFFF0000000000000
 ;
   %neg_max = load double, double* @dbl_neg_max
   %neg_inf = load double, double* @dbl_neg_infinity
@@ -133,7 +125,7 @@ define double @nexttoward_neg_overflow() {
 define float @nexttowardf_neg_overflow() {
 ; CHECK-LABEL: define float @nexttowardf_neg_overflow() {
 ; CHECK-NEXT:    [[NEXT:%.*]] = call float @nexttowardf(float 0xC7EFFFFFE0000000, fp128 0xL0000000000000000FFFF000000000000)
-; CHECK-NEXT:    ret float [[NEXT]]
+; CHECK-NEXT:    ret float 0xFFF0000000000000
 ;
   %neg_max = load float, float* @flt_neg_max
   %neg_inf = load float, float* @flt_neg_infinity
@@ -145,7 +137,7 @@ define float @nexttowardf_neg_overflow() {
 define double @nexttoward_zero_from_above() {
 ; CHECK-LABEL: define double @nexttoward_zero_from_above() {
 ; CHECK-NEXT:    [[NEXT:%.*]] = call double @nexttoward(double 4.940660e-324, fp128 0xL00000000000000000000000000000000)
-; CHECK-NEXT:    ret double [[NEXT]]
+; CHECK-NEXT:    ret double 0.000000e+00
 ;
   %subnormal = load double, double* @dbl_pos_min_subnormal
   %zero = fpext double 0.0 to fp128
@@ -156,7 +148,7 @@ define double @nexttoward_zero_from_above() {
 define float @nexttowardf_zero_from_above() {
 ; CHECK-LABEL: define float @nexttowardf_zero_from_above() {
 ; CHECK-NEXT:    [[NEXT:%.*]] = call float @nexttowardf(float 0x36A0000000000000, fp128 0xL00000000000000000000000000000000)
-; CHECK-NEXT:    ret float [[NEXT]]
+; CHECK-NEXT:    ret float 0.000000e+00
 ;
   %min_subnormal = load float, float* @flt_pos_min_subnormal
   %zero = fpext float 0.0 to fp128
@@ -167,7 +159,7 @@ define float @nexttowardf_zero_from_above() {
 define double @nexttoward_zero_from_below() {
 ; CHECK-LABEL: define double @nexttoward_zero_from_below() {
 ; CHECK-NEXT:    [[NEXT:%.*]] = call double @nexttoward(double -4.940660e-324, fp128 0xL00000000000000000000000000000000)
-; CHECK-NEXT:    ret double [[NEXT]]
+; CHECK-NEXT:    ret double -0.000000e+00
 ;
   %subnormal = load double, double* @dbl_neg_min_subnormal
   %zero = fpext double 0.0 to fp128
@@ -178,7 +170,7 @@ define double @nexttoward_zero_from_below() {
 define float @nexttowardf_zero_from_below() {
 ; CHECK-LABEL: define float @nexttowardf_zero_from_below() {
 ; CHECK-NEXT:    [[NEXT:%.*]] = call float @nexttowardf(float 0xB6A0000000000000, fp128 0xL00000000000000000000000000000000)
-; CHECK-NEXT:    ret float [[NEXT]]
+; CHECK-NEXT:    ret float -0.000000e+00
 ;
   %min_subnormal = load float, float* @flt_neg_min_subnormal
   %zero = fpext float 0.0 to fp128
@@ -189,7 +181,7 @@ define float @nexttowardf_zero_from_below() {
 define double @nexttoward_subnormal() {
 ; CHECK-LABEL: define double @nexttoward_subnormal() {
 ; CHECK-NEXT:    [[NEXT:%.*]] = call double @nexttoward(double 4.940660e-324, fp128 0xL00000000000000003FFF000000000000)
-; CHECK-NEXT:    ret double [[NEXT]]
+; CHECK-NEXT:    ret double 9.881310e-324
 ;
   %subnormal = load double, double* @dbl_pos_min_subnormal
   %target = fpext double 1.0 to fp128
@@ -200,7 +192,7 @@ define double @nexttoward_subnormal() {
 define float @nexttowardf_subnormal() {
 ; CHECK-LABEL: define float @nexttowardf_subnormal() {
 ; CHECK-NEXT:    [[NEXT:%.*]] = call float @nexttowardf(float 0x36A0000000000000, fp128 0xL00000000000000003FFF000000000000)
-; CHECK-NEXT:    ret float [[NEXT]]
+; CHECK-NEXT:    ret float 0x36B0000000000000
 ;
   %subnormal = load float, float* @flt_pos_min_subnormal
   %target = fpext float 1.0 to fp128
@@ -231,7 +223,7 @@ define float @nexttowardf_poison() {
 define double @nexttoward_subnormal_readnone() {
 ; CHECK-LABEL: define double @nexttoward_subnormal_readnone() {
 ; CHECK-NEXT:    [[NEXT:%.*]] = call double @nexttoward(double 4.940660e-324, fp128 0xL00000000000000003FFF000000000000) #[[ATTR1:[0-9]+]]
-; CHECK-NEXT:    ret double [[NEXT]]
+; CHECK-NEXT:    ret double 9.881310e-324
 ;
   %subnormal = load double, double* @dbl_pos_min_subnormal
   %target = fpext double 1.0 to fp128
@@ -242,7 +234,7 @@ define double @nexttoward_subnormal_readnone() {
 define float @nexttowardf_subnormal_readnone() {
 ; CHECK-LABEL: define float @nexttowardf_subnormal_readnone() {
 ; CHECK-NEXT:    [[NEXT:%.*]] = call float @nexttowardf(float 0x36A0000000000000, fp128 0xL00000000000000003FFF000000000000) #[[ATTR1]]
-; CHECK-NEXT:    ret float [[NEXT]]
+; CHECK-NEXT:    ret float 0x36B0000000000000
 ;
   %subnormal = load float, float* @flt_pos_min_subnormal
   %target = fpext float 1.0 to fp128
diff --git a/llvm/test/Transforms/InstCombine/constant-fold-nexttoward-ppc-fp128.ll b/llvm/test/Transforms/InstCombine/constant-fold-nexttoward-ppc-fp128.ll
index cfb1db14676b0..4eb6ae190c209 100644
--- a/llvm/test/Transforms/InstCombine/constant-fold-nexttoward-ppc-fp128.ll
+++ b/llvm/test/Transforms/InstCombine/constant-fold-nexttoward-ppc-fp128.ll
@@ -8,8 +8,7 @@ attributes #0 = { willreturn memory(errnomem: write) }
 
 define double @nexttoward_up_direction() {
 ; CHECK-LABEL: define double @nexttoward_up_direction() {
-; CHECK-NEXT:    [[NEXT:%.*]] = call double @nexttoward(double 1.000000e+00, ppc_fp128 0xM40000000000000000000000000000000)
-; CHECK-NEXT:    ret double [[NEXT]]
+; CHECK-NEXT:    ret double 0x3FF0000000000001
 ;
   %arg = fpext double 2.0 to ppc_fp128
   %next = call double @nexttoward(double 1.0, ppc_fp128 %arg)
@@ -18,8 +17,7 @@ define double @nexttoward_up_direction() {
 
 define float @nexttowardf_up_direction() {
 ; CHECK-LABEL: define float @nexttowardf_up_direction() {
-; CHECK-NEXT:    [[NEXT:%.*]] = call float @nexttowardf(float 1.000000e+00, ppc_fp128 0xM40000000000000000000000000000000)
-; CHECK-NEXT:    ret float [[NEXT]]
+; CHECK-NEXT:    ret float 0x3FF0000020000000
 ;
   %arg = fpext float 2.0 to ppc_fp128
   %next = call float @nexttowardf(float 1.0, ppc_fp128 %arg)
@@ -28,8 +26,7 @@ define float @nexttowardf_up_direction() {
 
 define double @nexttoward_down_direction() {
 ; CHECK-LABEL: define double @nexttoward_down_direction() {
-; CHECK-NEXT:    [[NEXT:%.*]] = call double @nexttoward(double 1.000000e+00, ppc_fp128 0xM00000000000000000000000000000000)
-; CHECK-NEXT:    ret double [[NEXT]]
+; CHECK-NEXT:    ret double 0x3FEFFFFFFFFFFFFF
 ;
   %arg = fpext double 0.0 to ppc_fp128
   %next = call double @nexttoward(double 1.0, ppc_fp128 %arg)
@@ -38,8 +35,7 @@ define double @nexttoward_down_direction() {
 
 define float @nexttowardf_down_direction() {
 ; CHECK-LABEL: define float @nexttowardf_down_direction() {
-; CHECK-NEXT:    [[NEXT:%.*]] = call float @nexttowardf(float 1.000000e+00, ppc_fp128 0xM00000000000000000000000000000000)
-; CHECK-NEXT:    ret float [[NEXT]]
+; CHECK-NEXT:    ret float 0x3FEFFFFFE0000000
 ;
   %arg = fpext float 0.0 to ppc_fp128
   %next = call float @nexttowardf(float 1.0, ppc_fp128 %arg)
@@ -49,7 +45,7 @@ define float @nexttowardf_down_direction() {
 define double @nexttoward_pos_overflow() {
 ; CHECK-LABEL: define double @nexttoward_pos_overflow() {
 ; CHECK-NEXT:    [[NEXT:%.*]] = call double @nexttoward(double 0x7FEFFFFFFFFFFFFF, ppc_fp128 0xM7FF00000000000000000000000000000)
-; CHECK-NEXT:    ret double [[NEXT]]
+; CHECK-NEXT:    ret double 0x7FF0000000000000
 ;
   %pos_max = load double, double* @dbl_pos_max
   %pos_inf = load double, double* @dbl_pos_infinity
@@ -61,7 +57,7 @@ define double @nexttoward_pos_overflow() {
 define float @nexttowardf_pos_overflow () {
 ; CHECK-LABEL: define float @nexttowardf_pos_overflow() {
 ; CHECK-NEXT:    [[NEXT:%.*]] = call float @nexttowardf(float 0x47EFFFFFE0000000, ppc_fp128 0xM7FF00000000000000000000000000000)
-; CHECK-NEXT:    ret float [[NEXT]]
+; CHECK-NEXT:    ret float 0x7FF0000000000000
 ;
   %pos_max = load float, float* @flt_pos_max
   %pos_inf = load float, float* @flt_pos_infinity
@@ -73,7 +69,7 @@ define float @nexttowardf_pos_overflow () {
 define double @nexttoward_neg_overflow() {
 ; CHECK-LABEL: define double @nexttoward_neg_overflow() {
 ; CHECK-NEXT:    [[NEXT:%.*]] = call double @nexttoward(double 0xFFEFFFFFFFFFFFFF, ppc_fp128 0xMFFF00000000000000000000000000000)
-; CHECK-NEXT:    ret double [[NEXT]]
+; CHECK-NEXT:    ret double 0xFFF0000000000000
 ;
   %neg_max = load double, double* @dbl_neg_max
   %neg_inf = load double, double* @dbl_neg_infinity
@@ -85,7 +81,7 @@ define double @nexttoward_neg_overflow() {
 define float @nexttowardf_neg_overflow() {
 ; CHECK-LABEL: define float @nexttowardf_neg_overflow() {
 ; CHECK-NEXT:    [[NEXT:%.*]] = call float @nexttowardf(float 0xC7EFFFFFE0000000, ppc_fp128 0xMFFF00000000000000000000000000000)
-; CHECK-NEXT:    ret float [[NEXT]]
+; CHECK-NEXT:    ret float 0xFFF0000000000000
 ;
   %neg_max = load float, float* @flt_neg_max
   %neg_inf = load float, float* @flt_neg_infinity
@@ -97,7 +93,7 @@ define float @nexttowardf_neg_overflow() {
 define double @nexttoward_subnormal() {
 ; CHECK-LABEL: define double @nexttoward_subnormal() {
 ; CHECK-NEXT:    [[NEXT:%.*]] = call double @nexttoward(double 4.940660e-324, ppc_fp128 0xM3FF00000000000000000000000000000)
-; CHECK-NEXT:    ret double [[NEXT]]
+; CHECK-NEXT:    ret double 9.881310e-324
 ;
   %subnormal = load double, double* @dbl_pos_min_subnormal
   %target = fpext double 1.0 to ppc_fp128
@@ -108,7 +104,7 @@ define double @nexttoward_subnormal() {
 define float @nexttowardf_subnormal() {
 ; CHECK-LABEL: define float @nexttowardf_subnormal() {
 ; CHECK-NEXT:    [[NEXT:%.*]] = call float @nexttowardf(float 0x36A0000000000000, ppc_fp128 0xM3FF00000000000000000000000000000)
-; CHECK-NEXT:    ret float [[NEXT]]
+; CHECK-NEXT:    ret float 0x36B0000000000000
 ;
   %subnormal = load float, float* @flt_pos_min_subnormal
   %target = fpext float 1.0 to ppc_fp128
diff --git a/llvm/test/Transforms/InstCombine/constant-fold-nexttoward-x86-fp80.ll b/llvm/test/Transforms/InstCombine/constant-fold-nexttoward-x86-fp80.ll
index 7cbdad338f0e9..4b26d9ac6cd68 100644
--- a/llvm/test/Transforms/InstCombine/constant-fold-nexttoward-x86-fp80.ll
+++ b/llvm/test/Transforms/InstCombine/constant-fold-nexttoward-x86-fp80.ll
@@ -8,8 +8,7 @@ attributes #0 = { willreturn memory(errnomem: write) }
 
 define double @nexttoward_up_direction() {
 ; CHECK-LABEL: define double @nexttoward_up_direction() {
-; CHECK-NEXT:    [[NEXT:%.*]] = call double @nexttoward(double 1.000000e+00, x86_fp80 0xK40008000000000000000)
-; CHECK-NEXT:    ret double [[NEXT]]
+; CHECK-NEXT:    ret double 0x3FF0000000000001
 ;
   %arg = fpext double 2.0 to x86_fp80
   %next = call double @nexttoward(double 1.0, x86_fp80 %arg)
@@ -18,8 +17,7 @@ define double @nexttoward_up_direction() {
 
 define float @nexttowardf_up_direction() {
 ; CHECK-LABEL: define float @nexttowardf_up_direction() {
-; CHECK-NEXT:    [[NEXT:%.*]] = call float @nexttowardf(float 1.000000e+00, x86_fp80 0xK40008000000000000000)
-; CHECK-NEXT:    ret float [[NEXT]]
+; CHECK-NEXT:    ret float 0x3FF0000020000000
 ;
   %arg = fpext float 2.0 to x86_fp80
   %next = call float @nexttowardf(float 1.0, x86_fp80 %arg)
@@ -28,8 +26,7 @@ define float @nexttowardf_up_direction() {
 
 define double @nexttoward_down_direction() {
 ; CHECK-LABEL: define double @nexttoward_down_direction() {
-; CHECK-NEXT:    [[NEXT:%.*]] = call double @nexttoward(double 1.000000e+00, x86_fp80 0xK00000000000000000000)
-; CHECK-NEXT:    ret double [[NEXT]]
+; CHECK-NEXT:    ret double 0x3FEFFFFFFFFFFFFF
 ;
   %arg = fpext double 0.0 to x86_fp80
   %next = call double @nexttoward(double 1.0, x86_fp80 %arg)
@@ -38,8 +35,7 @@ define double @nexttoward_down_direction() {
 
 define float @nexttowardf_down_direction() {
 ; CHECK-LABEL: define float @nexttowardf_down_direction() {
-; CHECK-NEXT:    [[NEXT:%.*]] = call float @nexttowardf(float 1.000000e+00, x86_fp80 0xK00000000000000000000)
-; CHECK-NEXT:    ret float [[NEXT]]
+; CHECK-NEXT:    ret float 0x3FEFFFFFE0000000
 ;
   %arg = fpext float 0.0 to x86_fp80
   %next = call float @nexttowardf(float 1.0, x86_fp80 %arg)
@@ -49,7 +45,7 @@ define float @nexttowardf_down_direction() {
 define double @nexttoward_pos_overflow () {
 ; CHECK-LABEL: define double @nexttoward_pos_overflow() {
 ; CHECK-NEXT:    [[NEXT:%.*]] = call double @nexttoward(double 0x7FEFFFFFFFFFFFFF, x86_fp80 0xK7FFF8000000000000000)
-; CHECK-NEXT:    ret double [[NEXT]]
+; CHECK-NEXT:    ret double 0x7FF0000000000000
 ;
   %pos_max = load double, double* @dbl_pos_max
   %pos_inf = load double, double* @dbl_pos_infinity
@@ -61,7 +57,7 @@ define double @nexttoward_pos_overflow () {
 define float @nexttowardf_pos_overflow() {
 ; CHECK-LABEL: define float @nexttowardf_pos_overflow() {
 ; CHECK-NEXT:    [[NEXT:%.*]] = call float @nexttowardf(float 0x47EFFFFFE0000000, x86_fp80 0xK7FFF8000000000000000)
-; CHECK-NEXT:    ret float [[NEXT]]
+; CHECK-NEXT:    ret float 0x7FF0000000000000
 ;
   %pos_max = load float, float* @flt_pos_max
   %pos_inf = load float, float* @flt_pos_infinity
@@ -73,7 +69,7 @@ define float @nexttowardf_pos_overflow() {
 define double @nexttoward_neg_overflow() {
 ; CHECK-LABEL: define double @nexttoward_neg_overflow() {
 ; CHECK-NEXT:    [[NEXT:%.*]] = call double @nexttoward(double 0xFFEFFFFFFFFFFFFF, x86_fp80 0xKFFFF8000000000000000)
-; CHECK-NEXT:    ret double [[NEXT]]
+; CHECK-NEXT:    ret double 0xFFF0000000000000
 ;
   %neg_max = load double, double* @dbl_neg_max
   %neg_inf = load double, double* @dbl_neg_infinity
@@ -85,7 +81,7 @@ define double @nexttoward_neg_overflow() {
 define float @nexttowardf_neg_overflow() {
 ; CHECK-LABEL: define float @nexttowardf_neg_overflow() {
 ; CHECK-NEXT:    [[NEXT:%.*]] = call float @nexttowardf(float 0xC7EFFFFFE0000000, x86_fp80 0xKFFFF8000000000000000)
-; CHECK-NEXT:    ret float [[NEXT]]
+; CHECK-NEXT:    ret float 0xFFF0000000000000
 ;
   %neg_max = load float, float* @flt_neg_max
   %neg_inf = load float, float* @flt_neg_infinity
@@ -97,7 +93,7 @@ define float @nexttowardf_neg_overflow() {
 define double @nexttoward_subnormal() {
 ; CHECK-LABEL: define double @nexttoward_subnormal() {
 ; CHECK-NEXT:    [[NEXT:%.*]] = call double @nexttoward(double 4.940660e-324, x86_fp80 0xK3FFF8000000000000000)
-; CHECK-NEXT:    ret double [[NEXT]]
+; CHECK-NEXT:    ret double 9.881310e-324
 ;
   %subnormal = load double, double* @dbl_pos_min_subnormal
   %target = fpext double 1.0 to x86_fp80
@@ -108,7 +104,7 @@ define double @nexttoward_subnormal() {
 define float @nexttowardf_subnormal() {
 ; CHECK-LABEL: define float @nexttowardf_subnormal() {
 ; CHECK-NEXT:    [[NEXT:%.*]] = call float @nexttowardf(float 0x36A0000000000000, x86_fp80 0xK3FFF8000000000000000)
-; CHECK-NEXT:    ret float [[NEXT]]
+; CHECK-NEXT:    ret float 0x36B0000000000000
 ;
   %subnormal = load float, float* @flt_pos_min_subnormal
   %target = fpext float 1.0 to x86_fp80



More information about the llvm-commits mailing list