[llvm] [TLI] Add basic support for scalbnxx (PR #112936)

via llvm-commits llvm-commits at lists.llvm.org
Sat Oct 19 22:05:18 PDT 2024


https://github.com/fawdlstty updated https://github.com/llvm/llvm-project/pull/112936

>From 33d2e799fbfa648aa79cd2c5a7d829dff5d39407 Mon Sep 17 00:00:00 2001
From: fawdlstty <f at fawdlstty.com>
Date: Sat, 19 Oct 2024 01:04:04 +0800
Subject: [PATCH 1/3] [TLI] Add basic support for scabnxx

---
 .../llvm/Analysis/TargetLibraryInfo.def       | 30 +++++++++++++++++++
 llvm/lib/Analysis/TargetLibraryInfo.cpp       |  6 ++++
 llvm/lib/Transforms/Utils/BuildLibCalls.cpp   |  6 ++++
 .../Transforms/InferFunctionAttrs/annotate.ll | 18 +++++++++++
 .../tools/llvm-tli-checker/ps4-tli-check.yaml | 30 +++++++++++++++++--
 .../Analysis/TargetLibraryInfoTest.cpp        |  6 ++++
 6 files changed, 93 insertions(+), 3 deletions(-)

diff --git a/llvm/include/llvm/Analysis/TargetLibraryInfo.def b/llvm/include/llvm/Analysis/TargetLibraryInfo.def
index d472cde3d50431..f890e2b9ec4c82 100644
--- a/llvm/include/llvm/Analysis/TargetLibraryInfo.def
+++ b/llvm/include/llvm/Analysis/TargetLibraryInfo.def
@@ -2162,6 +2162,36 @@ TLI_DEFINE_ENUM_INTERNAL(roundl)
 TLI_DEFINE_STRING_INTERNAL("roundl")
 TLI_DEFINE_SIG_INTERNAL(LDbl, LDbl)
 
+/// double scalbln(double arg, long exp);
+TLI_DEFINE_ENUM_INTERNAL(scalbln)
+TLI_DEFINE_STRING_INTERNAL("scalbln")
+TLI_DEFINE_SIG_INTERNAL(Dbl, Dbl, Long)
+
+/// float scalblnf(float arg, long exp);
+TLI_DEFINE_ENUM_INTERNAL(scalblnf)
+TLI_DEFINE_STRING_INTERNAL("scalblnf")
+TLI_DEFINE_SIG_INTERNAL(Flt, Flt, Long)
+
+/// long double scalblnl(long double arg, long exp);
+TLI_DEFINE_ENUM_INTERNAL(scalblnl)
+TLI_DEFINE_STRING_INTERNAL("scalblnl")
+TLI_DEFINE_SIG_INTERNAL(LDbl, LDbl, Long)
+
+/// double scalbn(double arg, int exp);
+TLI_DEFINE_ENUM_INTERNAL(scalbn)
+TLI_DEFINE_STRING_INTERNAL("scalbn")
+TLI_DEFINE_SIG_INTERNAL(Dbl, Dbl, Int)
+
+/// float scalbnf(float arg, int exp);
+TLI_DEFINE_ENUM_INTERNAL(scalbnf)
+TLI_DEFINE_STRING_INTERNAL("scalbnf")
+TLI_DEFINE_SIG_INTERNAL(Flt, Flt, Int)
+
+/// long double scalbnl(long double arg, int exp);
+TLI_DEFINE_ENUM_INTERNAL(scalbnl)
+TLI_DEFINE_STRING_INTERNAL("scalbnl")
+TLI_DEFINE_SIG_INTERNAL(LDbl, LDbl, Int)
+
 /// int scanf(const char *restrict format, ... );
 TLI_DEFINE_ENUM_INTERNAL(scanf)
 TLI_DEFINE_STRING_INTERNAL("scanf")
diff --git a/llvm/lib/Analysis/TargetLibraryInfo.cpp b/llvm/lib/Analysis/TargetLibraryInfo.cpp
index d9651d2f47c647..654cd9f12d74eb 100644
--- a/llvm/lib/Analysis/TargetLibraryInfo.cpp
+++ b/llvm/lib/Analysis/TargetLibraryInfo.cpp
@@ -382,6 +382,12 @@ static void initializeLibCalls(TargetLibraryInfoImpl &TLI, const Triple &T,
       TLI.setUnavailable(LibFunc_rintf);
       TLI.setUnavailable(LibFunc_round);
       TLI.setUnavailable(LibFunc_roundf);
+      TLI.setUnavailable(LibFunc_scalbln);
+      TLI.setUnavailable(LibFunc_scalblnf);
+      TLI.setUnavailable(LibFunc_scalblnl);
+      TLI.setUnavailable(LibFunc_scalbn);
+      TLI.setUnavailable(LibFunc_scalbnf);
+      TLI.setUnavailable(LibFunc_scalbnl);
       TLI.setUnavailable(LibFunc_trunc);
       TLI.setUnavailable(LibFunc_truncf);
     }
diff --git a/llvm/lib/Transforms/Utils/BuildLibCalls.cpp b/llvm/lib/Transforms/Utils/BuildLibCalls.cpp
index c97a77d12e3e9d..13323604eb514a 100644
--- a/llvm/lib/Transforms/Utils/BuildLibCalls.cpp
+++ b/llvm/lib/Transforms/Utils/BuildLibCalls.cpp
@@ -1249,6 +1249,12 @@ bool llvm::inferNonMandatoryLibFuncAttrs(Function &F,
   case LibFunc_round:
   case LibFunc_roundf:
   case LibFunc_roundl:
+  case LibFunc_scalbln:
+  case LibFunc_scalblnf:
+  case LibFunc_scalblnl:
+  case LibFunc_scalbn:
+  case LibFunc_scalbnf:
+  case LibFunc_scalbnl:
   case LibFunc_sin:
   case LibFunc_sincospif_stret:
   case LibFunc_sinf:
diff --git a/llvm/test/Transforms/InferFunctionAttrs/annotate.ll b/llvm/test/Transforms/InferFunctionAttrs/annotate.ll
index 8567cc00ed00e3..3e9b2d94efda89 100644
--- a/llvm/test/Transforms/InferFunctionAttrs/annotate.ll
+++ b/llvm/test/Transforms/InferFunctionAttrs/annotate.ll
@@ -876,6 +876,24 @@ declare float @roundf(float)
 ; CHECK: declare x86_fp80 @roundl(x86_fp80) [[NOFREE_NOUNWIND_WILLRETURN_WRITEONLY]]
 declare x86_fp80 @roundl(x86_fp80)
 
+; CHECK: declare double @scalbln(double, i64) [[NOFREE_NOUNWIND_WILLRETURN_WRITEONLY]]
+declare double @scalbln(double, i64)
+
+; CHECK: declare float @scalblnf(float, i64) [[NOFREE_NOUNWIND_WILLRETURN_WRITEONLY]]
+declare float @scalblnf(float, i64)
+
+; CHECK: declare x86_fp80 @scalblnl(x86_fp80, i64) [[NOFREE_NOUNWIND_WILLRETURN_WRITEONLY]]
+declare x86_fp80 @scalblnl(x86_fp80, i64)
+
+; CHECK: declare double @scalbn(double, i32) [[NOFREE_NOUNWIND_WILLRETURN_WRITEONLY]]
+declare double @scalbn(double, i32)
+
+; CHECK: declare float @scalbnf(float, i32) [[NOFREE_NOUNWIND_WILLRETURN_WRITEONLY]]
+declare float @scalbnf(float, i32)
+
+; CHECK: declare x86_fp80 @scalbnl(x86_fp80, i32) [[NOFREE_NOUNWIND_WILLRETURN_WRITEONLY]]
+declare x86_fp80 @scalbnl(x86_fp80, i32)
+
 ; CHECK: declare noundef i32 @scanf(ptr nocapture noundef readonly, ...) [[NOFREE_NOUNWIND]]
 declare i32 @scanf(ptr, ...)
 
diff --git a/llvm/test/tools/llvm-tli-checker/ps4-tli-check.yaml b/llvm/test/tools/llvm-tli-checker/ps4-tli-check.yaml
index aad5794fd8c278..2497566b009fbf 100644
--- a/llvm/test/tools/llvm-tli-checker/ps4-tli-check.yaml
+++ b/llvm/test/tools/llvm-tli-checker/ps4-tli-check.yaml
@@ -34,7 +34,7 @@
 #
 # CHECK: << Total TLI yes SDK no:  18
 # CHECK: >> Total TLI no  SDK yes: 0
-# CHECK: == Total TLI yes SDK yes: 259
+# CHECK: == Total TLI yes SDK yes: 265
 #
 # WRONG_DETAIL: << TLI yes SDK no : '_ZdaPv' aka operator delete[](void*)
 # WRONG_DETAIL: >> TLI no  SDK yes: '_ZdaPvj' aka operator delete[](void*, unsigned int)
@@ -54,8 +54,8 @@
 ## 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 510 symbols, 277 available
-# AVAIL-COUNT-277: {{^}} available
+# AVAIL: TLI knows 516 symbols, 283 available
+# AVAIL-COUNT-283: {{^}} available
 # AVAIL-NOT:       {{^}} available
 # UNAVAIL-COUNT-233: not available
 # UNAVAIL-NOT:       not available
@@ -866,6 +866,30 @@ DynamicSymbols:
     Type:            STT_FUNC
     Section:         .text
     Binding:         STB_GLOBAL
+  - Name:            scalbln
+    Type:            STT_FUNC
+    Section:         .text
+    Binding:         STB_GLOBAL
+  - Name:            scalblnf
+    Type:            STT_FUNC
+    Section:         .text
+    Binding:         STB_GLOBAL
+  - Name:            scalblnl
+    Type:            STT_FUNC
+    Section:         .text
+    Binding:         STB_GLOBAL
+  - Name:            scalbn
+    Type:            STT_FUNC
+    Section:         .text
+    Binding:         STB_GLOBAL
+  - Name:            scalbnf
+    Type:            STT_FUNC
+    Section:         .text
+    Binding:         STB_GLOBAL
+  - Name:            scalbnl
+    Type:            STT_FUNC
+    Section:         .text
+    Binding:         STB_GLOBAL
   - Name:            scanf
     Type:            STT_FUNC
     Section:         .text
diff --git a/llvm/unittests/Analysis/TargetLibraryInfoTest.cpp b/llvm/unittests/Analysis/TargetLibraryInfoTest.cpp
index b4856b50bbe584..346940384aff91 100644
--- a/llvm/unittests/Analysis/TargetLibraryInfoTest.cpp
+++ b/llvm/unittests/Analysis/TargetLibraryInfoTest.cpp
@@ -335,6 +335,12 @@ TEST_F(TargetLibraryInfoTest, ValidProto) {
       "declare double @roundeven(double)\n"
       "declare float @roundevenf(float)\n"
       "declare x86_fp80 @roundevenl(x86_fp80)\n"
+      "declare double @scalbln(double, i64)\n"
+      "declare float @scalblnf(float, i64)\n"
+      "declare x86_fp80 @scalblnl(x86_fp80, i64)\n"
+      "declare double @scalbn(double, i32)\n"
+      "declare float @scalbnf(float, i32)\n"
+      "declare x86_fp80 @scalbnl(x86_fp80, i32)\n"
       "declare i32 @scanf(i8*, ...)\n"
       "declare void @setbuf(%struct*, i8*)\n"
       "declare i32 @setitimer(i32, %struct*, %struct*)\n"

>From 59253f47246bf9d50c2df2b66a48f0f14198106a Mon Sep 17 00:00:00 2001
From: fawdlstty <f at fawdlstty.com>
Date: Sat, 19 Oct 2024 16:55:14 +0800
Subject: [PATCH 2/3] add unavailable methods

---
 llvm/lib/Analysis/TargetLibraryInfo.cpp | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/llvm/lib/Analysis/TargetLibraryInfo.cpp b/llvm/lib/Analysis/TargetLibraryInfo.cpp
index 654cd9f12d74eb..0ee83d217a5001 100644
--- a/llvm/lib/Analysis/TargetLibraryInfo.cpp
+++ b/llvm/lib/Analysis/TargetLibraryInfo.cpp
@@ -410,6 +410,8 @@ static void initializeLibCalls(TargetLibraryInfoImpl &TLI, const Triple &T,
     TLI.setUnavailable(LibFunc_nearbyintl);
     TLI.setUnavailable(LibFunc_rintl);
     TLI.setUnavailable(LibFunc_roundl);
+    TLI.setUnavailable(LibFunc_scalblnl);
+    TLI.setUnavailable(LibFunc_scalbnl);
     TLI.setUnavailable(LibFunc_truncl);
 
     // Win32 does not support these functions, but

>From cd7fc6c9fb1904711ae1f2fbe5f6ebb83dbdca5b Mon Sep 17 00:00:00 2001
From: fawdlstty <f at fawdlstty.com>
Date: Sun, 20 Oct 2024 13:04:27 +0800
Subject: [PATCH 3/3] update test result info

---
 llvm/test/tools/llvm-tli-checker/ps4-tli-check.yaml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/test/tools/llvm-tli-checker/ps4-tli-check.yaml b/llvm/test/tools/llvm-tli-checker/ps4-tli-check.yaml
index 2497566b009fbf..20e7e15e3efb55 100644
--- a/llvm/test/tools/llvm-tli-checker/ps4-tli-check.yaml
+++ b/llvm/test/tools/llvm-tli-checker/ps4-tli-check.yaml
@@ -48,7 +48,7 @@
 # WRONG_DETAIL: << TLI yes SDK no : 'fminimum_numl'
 # WRONG_SUMMARY: << Total TLI yes SDK no:  19{{$}}
 # WRONG_SUMMARY: >> Total TLI no  SDK yes: 1{{$}}
-# WRONG_SUMMARY: == Total TLI yes SDK yes: 258
+# WRONG_SUMMARY: == Total TLI yes SDK yes: 264
 #
 ## 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.



More information about the llvm-commits mailing list