Skip to content

Commit 7db20b1

Browse files
committed
[TLI] Add support for hypot libcall.
1 parent 9d88543 commit 7db20b1

File tree

6 files changed

+48
-4
lines changed

6 files changed

+48
-4
lines changed

llvm/include/llvm/Analysis/TargetLibraryInfo.def

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1656,6 +1656,21 @@ TLI_DEFINE_ENUM_INTERNAL(htons)
16561656
TLI_DEFINE_STRING_INTERNAL("htons")
16571657
TLI_DEFINE_SIG_INTERNAL(Int16, Int16)
16581658

1659+
/// double hypot(double x, double y);
1660+
TLI_DEFINE_ENUM_INTERNAL(hypot)
1661+
TLI_DEFINE_STRING_INTERNAL("hypot")
1662+
TLI_DEFINE_SIG_INTERNAL(Dbl, Dbl, Dbl)
1663+
1664+
/// float hypotf(float x, float y);
1665+
TLI_DEFINE_ENUM_INTERNAL(hypotf)
1666+
TLI_DEFINE_STRING_INTERNAL("hypotf")
1667+
TLI_DEFINE_SIG_INTERNAL(Flt, Flt, Flt)
1668+
1669+
/// long double hypotl(long double x, long double y);
1670+
TLI_DEFINE_ENUM_INTERNAL(hypotl)
1671+
TLI_DEFINE_STRING_INTERNAL("hypotl")
1672+
TLI_DEFINE_SIG_INTERNAL(LDbl, LDbl, LDbl)
1673+
16591674
/// int iprintf(const char *format, ...);
16601675
TLI_DEFINE_ENUM_INTERNAL(iprintf)
16611676
TLI_DEFINE_STRING_INTERNAL("iprintf")

llvm/lib/Analysis/TargetLibraryInfo.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ static void initializeLibCalls(TargetLibraryInfoImpl &TLI, const Triple &T,
300300
TLI.setUnavailable(LibFunc_expf);
301301
TLI.setUnavailable(LibFunc_floorf);
302302
TLI.setUnavailable(LibFunc_fmodf);
303+
TLI.setUnavailable(LibFunc_hypotf);
303304
TLI.setUnavailable(LibFunc_log10f);
304305
TLI.setUnavailable(LibFunc_logf);
305306
TLI.setUnavailable(LibFunc_modff);
@@ -331,6 +332,7 @@ static void initializeLibCalls(TargetLibraryInfoImpl &TLI, const Triple &T,
331332
TLI.setUnavailable(LibFunc_floorl);
332333
TLI.setUnavailable(LibFunc_fmodl);
333334
TLI.setUnavailable(LibFunc_frexpl);
335+
TLI.setUnavailable(LibFunc_hypotl);
334336
TLI.setUnavailable(LibFunc_ldexpl);
335337
TLI.setUnavailable(LibFunc_log10l);
336338
TLI.setUnavailable(LibFunc_logl);

llvm/lib/Transforms/Utils/BuildLibCalls.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,6 +1212,9 @@ bool llvm::inferNonMandatoryLibFuncAttrs(Function &F,
12121212
case LibFunc_fmod:
12131213
case LibFunc_fmodf:
12141214
case LibFunc_fmodl:
1215+
case LibFunc_hypot:
1216+
case LibFunc_hypotf:
1217+
case LibFunc_hypotl:
12151218
case LibFunc_isascii:
12161219
case LibFunc_isdigit:
12171220
case LibFunc_labs:

llvm/test/Transforms/InferFunctionAttrs/annotate.ll

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,15 @@ declare ptr @gets(ptr)
589589
; CHECK: declare noundef i32 @gettimeofday(ptr nocapture noundef, ptr nocapture noundef) [[NOFREE_NOUNWIND]]
590590
declare i32 @gettimeofday(ptr, ptr)
591591

592+
; CHECK: declare double @hypot(double, double) [[NOFREE_NOUNWIND_WILLRETURN_WRITEONLY]]
593+
declare double @hypot(double, double)
594+
595+
; CHECK: declare float @hypotf(float, float) [[NOFREE_NOUNWIND_WILLRETURN_WRITEONLY]]
596+
declare float @hypotf(float, float)
597+
598+
; CHECK: declare x86_fp80 @hypotl(x86_fp80, x86_fp80) [[NOFREE_NOUNWIND_WILLRETURN_WRITEONLY]]
599+
declare x86_fp80 @hypotl(x86_fp80, x86_fp80)
600+
592601
; CHECK: declare i32 @isascii(i32) [[NOFREE_NOUNWIND_WILLRETURN_WRITEONLY]]
593602
declare i32 @isascii(i32)
594603

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

Lines changed: 16 additions & 4 deletions
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: 265
37+
# CHECK: == Total TLI yes SDK yes: 268
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: 264
51+
# WRONG_SUMMARY: == Total TLI yes SDK yes: 267
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 516 symbols, 283 available
58-
# AVAIL-COUNT-283: {{^}} available
57+
# AVAIL: TLI knows 519 symbols, 286 available
58+
# AVAIL-COUNT-286: {{^}} available
5959
# AVAIL-NOT: {{^}} available
6060
# UNAVAIL-COUNT-233: not available
6161
# UNAVAIL-NOT: not available
@@ -590,6 +590,18 @@ DynamicSymbols:
590590
Type: STT_FUNC
591591
Section: .text
592592
Binding: STB_GLOBAL
593+
- Name: hypot
594+
Type: STT_FUNC
595+
Section: .text
596+
Binding: STB_GLOBAL
597+
- Name: hypotf
598+
Type: STT_FUNC
599+
Section: .text
600+
Binding: STB_GLOBAL
601+
- Name: hypotl
602+
Type: STT_FUNC
603+
Section: .text
604+
Binding: STB_GLOBAL
593605
- Name: isdigit
594606
Type: STT_FUNC
595607
Section: .text

llvm/unittests/Analysis/TargetLibraryInfoTest.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,9 @@ TEST_F(TargetLibraryInfoTest, ValidProto) {
249249
"declare %struct* @getpwnam(i8*)\n"
250250
"declare i8* @gets(i8*)\n"
251251
"declare i32 @gettimeofday(%struct*, i8*)\n"
252+
"declare double @hypot(double, double)\n"
253+
"declare float @hypotf(float, float)\n"
254+
"declare x86_fp80 @hypotl(x86_fp80, x86_fp80)\n"
252255
"declare i32 @_Z7isasciii(i32)\n"
253256
"declare i32 @_Z7isdigiti(i32)\n"
254257
"declare i64 @labs(i64)\n"

0 commit comments

Comments
 (0)