Skip to content

Commit

Permalink
[TLI] Add basic support for remquo libcall (#99611)
Browse files Browse the repository at this point in the history
This patch adds basic support for `remquo`. Constant folding support
will be submitted in a subsequent patch.

Related issue: #99497
  • Loading branch information
dtcxzyw authored Jul 19, 2024
1 parent 270f5e4 commit e8fbefe
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 4 deletions.
15 changes: 15 additions & 0 deletions llvm/include/llvm/Analysis/TargetLibraryInfo.def
Original file line number Diff line number Diff line change
Expand Up @@ -1953,6 +1953,21 @@ TLI_DEFINE_ENUM_INTERNAL(remainderl)
TLI_DEFINE_STRING_INTERNAL("remainderl")
TLI_DEFINE_SIG_INTERNAL(LDbl, LDbl, LDbl)

/// double remquo(double x, double y, int *quo);
TLI_DEFINE_ENUM_INTERNAL(remquo)
TLI_DEFINE_STRING_INTERNAL("remquo")
TLI_DEFINE_SIG_INTERNAL(Dbl, Dbl, Dbl, Ptr)

/// float remquof(float x, float y, int *quo);
TLI_DEFINE_ENUM_INTERNAL(remquof)
TLI_DEFINE_STRING_INTERNAL("remquof")
TLI_DEFINE_SIG_INTERNAL(Flt, Flt, Flt, Ptr)

/// long double remquol(long double x, long double y, int *quo);
TLI_DEFINE_ENUM_INTERNAL(remquol)
TLI_DEFINE_STRING_INTERNAL("remquol")
TLI_DEFINE_SIG_INTERNAL(LDbl, LDbl, LDbl, Ptr)

/// int remove(const char *path);
TLI_DEFINE_ENUM_INTERNAL(remove)
TLI_DEFINE_STRING_INTERNAL("remove")
Expand Down
2 changes: 2 additions & 0 deletions llvm/lib/Analysis/TargetLibraryInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ static void initializeLibCalls(TargetLibraryInfoImpl &TLI, const Triple &T,
TLI.setUnavailable(LibFunc_modff);
TLI.setUnavailable(LibFunc_powf);
TLI.setUnavailable(LibFunc_remainderf);
TLI.setUnavailable(LibFunc_remquof);
TLI.setUnavailable(LibFunc_sinf);
TLI.setUnavailable(LibFunc_sinhf);
TLI.setUnavailable(LibFunc_sqrtf);
Expand Down Expand Up @@ -335,6 +336,7 @@ static void initializeLibCalls(TargetLibraryInfoImpl &TLI, const Triple &T,
TLI.setUnavailable(LibFunc_modfl);
TLI.setUnavailable(LibFunc_powl);
TLI.setUnavailable(LibFunc_remainderl);
TLI.setUnavailable(LibFunc_remquol);
TLI.setUnavailable(LibFunc_sinl);
TLI.setUnavailable(LibFunc_sinhl);
TLI.setUnavailable(LibFunc_sqrtl);
Expand Down
5 changes: 5 additions & 0 deletions llvm/lib/Transforms/Utils/BuildLibCalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1098,6 +1098,11 @@ bool llvm::inferNonMandatoryLibFuncAttrs(Function &F,
case LibFunc_ldexpl:
Changed |= setWillReturn(F);
break;
case LibFunc_remquo:
case LibFunc_remquof:
case LibFunc_remquol:
Changed |= setDoesNotCapture(F, 2);
[[fallthrough]];
case LibFunc_abs:
case LibFunc_acos:
case LibFunc_acosf:
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 @@ -812,6 +812,15 @@ declare x86_fp80 @remainderl(x86_fp80, x86_fp80)
; CHECK: declare noundef i32 @remove(ptr nocapture noundef readonly) [[NOFREE_NOUNWIND]]
declare i32 @remove(ptr)

; CHECK: declare double @remquo(double, double, ptr nocapture) [[NOFREE_NOUNWIND_WILLRETURN_WRITEONLY]]
declare double @remquo(double, double, ptr)

; CHECK: declare float @remquof(float, float, ptr nocapture) [[NOFREE_NOUNWIND_WILLRETURN_WRITEONLY]]
declare float @remquof(float, float, ptr)

; CHECK: declare x86_fp80 @remquol(x86_fp80, x86_fp80, ptr nocapture) [[NOFREE_NOUNWIND_WILLRETURN_WRITEONLY]]
declare x86_fp80 @remquol(x86_fp80, x86_fp80, ptr)

; CHECK: declare noundef i32 @rename(ptr nocapture noundef readonly, ptr nocapture noundef readonly) [[NOFREE_NOUNWIND]]
declare i32 @rename(ptr, ptr)

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,21 +34,21 @@
#
# CHECK: << Total TLI yes SDK no: 8
# CHECK: >> Total TLI no SDK yes: 0
# CHECK: == Total TLI yes SDK yes: 239
# CHECK: == Total TLI yes SDK yes: 242
#
# WRONG_DETAIL: << TLI yes SDK no : '_ZdaPv' aka operator delete[](void*)
# WRONG_DETAIL: >> TLI no SDK yes: '_ZdaPvj' aka operator delete[](void*, unsigned int)
# WRONG_DETAIL-COUNT-8: << TLI yes SDK no : {{.*}}__hot_cold_t
# WRONG_SUMMARY: << Total TLI yes SDK no: 9{{$}}
# WRONG_SUMMARY: >> Total TLI no SDK yes: 1{{$}}
# WRONG_SUMMARY: == Total TLI yes SDK yes: 238
# WRONG_SUMMARY: == Total TLI yes SDK yes: 241
#
## 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 480 symbols, 247 available
# AVAIL-COUNT-247: {{^}} available
# AVAIL: TLI knows 483 symbols, 250 available
# AVAIL-COUNT-250: {{^}} available
# AVAIL-NOT: {{^}} available
# UNAVAIL-COUNT-233: not available
# UNAVAIL-NOT: not available
Expand Down Expand Up @@ -763,6 +763,18 @@ DynamicSymbols:
Type: STT_FUNC
Section: .text
Binding: STB_GLOBAL
- Name: remquo
Type: STT_FUNC
Section: .text
Binding: STB_GLOBAL
- Name: remquof
Type: STT_FUNC
Section: .text
Binding: STB_GLOBAL
- Name: remquol
Type: STT_FUNC
Section: .text
Binding: STB_GLOBAL
- Name: rewind
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 @@ -281,6 +281,9 @@ TEST_F(TargetLibraryInfoTest, ValidProto) {
"declare float @remainderf(float, float)\n"
"declare x86_fp80 @remainderl(x86_fp80, x86_fp80)\n"
"declare i32 @remove(i8*)\n"
"declare double @remquo(double, double, ptr)\n"
"declare float @remquof(float, float, ptr)\n"
"declare x86_fp80 @remquol(x86_fp80, x86_fp80, ptr)\n"
"declare i32 @rename(i8*, i8*)\n"
"declare void @rewind(%struct*)\n"
"declare double @rint(double)\n"
Expand Down

0 comments on commit e8fbefe

Please sign in to comment.