[llvm] [ConstantFolding] Add constant folding support for nextafter/nexttoward (PR #167324)
Joshua Cranmer via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 12 14:03:39 PST 2025
================
@@ -3221,6 +3223,26 @@ 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)) {
+ if (Op1V.isNaN() || Op2V.isNaN()) {
+ return ConstantFP::get(Ty->getContext(),
+ APFloat::getNaN(Ty->getFltSemantics()));
+ }
+
+ APFloat PromotedOp1V = Op1V.getPromoted(APFloat::IEEEquad());
+ APFloat PromotedOp2V = Op2V.getPromoted(APFloat::IEEEquad());
----------------
jcranmer-intel wrote:
I should also add, C and C++ both guarantee that the set of values for `long double` is a (not necessarily strict) superset of the set of values representable for `double`.
https://github.com/llvm/llvm-project/pull/167324
More information about the llvm-commits
mailing list