Skip to content

Commit 20bda93

Browse files
authored
[TLI] Add basic support for scalbnxx (#112936)
This patch adds basic support for `scalbln, scalblnf, scalblnl, scalbn, scalbnf, scalbnl`. Constant folding support will be submitted in a subsequent patch. Related issue: <#112631>
1 parent c2717a8 commit 20bda93

File tree

6 files changed

+96
-4
lines changed

6 files changed

+96
-4
lines changed

llvm/include/llvm/Analysis/TargetLibraryInfo.def

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2162,6 +2162,36 @@ TLI_DEFINE_ENUM_INTERNAL(roundl)
21622162
TLI_DEFINE_STRING_INTERNAL("roundl")
21632163
TLI_DEFINE_SIG_INTERNAL(LDbl, LDbl)
21642164

2165+
/// double scalbln(double arg, long exp);
2166+
TLI_DEFINE_ENUM_INTERNAL(scalbln)
2167+
TLI_DEFINE_STRING_INTERNAL("scalbln")
2168+
TLI_DEFINE_SIG_INTERNAL(Dbl, Dbl, Long)
2169+
2170+
/// float scalblnf(float arg, long exp);
2171+
TLI_DEFINE_ENUM_INTERNAL(scalblnf)
2172+
TLI_DEFINE_STRING_INTERNAL("scalblnf")
2173+
TLI_DEFINE_SIG_INTERNAL(Flt, Flt, Long)
2174+
2175+
/// long double scalblnl(long double arg, long exp);
2176+
TLI_DEFINE_ENUM_INTERNAL(scalblnl)
2177+
TLI_DEFINE_STRING_INTERNAL("scalblnl")
2178+
TLI_DEFINE_SIG_INTERNAL(LDbl, LDbl, Long)
2179+
2180+
/// double scalbn(double arg, int exp);
2181+
TLI_DEFINE_ENUM_INTERNAL(scalbn)
2182+
TLI_DEFINE_STRING_INTERNAL("scalbn")
2183+
TLI_DEFINE_SIG_INTERNAL(Dbl, Dbl, Int)
2184+
2185+
/// float scalbnf(float arg, int exp);
2186+
TLI_DEFINE_ENUM_INTERNAL(scalbnf)
2187+
TLI_DEFINE_STRING_INTERNAL("scalbnf")
2188+
TLI_DEFINE_SIG_INTERNAL(Flt, Flt, Int)
2189+
2190+
/// long double scalbnl(long double arg, int exp);
2191+
TLI_DEFINE_ENUM_INTERNAL(scalbnl)
2192+
TLI_DEFINE_STRING_INTERNAL("scalbnl")
2193+
TLI_DEFINE_SIG_INTERNAL(LDbl, LDbl, Int)
2194+
21652195
/// int scanf(const char *restrict format, ... );
21662196
TLI_DEFINE_ENUM_INTERNAL(scanf)
21672197
TLI_DEFINE_STRING_INTERNAL("scanf")

llvm/lib/Analysis/TargetLibraryInfo.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,12 @@ static void initializeLibCalls(TargetLibraryInfoImpl &TLI, const Triple &T,
382382
TLI.setUnavailable(LibFunc_rintf);
383383
TLI.setUnavailable(LibFunc_round);
384384
TLI.setUnavailable(LibFunc_roundf);
385+
TLI.setUnavailable(LibFunc_scalbln);
386+
TLI.setUnavailable(LibFunc_scalblnf);
387+
TLI.setUnavailable(LibFunc_scalblnl);
388+
TLI.setUnavailable(LibFunc_scalbn);
389+
TLI.setUnavailable(LibFunc_scalbnf);
390+
TLI.setUnavailable(LibFunc_scalbnl);
385391
TLI.setUnavailable(LibFunc_trunc);
386392
TLI.setUnavailable(LibFunc_truncf);
387393
}
@@ -404,6 +410,8 @@ static void initializeLibCalls(TargetLibraryInfoImpl &TLI, const Triple &T,
404410
TLI.setUnavailable(LibFunc_nearbyintl);
405411
TLI.setUnavailable(LibFunc_rintl);
406412
TLI.setUnavailable(LibFunc_roundl);
413+
TLI.setUnavailable(LibFunc_scalblnl);
414+
TLI.setUnavailable(LibFunc_scalbnl);
407415
TLI.setUnavailable(LibFunc_truncl);
408416

409417
// Win32 does not support these functions, but

llvm/lib/Transforms/Utils/BuildLibCalls.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1249,6 +1249,12 @@ bool llvm::inferNonMandatoryLibFuncAttrs(Function &F,
12491249
case LibFunc_round:
12501250
case LibFunc_roundf:
12511251
case LibFunc_roundl:
1252+
case LibFunc_scalbln:
1253+
case LibFunc_scalblnf:
1254+
case LibFunc_scalblnl:
1255+
case LibFunc_scalbn:
1256+
case LibFunc_scalbnf:
1257+
case LibFunc_scalbnl:
12521258
case LibFunc_sin:
12531259
case LibFunc_sincospif_stret:
12541260
case LibFunc_sinf:

llvm/test/Transforms/InferFunctionAttrs/annotate.ll

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,24 @@ declare float @roundf(float)
876876
; CHECK: declare x86_fp80 @roundl(x86_fp80) [[NOFREE_NOUNWIND_WILLRETURN_WRITEONLY]]
877877
declare x86_fp80 @roundl(x86_fp80)
878878

879+
; CHECK: declare double @scalbln(double, i64) [[NOFREE_NOUNWIND_WILLRETURN_WRITEONLY]]
880+
declare double @scalbln(double, i64)
881+
882+
; CHECK: declare float @scalblnf(float, i64) [[NOFREE_NOUNWIND_WILLRETURN_WRITEONLY]]
883+
declare float @scalblnf(float, i64)
884+
885+
; CHECK: declare x86_fp80 @scalblnl(x86_fp80, i64) [[NOFREE_NOUNWIND_WILLRETURN_WRITEONLY]]
886+
declare x86_fp80 @scalblnl(x86_fp80, i64)
887+
888+
; CHECK: declare double @scalbn(double, i32) [[NOFREE_NOUNWIND_WILLRETURN_WRITEONLY]]
889+
declare double @scalbn(double, i32)
890+
891+
; CHECK: declare float @scalbnf(float, i32) [[NOFREE_NOUNWIND_WILLRETURN_WRITEONLY]]
892+
declare float @scalbnf(float, i32)
893+
894+
; CHECK: declare x86_fp80 @scalbnl(x86_fp80, i32) [[NOFREE_NOUNWIND_WILLRETURN_WRITEONLY]]
895+
declare x86_fp80 @scalbnl(x86_fp80, i32)
896+
879897
; CHECK: declare noundef i32 @scanf(ptr nocapture noundef readonly, ...) [[NOFREE_NOUNWIND]]
880898
declare i32 @scanf(ptr, ...)
881899

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

Lines changed: 28 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: 259
37+
# CHECK: == Total TLI yes SDK yes: 265
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: 258
51+
# WRONG_SUMMARY: == Total TLI yes SDK yes: 264
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 510 symbols, 277 available
58-
# AVAIL-COUNT-277: {{^}} available
57+
# AVAIL: TLI knows 516 symbols, 283 available
58+
# AVAIL-COUNT-283: {{^}} available
5959
# AVAIL-NOT: {{^}} available
6060
# UNAVAIL-COUNT-233: not available
6161
# UNAVAIL-NOT: not available
@@ -866,6 +866,30 @@ DynamicSymbols:
866866
Type: STT_FUNC
867867
Section: .text
868868
Binding: STB_GLOBAL
869+
- Name: scalbln
870+
Type: STT_FUNC
871+
Section: .text
872+
Binding: STB_GLOBAL
873+
- Name: scalblnf
874+
Type: STT_FUNC
875+
Section: .text
876+
Binding: STB_GLOBAL
877+
- Name: scalblnl
878+
Type: STT_FUNC
879+
Section: .text
880+
Binding: STB_GLOBAL
881+
- Name: scalbn
882+
Type: STT_FUNC
883+
Section: .text
884+
Binding: STB_GLOBAL
885+
- Name: scalbnf
886+
Type: STT_FUNC
887+
Section: .text
888+
Binding: STB_GLOBAL
889+
- Name: scalbnl
890+
Type: STT_FUNC
891+
Section: .text
892+
Binding: STB_GLOBAL
869893
- Name: scanf
870894
Type: STT_FUNC
871895
Section: .text

llvm/unittests/Analysis/TargetLibraryInfoTest.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,12 @@ TEST_F(TargetLibraryInfoTest, ValidProto) {
335335
"declare double @roundeven(double)\n"
336336
"declare float @roundevenf(float)\n"
337337
"declare x86_fp80 @roundevenl(x86_fp80)\n"
338+
"declare double @scalbln(double, i64)\n"
339+
"declare float @scalblnf(float, i64)\n"
340+
"declare x86_fp80 @scalblnl(x86_fp80, i64)\n"
341+
"declare double @scalbn(double, i32)\n"
342+
"declare float @scalbnf(float, i32)\n"
343+
"declare x86_fp80 @scalbnl(x86_fp80, i32)\n"
338344
"declare i32 @scanf(i8*, ...)\n"
339345
"declare void @setbuf(%struct*, i8*)\n"
340346
"declare i32 @setitimer(i32, %struct*, %struct*)\n"

0 commit comments

Comments
 (0)