Skip to content

[TLI] Add support for lgamma libcall. #114536

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
15 changes: 15 additions & 0 deletions llvm/include/llvm/Analysis/TargetLibraryInfo.def
Original file line number Diff line number Diff line change
Expand Up @@ -1726,6 +1726,21 @@ TLI_DEFINE_ENUM_INTERNAL(ldexpl)
TLI_DEFINE_STRING_INTERNAL("ldexpl")
TLI_DEFINE_SIG_INTERNAL(LDbl, LDbl, Int)

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

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

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

/// long long int llabs(long long int j);
TLI_DEFINE_ENUM_INTERNAL(llabs)
TLI_DEFINE_STRING_INTERNAL("llabs")
Expand Down
2 changes: 2 additions & 0 deletions llvm/lib/Analysis/TargetLibraryInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ static void initializeLibCalls(TargetLibraryInfoImpl &TLI, const Triple &T,
TLI.setUnavailable(LibFunc_floorf);
TLI.setUnavailable(LibFunc_fmodf);
TLI.setUnavailable(LibFunc_hypotf);
TLI.setUnavailable(LibFunc_lgammaf);
TLI.setUnavailable(LibFunc_log10f);
TLI.setUnavailable(LibFunc_logf);
TLI.setUnavailable(LibFunc_modff);
Expand Down Expand Up @@ -334,6 +335,7 @@ static void initializeLibCalls(TargetLibraryInfoImpl &TLI, const Triple &T,
TLI.setUnavailable(LibFunc_frexpl);
TLI.setUnavailable(LibFunc_hypotl);
TLI.setUnavailable(LibFunc_ldexpl);
TLI.setUnavailable(LibFunc_lgammal);
Copy link
Contributor

Choose a reason for hiding this comment

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

As a pre-commit can you add new baseline TLI checker tests for the windows and linux cases? This is untested, and this is a problem in every one of these new libcall patches.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here is the PR: #114556

TLI.setUnavailable(LibFunc_log10l);
TLI.setUnavailable(LibFunc_logl);
TLI.setUnavailable(LibFunc_modfl);
Expand Down
3 changes: 3 additions & 0 deletions llvm/lib/Transforms/Utils/BuildLibCalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1221,6 +1221,9 @@ bool llvm::inferNonMandatoryLibFuncAttrs(Function &F,
case LibFunc_isascii:
case LibFunc_isdigit:
case LibFunc_labs:
case LibFunc_lgamma:
case LibFunc_lgammaf:
case LibFunc_lgammal:
case LibFunc_llabs:
case LibFunc_log:
case LibFunc_log10:
Expand Down
9 changes: 9 additions & 0 deletions llvm/test/Transforms/InferFunctionAttrs/annotate.ll
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,15 @@ declare float @ldexpf(float, i32)
; CHECK: declare x86_fp80 @ldexpl(x86_fp80, i32) [[NOFREE_WILLRETURN]]
declare x86_fp80 @ldexpl(x86_fp80, i32)

; CHECK: declare double @lgamma(double) [[NOFREE_NOUNWIND_WILLRETURN_WRITEONLY]]
declare double @lgamma(double)

; CHECK: declare float @lgammaf(float) [[NOFREE_NOUNWIND_WILLRETURN_WRITEONLY]]
declare float @lgammaf(float)

; CHECK: declare x86_fp80 @lgammal(x86_fp80) [[NOFREE_NOUNWIND_WILLRETURN_WRITEONLY]]
declare x86_fp80 @lgammal(x86_fp80)

; CHECK: declare i64 @llabs(i64) [[NOFREE_NOUNWIND_WILLRETURN_WRITEONLY]]
declare i64 @llabs(i64)

Expand Down
20 changes: 16 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: 274
#
# 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: 273
#
## 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 522 symbols, 289 available
# AVAIL-COUNT-289: {{^}} available
# AVAIL: TLI knows 525 symbols, 292 available
# AVAIL-COUNT-292: {{^}} available
# AVAIL-NOT: {{^}} available
# UNAVAIL-COUNT-233: not available
# UNAVAIL-NOT: not available
Expand Down Expand Up @@ -634,6 +634,18 @@ DynamicSymbols:
Type: STT_FUNC
Section: .text
Binding: STB_GLOBAL
- Name: lgamma
Type: STT_FUNC
Section: .text
Binding: STB_GLOBAL
- Name: lgammaf
Type: STT_FUNC
Section: .text
Binding: STB_GLOBAL
- Name: lgammal
Type: STT_FUNC
Section: .text
Binding: STB_GLOBAL
- Name: llabs
Type: STT_FUNC
Section: .text
Expand Down
3 changes: 3 additions & 0 deletions llvm/unittests/Analysis/TargetLibraryInfoTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,9 @@ TEST_F(TargetLibraryInfoTest, ValidProto) {
"declare i32 @ilogb(double)\n"
"declare i32 @ilogbf(float)\n"
"declare i32 @ilogbl(x86_fp80)\n"
"declare double @lgamma(double)\n"
"declare float @lgammaf(float)\n"
"declare x86_fp80 @lgammal(x86_fp80)\n"
"declare double @logb(double)\n"
"declare float @logbf(float)\n"
"declare x86_fp80 @logbl(x86_fp80)\n"
Expand Down
Loading