[llvm] TargetLibraryInfo: Disable roundeven variants by default except for GLIBC (PR #188898)
Brad Smith via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 3 17:03:23 PDT 2026
https://github.com/brad0 updated https://github.com/llvm/llvm-project/pull/188898
>From 90d0576fce52a7425107077b53c7fe75c492c612 Mon Sep 17 00:00:00 2001
From: Brad Smith <brad at comstyle.com>
Date: Tue, 24 Mar 2026 19:16:38 -0400
Subject: [PATCH] TargetLibraryInfo: Disable roundeven variants by default
except for GLIBC
roundeven functions are quite new only being added C23. None of the
other major libc's be it from Musl, Bionic, *BSD's libc, Solaris
have these functions.
---
llvm/lib/Analysis/TargetLibraryInfo.cpp | 18 ++++++++++++------
.../Transforms/InferFunctionAttrs/annotate.ll | 6 +++---
2 files changed, 15 insertions(+), 9 deletions(-)
diff --git a/llvm/lib/Analysis/TargetLibraryInfo.cpp b/llvm/lib/Analysis/TargetLibraryInfo.cpp
index d0555d68606b4..9a42f4f5548a0 100644
--- a/llvm/lib/Analysis/TargetLibraryInfo.cpp
+++ b/llvm/lib/Analysis/TargetLibraryInfo.cpp
@@ -142,6 +142,12 @@ static void initializeLibCalls(TargetLibraryInfoImpl &TLI, const Triple &T,
TLI.setUnavailable(LibFunc_fputs_unlocked);
TLI.setUnavailable(LibFunc_fgets_unlocked);
+ // Set roundeven variants as unavailable
+ // Set them as available per system below
+ TLI.setUnavailable(LibFunc_roundeven);
+ TLI.setUnavailable(LibFunc_roundevenf);
+ TLI.setUnavailable(LibFunc_roundevenl);
+
// There is really no runtime library on AMDGPU, apart from
// __kmpc_alloc/free_shared.
if (T.isAMDGPU()) {
@@ -677,6 +683,12 @@ static void initializeLibCalls(TargetLibraryInfoImpl &TLI, const Triple &T,
TLI.setUnavailable(LibFunc_sqrtl_finite);
}
+ if (T.isOSLinux() && T.isGNUEnvironment()) {
+ TLI.setAvailable(LibFunc_roundeven);
+ TLI.setAvailable(LibFunc_roundevenf);
+ TLI.setAvailable(LibFunc_roundevenl);
+ }
+
if ((T.isOSLinux() && T.isGNUEnvironment()) ||
(T.isAndroid() && !T.isAndroidVersionLT(28))) {
// available IO unlocked variants on GNU/Linux and Android P or later
@@ -810,9 +822,6 @@ static void initializeLibCalls(TargetLibraryInfoImpl &TLI, const Triple &T,
TLI.setUnavailable(LibFunc_ntohs);
TLI.setUnavailable(LibFunc_reallocarray);
TLI.setUnavailable(LibFunc_reallocf);
- TLI.setUnavailable(LibFunc_roundeven);
- TLI.setUnavailable(LibFunc_roundevenf);
- TLI.setUnavailable(LibFunc_roundevenl);
TLI.setUnavailable(LibFunc_stpcpy);
TLI.setUnavailable(LibFunc_stpncpy);
TLI.setUnavailable(LibFunc_strlcat);
@@ -845,9 +854,6 @@ static void initializeLibCalls(TargetLibraryInfoImpl &TLI, const Triple &T,
TLI.setUnavailable(LibFunc_fminimum_num);
TLI.setUnavailable(LibFunc_fminimum_numf);
TLI.setUnavailable(LibFunc_fminimum_numl);
- TLI.setUnavailable(LibFunc_roundeven);
- TLI.setUnavailable(LibFunc_roundevenf);
- TLI.setUnavailable(LibFunc_roundevenl);
}
// As currently implemented in clang, NVPTX code has no standard library to
diff --git a/llvm/test/Transforms/InferFunctionAttrs/annotate.ll b/llvm/test/Transforms/InferFunctionAttrs/annotate.ll
index ed5d5a56770f9..66c85c544bdf9 100644
--- a/llvm/test/Transforms/InferFunctionAttrs/annotate.ll
+++ b/llvm/test/Transforms/InferFunctionAttrs/annotate.ll
@@ -936,13 +936,13 @@ declare float @roundf(float)
; CHECK: declare x86_fp80 @roundl(x86_fp80) [[MEMNONE_NOFREE_NOUNWIND_WILLRETURN]]
declare x86_fp80 @roundl(x86_fp80)
-; CHECK: declare double @roundeven(double) [[MEMNONE_NOFREE_NOUNWIND_WILLRETURN]]
+; CHECK-LINUX: declare double @roundeven(double) [[MEMNONE_NOFREE_NOUNWIND_WILLRETURN]]
declare double @roundeven(double)
-; CHECK: declare float @roundevenf(float) [[MEMNONE_NOFREE_NOUNWIND_WILLRETURN]]
+; CHECK-LINUX: declare float @roundevenf(float) [[MEMNONE_NOFREE_NOUNWIND_WILLRETURN]]
declare float @roundevenf(float)
-; CHECK: declare x86_fp80 @roundevenl(x86_fp80) [[MEMNONE_NOFREE_NOUNWIND_WILLRETURN]]
+; CHECK-LINUX: declare x86_fp80 @roundevenl(x86_fp80) [[MEMNONE_NOFREE_NOUNWIND_WILLRETURN]]
declare x86_fp80 @roundevenl(x86_fp80)
; CHECK: declare double @scalbln(double, i64) [[ERRNOMEMONLY_NOFREE_NOUNWIND_WILLRETURN]]
More information about the llvm-commits
mailing list