[llvm] [TLI] Add support for lgamma libcall. (PR #114536)

via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 1 06:26:02 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-analysis

Author: Kenji Mouri / 毛利 研二 (MouriNaruto)

<details>
<summary>Changes</summary>

This patch adds basic support for `lgamma`. Constant folding support will be submitted in a subsequent patch.

Related issue: https://github.com/llvm/llvm-project/issues/113804

Note: I'm sorry that I made a similar PR that I had created (https://github.com/llvm/llvm-project/pull/114343) recently because one of my friends, @<!-- -->fawdlstty, hopes me to help him solve that issue in private. I think it's a good time for me to practice again. I hope I can make this PR merged successfully without reverting.

I hope I can create PRs for different topics that I am interested in for the next time instead of solving friends' issues. I know this style PRs should be left to other people who want to participate in the LLVM for the first time.

I hope @<!-- -->arsenm and @<!-- -->c8ef can help me review the code.

Kenji Mouri

---
Full diff: https://github.com/llvm/llvm-project/pull/114536.diff


6 Files Affected:

- (modified) llvm/include/llvm/Analysis/TargetLibraryInfo.def (+15) 
- (modified) llvm/lib/Analysis/TargetLibraryInfo.cpp (+2) 
- (modified) llvm/lib/Transforms/Utils/BuildLibCalls.cpp (+3) 
- (modified) llvm/test/Transforms/InferFunctionAttrs/annotate.ll (+9) 
- (modified) llvm/test/tools/llvm-tli-checker/ps4-tli-check.yaml (+16-4) 
- (modified) llvm/unittests/Analysis/TargetLibraryInfoTest.cpp (+3) 


``````````diff
diff --git a/llvm/include/llvm/Analysis/TargetLibraryInfo.def b/llvm/include/llvm/Analysis/TargetLibraryInfo.def
index fd53a26ef8fc11..04d6aef56783d5 100644
--- a/llvm/include/llvm/Analysis/TargetLibraryInfo.def
+++ b/llvm/include/llvm/Analysis/TargetLibraryInfo.def
@@ -1726,6 +1726,21 @@ TLI_DEFINE_ENUM_INTERNAL(ldexpl)
 TLI_DEFINE_STRING_INTERNAL("ldexpl")
 TLI_DEFINE_SIG_INTERNAL(LDbl, LDbl, Int)
 
+/// double lgamma(double x);
+TLI_DEFINE_ENUM_INTERNAL(lgamma)
+TLI_DEFINE_STRING_INTERNAL("lgamma")
+TLI_DEFINE_SIG_INTERNAL(Dbl, Dbl)
+
+/// float lgammaf(float x);
+TLI_DEFINE_ENUM_INTERNAL(lgammaf)
+TLI_DEFINE_STRING_INTERNAL("lgammaf")
+TLI_DEFINE_SIG_INTERNAL(Flt, Flt)
+
+/// long double lgammal(long double x);
+TLI_DEFINE_ENUM_INTERNAL(lgammal)
+TLI_DEFINE_STRING_INTERNAL("lgammal")
+TLI_DEFINE_SIG_INTERNAL(LDbl, LDbl)
+
 /// long long int llabs(long long int j);
 TLI_DEFINE_ENUM_INTERNAL(llabs)
 TLI_DEFINE_STRING_INTERNAL("llabs")
diff --git a/llvm/lib/Analysis/TargetLibraryInfo.cpp b/llvm/lib/Analysis/TargetLibraryInfo.cpp
index 7f0b98ab3c1514..a54ab8c9966c3c 100644
--- a/llvm/lib/Analysis/TargetLibraryInfo.cpp
+++ b/llvm/lib/Analysis/TargetLibraryInfo.cpp
@@ -301,6 +301,7 @@ static void initializeLibCalls(TargetLibraryInfoImpl &TLI, const Triple &T,
       TLI.setUnavailable(LibFunc_floorf);
       TLI.setUnavailable(LibFunc_fmodf);
       TLI.setUnavailable(LibFunc_hypotf);
+      TLI.setUnavailable(LibFunc_lgammaf);
       TLI.setUnavailable(LibFunc_log10f);
       TLI.setUnavailable(LibFunc_logf);
       TLI.setUnavailable(LibFunc_modff);
@@ -334,6 +335,7 @@ static void initializeLibCalls(TargetLibraryInfoImpl &TLI, const Triple &T,
     TLI.setUnavailable(LibFunc_frexpl);
     TLI.setUnavailable(LibFunc_hypotl);
     TLI.setUnavailable(LibFunc_ldexpl);
+    TLI.setUnavailable(LibFunc_lgammal);
     TLI.setUnavailable(LibFunc_log10l);
     TLI.setUnavailable(LibFunc_logl);
     TLI.setUnavailable(LibFunc_modfl);
diff --git a/llvm/lib/Transforms/Utils/BuildLibCalls.cpp b/llvm/lib/Transforms/Utils/BuildLibCalls.cpp
index e039457f313b29..35001809daeecb 100644
--- a/llvm/lib/Transforms/Utils/BuildLibCalls.cpp
+++ b/llvm/lib/Transforms/Utils/BuildLibCalls.cpp
@@ -1221,6 +1221,9 @@ bool llvm::inferNonMandatoryLibFuncAttrs(Function &F,
   case LibFunc_isascii:
   case LibFunc_isdigit:
   case LibFunc_labs:
+  case LibFunc_lgamma:
+  case LibFunc_lgammaf:
+  case LibFunc_lgammal:
   case LibFunc_llabs:
   case LibFunc_log:
   case LibFunc_log10:
diff --git a/llvm/test/Transforms/InferFunctionAttrs/annotate.ll b/llvm/test/Transforms/InferFunctionAttrs/annotate.ll
index 452d90aa98d88d..e10e60f3a86763 100644
--- a/llvm/test/Transforms/InferFunctionAttrs/annotate.ll
+++ b/llvm/test/Transforms/InferFunctionAttrs/annotate.ll
@@ -619,6 +619,15 @@ declare float @ldexpf(float, i32)
 ; CHECK: declare x86_fp80 @ldexpl(x86_fp80, i32) [[NOFREE_WILLRETURN]]
 declare x86_fp80 @ldexpl(x86_fp80, i32)
 
+; CHECK: declare double @lgamma(double) [[NOFREE_NOUNWIND_WILLRETURN_WRITEONLY]]
+declare double @lgamma(double)
+
+; CHECK: declare float @lgammaf(float) [[NOFREE_NOUNWIND_WILLRETURN_WRITEONLY]]
+declare float @lgammaf(float)
+
+; CHECK: declare x86_fp80 @lgammal(x86_fp80) [[NOFREE_NOUNWIND_WILLRETURN_WRITEONLY]]
+declare x86_fp80 @lgammal(x86_fp80)
+
 ; CHECK: declare i64 @llabs(i64) [[NOFREE_NOUNWIND_WILLRETURN_WRITEONLY]]
 declare i64 @llabs(i64)
 
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 6702725e4fc8a4..83e35b50c12920 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: 271
+# CHECK: == Total TLI yes SDK yes: 274
 #
 # WRONG_DETAIL: << TLI yes SDK no : '_ZdaPv' aka operator delete[](void*)
 # WRONG_DETAIL: >> TLI no  SDK yes: '_ZdaPvj' aka operator delete[](void*, unsigned int)
@@ -48,14 +48,14 @@
 # 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: 270
+# WRONG_SUMMARY: == Total TLI yes SDK yes: 273
 #
 ## 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 522 symbols, 289 available
-# AVAIL-COUNT-289: {{^}} available
+# AVAIL: TLI knows 525 symbols, 292 available
+# AVAIL-COUNT-292: {{^}} available
 # AVAIL-NOT:       {{^}} available
 # UNAVAIL-COUNT-233: not available
 # UNAVAIL-NOT:       not available
@@ -634,6 +634,18 @@ DynamicSymbols:
     Type:            STT_FUNC
     Section:         .text
     Binding:         STB_GLOBAL
+  - Name:            lgamma
+    Type:            STT_FUNC
+    Section:         .text
+    Binding:         STB_GLOBAL
+  - Name:            lgammaf
+    Type:            STT_FUNC
+    Section:         .text
+    Binding:         STB_GLOBAL
+  - Name:            lgammal
+    Type:            STT_FUNC
+    Section:         .text
+    Binding:         STB_GLOBAL
   - Name:            llabs
     Type:            STT_FUNC
     Section:         .text
diff --git a/llvm/unittests/Analysis/TargetLibraryInfoTest.cpp b/llvm/unittests/Analysis/TargetLibraryInfoTest.cpp
index 982d00c5d33593..34d8cae9ab3927 100644
--- a/llvm/unittests/Analysis/TargetLibraryInfoTest.cpp
+++ b/llvm/unittests/Analysis/TargetLibraryInfoTest.cpp
@@ -272,6 +272,9 @@ TEST_F(TargetLibraryInfoTest, ValidProto) {
       "declare i32 @ilogb(double)\n"
       "declare i32 @ilogbf(float)\n"
       "declare i32 @ilogbl(x86_fp80)\n"
+      "declare double @lgamma(double)\n"
+      "declare float @lgammaf(float)\n"
+      "declare x86_fp80 @lgammal(x86_fp80)\n"
       "declare double @logb(double)\n"
       "declare float @logbf(float)\n"
       "declare x86_fp80 @logbl(x86_fp80)\n"

``````````

</details>


https://github.com/llvm/llvm-project/pull/114536


More information about the llvm-commits mailing list