[llvm] [ConstantFolding] Handle roundeven libcalls (PR #170692)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 4 08:42:37 PST 2025
https://github.com/valadaptive created https://github.com/llvm/llvm-project/pull/170692
Basically identical to nearbyint and rint, which we already treat as
rounding to nearest with ties to even during constant folding.
>From 72bb0227fc52369bc2aa31490a1ef76ad8177278 Mon Sep 17 00:00:00 2001
From: valadaptive <valadaptive at protonmail.com>
Date: Thu, 4 Dec 2025 10:42:03 -0500
Subject: [PATCH] [ConstantFolding] Handle roundeven libcalls
Basically identical to nearbyint and rint, which we already treat as
rounding to nearest with ties to even during constant folding.
---
llvm/lib/Analysis/ConstantFolding.cpp | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp
index 63d12ee585e64..b39b32042dd2f 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -1984,6 +1984,7 @@ bool llvm::canConstantFoldCallTo(const CallBase *Call, const Function *F) {
switch (Name[0]) {
default:
return false;
+ // clang-format off
case 'a':
return Name == "acos" || Name == "acosf" ||
Name == "asin" || Name == "asinf" ||
@@ -2014,7 +2015,8 @@ bool llvm::canConstantFoldCallTo(const CallBase *Call, const Function *F) {
case 'r':
return Name == "remainder" || Name == "remainderf" ||
Name == "rint" || Name == "rintf" ||
- Name == "round" || Name == "roundf";
+ Name == "round" || Name == "roundf" ||
+ Name == "roundeven" || Name == "roundevenf";
case 's':
return Name == "sin" || Name == "sinf" ||
Name == "sinh" || Name == "sinhf" ||
@@ -2052,6 +2054,7 @@ bool llvm::canConstantFoldCallTo(const CallBase *Call, const Function *F) {
case 's':
return Name == "__sinh_finite" || Name == "__sinhf_finite";
}
+ // clang-format on
}
}
@@ -2516,7 +2519,8 @@ static Constant *ConstantFoldScalarCall1(StringRef Name,
// Use internal versions of these intrinsics.
- if (IntrinsicID == Intrinsic::nearbyint || IntrinsicID == Intrinsic::rint) {
+ if (IntrinsicID == Intrinsic::nearbyint || IntrinsicID == Intrinsic::rint ||
+ IntrinsicID == Intrinsic::roundeven) {
U.roundToIntegral(APFloat::rmNearestTiesToEven);
return ConstantFP::get(Ty->getContext(), U);
}
@@ -2988,6 +2992,8 @@ static Constant *ConstantFoldScalarCall1(StringRef Name,
case LibFunc_nearbyintf:
case LibFunc_rint:
case LibFunc_rintf:
+ case LibFunc_roundeven:
+ case LibFunc_roundevenf:
if (TLI->has(Func)) {
U.roundToIntegral(APFloat::rmNearestTiesToEven);
return ConstantFP::get(Ty->getContext(), U);
More information about the llvm-commits
mailing list