Skip to content

Commit 43c9203

Browse files
authored
[TLI] Support inferring function attributes for sincos[f|l] (#108554)
1 parent 112aac4 commit 43c9203

File tree

5 files changed

+55
-4
lines changed

5 files changed

+55
-4
lines changed

llvm/include/llvm/Analysis/TargetLibraryInfo.def

+15
Original file line numberDiff line numberDiff line change
@@ -2183,6 +2183,21 @@ TLI_DEFINE_ENUM_INTERNAL(sinl)
21832183
TLI_DEFINE_STRING_INTERNAL("sinl")
21842184
TLI_DEFINE_SIG_INTERNAL(LDbl, LDbl)
21852185

2186+
/// void sincos(double x, double *sin_out, double *cos_out);
2187+
TLI_DEFINE_ENUM_INTERNAL(sincos)
2188+
TLI_DEFINE_STRING_INTERNAL("sincos")
2189+
TLI_DEFINE_SIG_INTERNAL(Void, Dbl, Ptr, Ptr)
2190+
2191+
/// void sincosf(float x, float *sin_out, float *cos_out);
2192+
TLI_DEFINE_ENUM_INTERNAL(sincosf)
2193+
TLI_DEFINE_STRING_INTERNAL("sincosf")
2194+
TLI_DEFINE_SIG_INTERNAL(Void, Flt, Ptr, Ptr)
2195+
2196+
/// void sincosl(long double x, long double *sin_out, long double *cos_out);
2197+
TLI_DEFINE_ENUM_INTERNAL(sincosl)
2198+
TLI_DEFINE_STRING_INTERNAL("sincosl")
2199+
TLI_DEFINE_SIG_INTERNAL(Void, LDbl, Ptr, Ptr)
2200+
21862201
/// int siprintf(char *str, const char *format, ...);
21872202
TLI_DEFINE_ENUM_INTERNAL(siprintf)
21882203
TLI_DEFINE_STRING_INTERNAL("siprintf")

llvm/lib/Transforms/Utils/BuildLibCalls.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -1270,6 +1270,18 @@ bool llvm::inferNonMandatoryLibFuncAttrs(Function &F,
12701270
Changed |= setOnlyWritesMemory(F);
12711271
Changed |= setWillReturn(F);
12721272
break;
1273+
case LibFunc_sincos:
1274+
case LibFunc_sincosf:
1275+
case LibFunc_sincosl:
1276+
Changed |= setDoesNotThrow(F);
1277+
Changed |= setDoesNotFreeMemory(F);
1278+
Changed |= setOnlyWritesMemory(F);
1279+
Changed |= setOnlyWritesMemory(F, 1);
1280+
Changed |= setOnlyWritesMemory(F, 2);
1281+
Changed |= setDoesNotCapture(F, 1);
1282+
Changed |= setDoesNotCapture(F, 2);
1283+
Changed |= setWillReturn(F);
1284+
break;
12731285
default:
12741286
// FIXME: It'd be really nice to cover all the library functions we're
12751287
// aware of here.

llvm/test/Transforms/InferFunctionAttrs/annotate.ll

+9
Original file line numberDiff line numberDiff line change
@@ -1106,6 +1106,15 @@ declare void @__cxa_throw(ptr, ptr, ptr)
11061106
; CHECK: declare void @_ZSt9terminatev() [[NOFREE_COLD_NORETURN:#[0-9]+]]
11071107
declare void @_ZSt9terminatev()
11081108

1109+
; CHECK: declare void @sincos(double, ptr nocapture writeonly, ptr nocapture writeonly) [[NOFREE_NOUNWIND_WILLRETURN_WRITEONLY]]
1110+
declare void @sincos(double, ptr, ptr)
1111+
1112+
; CHECK: declare void @sincosf(float, ptr nocapture writeonly, ptr nocapture writeonly) [[NOFREE_NOUNWIND_WILLRETURN_WRITEONLY]]
1113+
declare void @sincosf(float, ptr, ptr)
1114+
1115+
; CHECK: declare void @sincosl(x86_fp80, ptr nocapture writeonly, ptr nocapture writeonly) [[NOFREE_NOUNWIND_WILLRETURN_WRITEONLY]]
1116+
declare void @sincosl(x86_fp80, ptr, ptr)
1117+
11091118
; memset_pattern{4,8,16} aren't available everywhere.
11101119
; CHECK-DARWIN: declare void @memset_pattern4(ptr nocapture writeonly, ptr nocapture readonly, i64) [[ARGMEMONLY_NOFREE_NOUNWIND_WILLRETURN]]
11111120
declare void @memset_pattern4(ptr, ptr, i64)

llvm/test/tools/llvm-tli-checker/ps4-tli-check.yaml

+16-4
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
#
3535
# CHECK: << Total TLI yes SDK no: 18
3636
# CHECK: >> Total TLI no SDK yes: 0
37-
# CHECK: == Total TLI yes SDK yes: 250
37+
# CHECK: == Total TLI yes SDK yes: 253
3838
#
3939
# WRONG_DETAIL: << TLI yes SDK no : '_ZdaPv' aka operator delete[](void*)
4040
# WRONG_DETAIL: >> TLI no SDK yes: '_ZdaPvj' aka operator delete[](void*, unsigned int)
@@ -48,14 +48,14 @@
4848
# WRONG_DETAIL: << TLI yes SDK no : 'fminimum_numl'
4949
# WRONG_SUMMARY: << Total TLI yes SDK no: 19{{$}}
5050
# WRONG_SUMMARY: >> Total TLI no SDK yes: 1{{$}}
51-
# WRONG_SUMMARY: == Total TLI yes SDK yes: 249
51+
# WRONG_SUMMARY: == Total TLI yes SDK yes: 252
5252
#
5353
## The -COUNT suffix doesn't care if there are too many matches, so check
5454
## the exact count first; the two directives should add up to that.
5555
## Yes, this means additions to TLI will fail this test, but the argument
5656
## to -COUNT can't be an expression.
57-
# AVAIL: TLI knows 501 symbols, 268 available
58-
# AVAIL-COUNT-268: {{^}} available
57+
# AVAIL: TLI knows 504 symbols, 271 available
58+
# AVAIL-COUNT-271: {{^}} available
5959
# AVAIL-NOT: {{^}} available
6060
# UNAVAIL-COUNT-233: not available
6161
# UNAVAIL-NOT: not available
@@ -862,6 +862,18 @@ DynamicSymbols:
862862
Type: STT_FUNC
863863
Section: .text
864864
Binding: STB_GLOBAL
865+
- Name: sincos
866+
Type: STT_FUNC
867+
Section: .text
868+
Binding: STB_GLOBAL
869+
- Name: sincosf
870+
Type: STT_FUNC
871+
Section: .text
872+
Binding: STB_GLOBAL
873+
- Name: sincosl
874+
Type: STT_FUNC
875+
Section: .text
876+
Binding: STB_GLOBAL
865877
- Name: sinh
866878
Type: STT_FUNC
867879
Section: .text

llvm/unittests/Analysis/TargetLibraryInfoTest.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,9 @@ TEST_F(TargetLibraryInfoTest, ValidProto) {
339339
"declare float @sinhf(float)\n"
340340
"declare x86_fp80 @sinhl(x86_fp80)\n"
341341
"declare x86_fp80 @sinl(x86_fp80)\n"
342+
"declare void @sincos(double, ptr, ptr)\n"
343+
"declare void @sincosf(float, ptr, ptr)\n"
344+
"declare void @sincosl(x86_fp80, ptr, ptr)\n"
342345
"declare i32 @snprintf(i8*, i64, i8*, ...)\n"
343346
"declare i32 @sprintf(i8*, i8*, ...)\n"
344347
"declare double @sqrt(double)\n"

0 commit comments

Comments
 (0)