Skip to content

Commit 173841c

Browse files
authored
[TLI] Add basic support for fdim libcall (#108702)
first PR to fix #108695 Signed-off-by: Kushal Pal <[email protected]>
1 parent 5e78108 commit 173841c

File tree

6 files changed

+45
-0
lines changed

6 files changed

+45
-0
lines changed

llvm/include/llvm/Analysis/TargetLibraryInfo.def

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2067,6 +2067,21 @@ TLI_DEFINE_ENUM_INTERNAL(remquol)
20672067
TLI_DEFINE_STRING_INTERNAL("remquol")
20682068
TLI_DEFINE_SIG_INTERNAL(LDbl, LDbl, LDbl, Ptr)
20692069

2070+
/// double fdim(double x, double y);
2071+
TLI_DEFINE_ENUM_INTERNAL(fdim)
2072+
TLI_DEFINE_STRING_INTERNAL("fdim")
2073+
TLI_DEFINE_SIG_INTERNAL(Dbl, Dbl, Dbl)
2074+
2075+
/// float fdimf(float x, float y);
2076+
TLI_DEFINE_ENUM_INTERNAL(fdimf)
2077+
TLI_DEFINE_STRING_INTERNAL("fdimf")
2078+
TLI_DEFINE_SIG_INTERNAL(Flt, Flt, Flt)
2079+
2080+
/// long double fdiml(long double x, long double y);
2081+
TLI_DEFINE_ENUM_INTERNAL(fdiml)
2082+
TLI_DEFINE_STRING_INTERNAL("fdiml")
2083+
TLI_DEFINE_SIG_INTERNAL(LDbl, LDbl, LDbl)
2084+
20702085
/// int remove(const char *path);
20712086
TLI_DEFINE_ENUM_INTERNAL(remove)
20722087
TLI_DEFINE_STRING_INTERNAL("remove")

llvm/lib/Analysis/TargetLibraryInfo.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ static void initializeLibCalls(TargetLibraryInfoImpl &TLI, const Triple &T,
306306
TLI.setUnavailable(LibFunc_powf);
307307
TLI.setUnavailable(LibFunc_remainderf);
308308
TLI.setUnavailable(LibFunc_remquof);
309+
TLI.setUnavailable(LibFunc_fdimf);
309310
TLI.setUnavailable(LibFunc_sinf);
310311
TLI.setUnavailable(LibFunc_sinhf);
311312
TLI.setUnavailable(LibFunc_sqrtf);
@@ -337,6 +338,7 @@ static void initializeLibCalls(TargetLibraryInfoImpl &TLI, const Triple &T,
337338
TLI.setUnavailable(LibFunc_powl);
338339
TLI.setUnavailable(LibFunc_remainderl);
339340
TLI.setUnavailable(LibFunc_remquol);
341+
TLI.setUnavailable(LibFunc_fdiml);
340342
TLI.setUnavailable(LibFunc_sinl);
341343
TLI.setUnavailable(LibFunc_sinhl);
342344
TLI.setUnavailable(LibFunc_sqrtl);

llvm/lib/Transforms/Utils/BuildLibCalls.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,6 +1191,9 @@ bool llvm::inferNonMandatoryLibFuncAttrs(Function &F,
11911191
case LibFunc_fabs:
11921192
case LibFunc_fabsf:
11931193
case LibFunc_fabsl:
1194+
case LibFunc_fdim:
1195+
case LibFunc_fdiml:
1196+
case LibFunc_fdimf:
11941197
case LibFunc_ffs:
11951198
case LibFunc_ffsl:
11961199
case LibFunc_ffsll:

llvm/test/Transforms/InferFunctionAttrs/annotate.ll

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,16 @@ declare float @remquof(float, float, ptr)
830830
; CHECK: declare x86_fp80 @remquol(x86_fp80, x86_fp80, ptr nocapture) [[NOFREE_NOUNWIND_WILLRETURN_WRITEONLY]]
831831
declare x86_fp80 @remquol(x86_fp80, x86_fp80, ptr)
832832

833+
834+
; CHECK: declare double @fdim(double, double) [[NOFREE_NOUNWIND_WILLRETURN_WRITEONLY]]
835+
declare double @fdim(double, double)
836+
837+
; CHECK: declare float @fdimf(float, float) [[NOFREE_NOUNWIND_WILLRETURN_WRITEONLY]]
838+
declare float @fdimf(float, float)
839+
840+
; CHECK: declare x86_fp80 @fdiml(x86_fp80, x86_fp80) [[NOFREE_NOUNWIND_WILLRETURN_WRITEONLY]]
841+
declare x86_fp80 @fdiml(x86_fp80, x86_fp80)
842+
833843
; CHECK: declare noundef i32 @rename(ptr nocapture noundef readonly, ptr nocapture noundef readonly) [[NOFREE_NOUNWIND]]
834844
declare i32 @rename(ptr, ptr)
835845

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,18 @@ DynamicSymbols:
814814
Type: STT_FUNC
815815
Section: .text
816816
Binding: STB_GLOBAL
817+
- Name: fdim
818+
Type: STT_FUNC
819+
Section: .text
820+
Binding: STB_GLOBAL
821+
- Name: fdimf
822+
Type: STT_FUNC
823+
Section: .text
824+
Binding: STB_GLOBAL
825+
- Name: fdiml
826+
Type: STT_FUNC
827+
Section: .text
828+
Binding: STB_GLOBAL
817829
- Name: rewind
818830
Type: STT_FUNC
819831
Section: .text

llvm/unittests/Analysis/TargetLibraryInfoTest.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,9 @@ TEST_F(TargetLibraryInfoTest, ValidProto) {
317317
"declare double @remquo(double, double, ptr)\n"
318318
"declare float @remquof(float, float, ptr)\n"
319319
"declare x86_fp80 @remquol(x86_fp80, x86_fp80, ptr)\n"
320+
"declare double @fdim(double, double)\n"
321+
"declare float @fdimf(float, float)\n"
322+
"declare x86_fp80 @fdiml(x86_fp80, x86_fp80)\n"
320323
"declare i32 @rename(i8*, i8*)\n"
321324
"declare void @rewind(%struct*)\n"
322325
"declare double @rint(double)\n"

0 commit comments

Comments
 (0)