Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions llvm/include/llvm/Analysis/TargetLibraryInfo.def
Original file line number Diff line number Diff line change
Expand Up @@ -1951,6 +1951,36 @@ TLI_DEFINE_ENUM_INTERNAL(nearbyintl)
TLI_DEFINE_STRING_INTERNAL("nearbyintl")
TLI_DEFINE_SIG_INTERNAL(LDbl, LDbl)

/// double nextafter(double x, double y);
TLI_DEFINE_ENUM_INTERNAL(nextafter)
TLI_DEFINE_STRING_INTERNAL("nextafter")
TLI_DEFINE_SIG_INTERNAL(Dbl, Dbl, Dbl)

/// float nextafterf(float x, float y);
TLI_DEFINE_ENUM_INTERNAL(nextafterf)
TLI_DEFINE_STRING_INTERNAL("nextafterf")
TLI_DEFINE_SIG_INTERNAL(Flt, Flt, Flt)

/// long double nextafterl(long double x, long double y);
TLI_DEFINE_ENUM_INTERNAL(nextafterl)
TLI_DEFINE_STRING_INTERNAL("nextafterl")
TLI_DEFINE_SIG_INTERNAL(LDbl, LDbl, LDbl)

/// double nexttoward(double x, long double y);
TLI_DEFINE_ENUM_INTERNAL(nexttoward)
TLI_DEFINE_STRING_INTERNAL("nexttoward")
TLI_DEFINE_SIG_INTERNAL(Dbl, Dbl, LDbl)

/// float nexttowardf(float x, long double y);
TLI_DEFINE_ENUM_INTERNAL(nexttowardf)
TLI_DEFINE_STRING_INTERNAL("nexttowardf")
TLI_DEFINE_SIG_INTERNAL(Flt, Flt, LDbl)

/// long double nexttowardl(long double x, long double y);
TLI_DEFINE_ENUM_INTERNAL(nexttowardl)
TLI_DEFINE_STRING_INTERNAL("nexttowardl")
TLI_DEFINE_SIG_INTERNAL(LDbl, LDbl, LDbl)

/// uint32_t ntohl(uint32_t netlong);
TLI_DEFINE_ENUM_INTERNAL(ntohl)
TLI_DEFINE_STRING_INTERNAL("ntohl")
Expand Down
6 changes: 6 additions & 0 deletions llvm/lib/Analysis/TargetLibraryInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,10 @@ static void initializeLibCalls(TargetLibraryInfoImpl &TLI, const Triple &T,
TLI.setAvailableWithName(LibFunc_logbf, "_logbf");
else
TLI.setUnavailable(LibFunc_logbf);
TLI.setUnavailable(LibFunc_nextafter);
TLI.setUnavailable(LibFunc_nextafterf);
TLI.setUnavailable(LibFunc_nexttoward);
TLI.setUnavailable(LibFunc_nexttowardf);
TLI.setUnavailable(LibFunc_rint);
TLI.setUnavailable(LibFunc_rintf);
TLI.setUnavailable(LibFunc_round);
Expand Down Expand Up @@ -418,6 +422,8 @@ static void initializeLibCalls(TargetLibraryInfoImpl &TLI, const Triple &T,
TLI.setUnavailable(LibFunc_logbl);
TLI.setUnavailable(LibFunc_ilogbl);
TLI.setUnavailable(LibFunc_nearbyintl);
TLI.setUnavailable(LibFunc_nextafterl);
TLI.setUnavailable(LibFunc_nexttowardl);
Copy link
Contributor Author

@sivakusayan sivakusayan Nov 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was bit confused by the comment:

// Win32 does not support long double C99 math functions.

as I believe this documentation implies long double support for many C99 functions goes back as early as MSVC 140. I haven't actually tried it myself though and might be misunderstanding something, so I'll just follow the pattern for now.

Copy link
Contributor Author

@sivakusayan sivakusayan Nov 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This quote in the documentation linked in the code comments seems interesting:

Previous 16-bit versions of Microsoft C/C++ and Microsoft Visual C++ supported the long double type as an 80-bit precision floating-point data type. In later versions of Visual C++, the long double data type is a 64-bit precision floating-point data type identical to the double type. The compiler treats long double and double as distinct types, but the long double functions are identical to their double counterparts. The CRT provides long double versions of the math functions for ISO C99 source code compatibility, but note that the binary representation may differ from other compilers.

It's unfortunate that paragraph isn't more specific about the MSVC version, it's probably not worth worrying in this PR in any case.

TLI.setUnavailable(LibFunc_rintl);
TLI.setUnavailable(LibFunc_roundl);
TLI.setUnavailable(LibFunc_scalblnl);
Expand Down
6 changes: 6 additions & 0 deletions llvm/lib/Transforms/Utils/BuildLibCalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1283,6 +1283,12 @@ bool llvm::inferNonMandatoryLibFuncAttrs(Function &F,
case LibFunc_ilogbl:
case LibFunc_logf:
case LibFunc_logl:
case LibFunc_nextafter:
case LibFunc_nextafterf:
case LibFunc_nextafterl:
case LibFunc_nexttoward:
case LibFunc_nexttowardf:
case LibFunc_nexttowardl:
case LibFunc_pow:
case LibFunc_powf:
case LibFunc_powl:
Expand Down
18 changes: 18 additions & 0 deletions llvm/test/Transforms/InferFunctionAttrs/annotate.ll
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,24 @@ declare float @nearbyintf(float)
; CHECK: declare x86_fp80 @nearbyintl(x86_fp80) [[MEMNONE_NOFREE_NOUNWIND_WILLRETURN:#[0-9]+]]
declare x86_fp80 @nearbyintl(x86_fp80)

; CHECK: declare double @nextafter(double, double) [[ERRNOMEMONLY_NOFREE_NOUNWIND_WILLRETURN:#[0-9]+]]
declare double @nextafter(double, double)

; CHECK: declare float @nextafterf(float, float) [[ERRNOMEMONLY_NOFREE_NOUNWIND_WILLRETURN:#[0-9]+]]
declare float @nextafterf(float, float)

; CHECK: declare x86_fp80 @nextafterl(x86_fp80, x86_fp80) [[ERRNOMEMONLY_NOFREE_NOUNWIND_WILLRETURN:#[0-9]+]]
declare x86_fp80 @nextafterl(x86_fp80, x86_fp80)

; CHECK: declare double @nexttoward(double, x86_fp80) [[ERRNOMEMONLY_NOFREE_NOUNWIND_WILLRETURN:#[0-9]+]]
declare double @nexttoward(double, x86_fp80)

; CHECK: declare float @nexttowardf(float, x86_fp80) [[ERRNOMEMONLY_NOFREE_NOUNWIND_WILLRETURN:#[0-9]+]]
declare float @nexttowardf(float, x86_fp80)

; CHECK: declare x86_fp80 @nexttowardl(x86_fp80, x86_fp80) [[ERRNOMEMONLY_NOFREE_NOUNWIND_WILLRETURN:#[0-9]+]]
declare x86_fp80 @nexttowardl(x86_fp80, x86_fp80)

; CHECK-LINUX: declare noundef i32 @open(ptr noundef readonly captures(none), i32 noundef, ...) [[NOFREE]]
; CHECK-OPEN: declare noundef i32 @open(ptr noundef readonly captures(none), i32 noundef, ...) [[NOFREE:#[0-9]+]]
declare i32 @open(ptr, i32, ...)
Expand Down
32 changes: 28 additions & 4 deletions llvm/test/tools/llvm-tli-checker/ps4-tli-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#
# CHECK: << Total TLI yes SDK no: 18
# CHECK: >> Total TLI no SDK yes: 0
# CHECK: == Total TLI yes SDK yes: 271
# CHECK: == Total TLI yes SDK yes: 277
#
# WRONG_DETAIL: << TLI yes SDK no : '_ZdaPv' aka operator delete[](void*)
# WRONG_DETAIL: >> TLI no SDK yes: '_ZdaPvj' aka operator delete[](void*, unsigned int)
Expand All @@ -48,14 +48,14 @@
# WRONG_DETAIL: << TLI yes SDK no : 'fminimum_numl'
# WRONG_SUMMARY: << Total TLI yes SDK no: 19{{$}}
# WRONG_SUMMARY: >> Total TLI no SDK yes: 1{{$}}
# WRONG_SUMMARY: == Total TLI yes SDK yes: 270
# WRONG_SUMMARY: == Total TLI yes SDK yes: 276
#
## The -COUNT suffix doesn't care if there are too many matches, so check
## the exact count first; the two directives should add up to that.
## Yes, this means additions to TLI will fail this test, but the argument
## to -COUNT can't be an expression.
# AVAIL: TLI knows 524 symbols, 289 available
# AVAIL-COUNT-289: {{^}} available
# AVAIL: TLI knows 530 symbols, 295 available
# AVAIL-COUNT-295: {{^}} available
# AVAIL-NOT: {{^}} available
# UNAVAIL-COUNT-235: not available
# UNAVAIL-NOT: not available
Expand Down Expand Up @@ -778,6 +778,30 @@ DynamicSymbols:
Type: STT_FUNC
Section: .text
Binding: STB_GLOBAL
- Name: nextafter
Type: STT_FUNC
Section: .text
Binding: STB_GLOBAL
- Name: nextafterf
Type: STT_FUNC
Section: .text
Binding: STB_GLOBAL
- Name: nextafterl
Type: STT_FUNC
Section: .text
Binding: STB_GLOBAL
- Name: nexttoward
Type: STT_FUNC
Section: .text
Binding: STB_GLOBAL
- Name: nexttowardf
Type: STT_FUNC
Section: .text
Binding: STB_GLOBAL
- Name: nexttowardl
Type: STT_FUNC
Section: .text
Binding: STB_GLOBAL
Copy link
Contributor Author

@sivakusayan sivakusayan Nov 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that other similar patches added entries here, but I wasn't sure where to find authoritative documentation on what math functions are supported for PS4. Is there some obvious documentation I'm missing? The closest I was able to find is this wiki, which doesn't seem the most authoritative.

- Name: perror
Type: STT_FUNC
Section: .text
Expand Down
6 changes: 6 additions & 0 deletions llvm/unittests/Analysis/TargetLibraryInfoTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,12 @@ TEST_F(TargetLibraryInfoTest, ValidProto) {
"declare x86_fp80 @logbl(x86_fp80)\n"
"declare float @logf(float)\n"
"declare x86_fp80 @logl(x86_fp80)\n"
"declare double @nextafter(double, double)\n"
"declare float @nextafterf(float, float)\n"
"declare x86_fp80 @nextafterl(x86_fp80, x86_fp80)\n"
"declare double @nexttoward(double, x86_fp80)\n"
"declare float @nexttowardf(float, x86_fp80)\n"
"declare x86_fp80 @nexttowardl(x86_fp80, x86_fp80)\n"
"declare i8* @malloc(i64)\n"
"declare i8* @memccpy(i8*, i8*, i32, i64)\n"
"declare i8* @memchr(i8*, i32, i64)\n"
Expand Down
Loading