Skip to content

Commit feb2d86

Browse files
authored
[TLI] Add support for hypot libcall. (#113724)
This patch adds basic support for `hypot`. Constant folding support will be submitted in a subsequent patch. Related issue: #113711 Note: It's my first time contributing to the LLVM with encouragement from one of my friends, @fawdlstty. I learned a lot from #99611, and thanks for that. Kenji Mouri
1 parent b94762d commit feb2d86

File tree

6 files changed

+44
-0
lines changed

6 files changed

+44
-0
lines changed

llvm/include/llvm/Analysis/TargetLibraryInfo.def

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1671,6 +1671,21 @@ TLI_DEFINE_ENUM_INTERNAL(htons)
16711671
TLI_DEFINE_STRING_INTERNAL("htons")
16721672
TLI_DEFINE_SIG_INTERNAL(Int16, Int16)
16731673

1674+
/// double hypot(double x, double y);
1675+
TLI_DEFINE_ENUM_INTERNAL(hypot)
1676+
TLI_DEFINE_STRING_INTERNAL("hypot")
1677+
TLI_DEFINE_SIG_INTERNAL(Dbl, Dbl, Dbl)
1678+
1679+
/// float hypotf(float x, float y);
1680+
TLI_DEFINE_ENUM_INTERNAL(hypotf)
1681+
TLI_DEFINE_STRING_INTERNAL("hypotf")
1682+
TLI_DEFINE_SIG_INTERNAL(Flt, Flt, Flt)
1683+
1684+
/// long double hypotl(long double x, long double y);
1685+
TLI_DEFINE_ENUM_INTERNAL(hypotl)
1686+
TLI_DEFINE_STRING_INTERNAL("hypotl")
1687+
TLI_DEFINE_SIG_INTERNAL(LDbl, LDbl, LDbl)
1688+
16741689
/// int iprintf(const char *format, ...);
16751690
TLI_DEFINE_ENUM_INTERNAL(iprintf)
16761691
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
@@ -1215,6 +1215,9 @@ bool llvm::inferNonMandatoryLibFuncAttrs(Function &F,
12151215
case LibFunc_fmod:
12161216
case LibFunc_fmodf:
12171217
case LibFunc_fmodl:
1218+
case LibFunc_hypot:
1219+
case LibFunc_hypotf:
1220+
case LibFunc_hypotl:
12181221
case LibFunc_isascii:
12191222
case LibFunc_isdigit:
12201223
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: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,18 @@ DynamicSymbols:
602602
Type: STT_FUNC
603603
Section: .text
604604
Binding: STB_GLOBAL
605+
- Name: hypot
606+
Type: STT_FUNC
607+
Section: .text
608+
Binding: STB_GLOBAL
609+
- Name: hypotf
610+
Type: STT_FUNC
611+
Section: .text
612+
Binding: STB_GLOBAL
613+
- Name: hypotl
614+
Type: STT_FUNC
615+
Section: .text
616+
Binding: STB_GLOBAL
605617
- Name: isdigit
606618
Type: STT_FUNC
607619
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)