Skip to content
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

[TLI] Support inferring function attributes for sincos[f|l] #108554

Merged
merged 1 commit into from
Sep 18, 2024
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
15 changes: 15 additions & 0 deletions llvm/include/llvm/Analysis/TargetLibraryInfo.def
Original file line number Diff line number Diff line change
Expand Up @@ -2183,6 +2183,21 @@ TLI_DEFINE_ENUM_INTERNAL(sinl)
TLI_DEFINE_STRING_INTERNAL("sinl")
TLI_DEFINE_SIG_INTERNAL(LDbl, LDbl)

/// void sincos(double x, double *sin_out, double *cos_out);
TLI_DEFINE_ENUM_INTERNAL(sincos)
TLI_DEFINE_STRING_INTERNAL("sincos")
TLI_DEFINE_SIG_INTERNAL(Void, Dbl, Ptr, Ptr)

/// void sincosf(float x, float *sin_out, float *cos_out);
TLI_DEFINE_ENUM_INTERNAL(sincosf)
TLI_DEFINE_STRING_INTERNAL("sincosf")
TLI_DEFINE_SIG_INTERNAL(Void, Flt, Ptr, Ptr)

/// void sincosl(long double x, long double *sin_out, long double *cos_out);
TLI_DEFINE_ENUM_INTERNAL(sincosl)
TLI_DEFINE_STRING_INTERNAL("sincosl")
TLI_DEFINE_SIG_INTERNAL(Void, LDbl, Ptr, Ptr)

/// int siprintf(char *str, const char *format, ...);
TLI_DEFINE_ENUM_INTERNAL(siprintf)
TLI_DEFINE_STRING_INTERNAL("siprintf")
Expand Down
12 changes: 12 additions & 0 deletions llvm/lib/Transforms/Utils/BuildLibCalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1270,6 +1270,18 @@ bool llvm::inferNonMandatoryLibFuncAttrs(Function &F,
Changed |= setOnlyWritesMemory(F);
Changed |= setWillReturn(F);
break;
case LibFunc_sincos:
case LibFunc_sincosf:
case LibFunc_sincosl:
Changed |= setDoesNotThrow(F);
Changed |= setDoesNotFreeMemory(F);
Changed |= setOnlyWritesMemory(F);
Changed |= setOnlyWritesMemory(F, 1);
Changed |= setOnlyWritesMemory(F, 2);
Changed |= setDoesNotCapture(F, 1);
Changed |= setDoesNotCapture(F, 2);
Changed |= setWillReturn(F);
arsenm marked this conversation as resolved.
Show resolved Hide resolved
break;
default:
// FIXME: It'd be really nice to cover all the library functions we're
// aware of here.
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 @@ -1106,6 +1106,15 @@ declare void @__cxa_throw(ptr, ptr, ptr)
; CHECK: declare void @_ZSt9terminatev() [[NOFREE_COLD_NORETURN:#[0-9]+]]
declare void @_ZSt9terminatev()

; CHECK: declare void @sincos(double, ptr nocapture writeonly, ptr nocapture writeonly) [[NOFREE_NOUNWIND_WILLRETURN_WRITEONLY]]
declare void @sincos(double, ptr, ptr)

; CHECK: declare void @sincosf(float, ptr nocapture writeonly, ptr nocapture writeonly) [[NOFREE_NOUNWIND_WILLRETURN_WRITEONLY]]
declare void @sincosf(float, ptr, ptr)

; CHECK: declare void @sincosl(x86_fp80, ptr nocapture writeonly, ptr nocapture writeonly) [[NOFREE_NOUNWIND_WILLRETURN_WRITEONLY]]
declare void @sincosl(x86_fp80, ptr, ptr)

; memset_pattern{4,8,16} aren't available everywhere.
; CHECK-DARWIN: declare void @memset_pattern4(ptr nocapture writeonly, ptr nocapture readonly, i64) [[ARGMEMONLY_NOFREE_NOUNWIND_WILLRETURN]]
declare void @memset_pattern4(ptr, ptr, 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: 250
# CHECK: == Total TLI yes SDK yes: 253
#
# 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: 249
# WRONG_SUMMARY: == Total TLI yes SDK yes: 252
#
## 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 501 symbols, 268 available
# AVAIL-COUNT-268: {{^}} available
# AVAIL: TLI knows 504 symbols, 271 available
# AVAIL-COUNT-271: {{^}} available
# AVAIL-NOT: {{^}} available
# UNAVAIL-COUNT-233: not available
# UNAVAIL-NOT: not available
Expand Down Expand Up @@ -862,6 +862,18 @@ DynamicSymbols:
Type: STT_FUNC
Section: .text
Binding: STB_GLOBAL
- Name: sincos
Type: STT_FUNC
Section: .text
Binding: STB_GLOBAL
- Name: sincosf
Type: STT_FUNC
Section: .text
Binding: STB_GLOBAL
- Name: sincosl
Type: STT_FUNC
Section: .text
Binding: STB_GLOBAL
- Name: sinh
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 @@ -339,6 +339,9 @@ TEST_F(TargetLibraryInfoTest, ValidProto) {
"declare float @sinhf(float)\n"
"declare x86_fp80 @sinhl(x86_fp80)\n"
"declare x86_fp80 @sinl(x86_fp80)\n"
"declare void @sincos(double, ptr, ptr)\n"
"declare void @sincosf(float, ptr, ptr)\n"
"declare void @sincosl(x86_fp80, ptr, ptr)\n"
"declare i32 @snprintf(i8*, i64, i8*, ...)\n"
"declare i32 @sprintf(i8*, i8*, ...)\n"
"declare double @sqrt(double)\n"
Expand Down
Loading