Skip to content

Conversation

@c8ef
Copy link
Contributor

@c8ef c8ef commented Oct 27, 2024

This patch adds the tgamma libcall.

@c8ef c8ef changed the title Draft [TLI] Add support for the tgamma libcall. Oct 27, 2024
@c8ef c8ef marked this pull request as ready for review October 27, 2024 05:55
@llvmbot llvmbot added llvm:analysis Includes value tracking, cost tables and constant folding llvm:transforms labels Oct 27, 2024
@c8ef c8ef requested review from arsenm, dtcxzyw and nikic October 27, 2024 05:56
@llvmbot
Copy link
Member

llvmbot commented Oct 27, 2024

@llvm/pr-subscribers-llvm-transforms

@llvm/pr-subscribers-llvm-analysis

Author: None (c8ef)

Changes

This patch adds the tgamma libcall.


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

5 Files Affected:

  • (modified) llvm/include/llvm/Analysis/TargetLibraryInfo.def (+15)
  • (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 --git a/llvm/include/llvm/Analysis/TargetLibraryInfo.def b/llvm/include/llvm/Analysis/TargetLibraryInfo.def
index f890e2b9ec4c82..3e23e398f6a797 100644
--- a/llvm/include/llvm/Analysis/TargetLibraryInfo.def
+++ b/llvm/include/llvm/Analysis/TargetLibraryInfo.def
@@ -1140,6 +1140,21 @@ TLI_DEFINE_ENUM_INTERNAL(erfl)
 TLI_DEFINE_STRING_INTERNAL("erfl")
 TLI_DEFINE_SIG_INTERNAL(LDbl, LDbl)
 
+/// double tgamma(double x);
+TLI_DEFINE_ENUM_INTERNAL(tgamma)
+TLI_DEFINE_STRING_INTERNAL("tgamma")
+TLI_DEFINE_SIG_INTERNAL(Dbl, Dbl)
+
+/// float tgammaf(float x);
+TLI_DEFINE_ENUM_INTERNAL(tgammaf)
+TLI_DEFINE_STRING_INTERNAL("tgammaf")
+TLI_DEFINE_SIG_INTERNAL(Flt, Flt)
+
+/// long double tgammal(long double x);
+TLI_DEFINE_ENUM_INTERNAL(tgammal)
+TLI_DEFINE_STRING_INTERNAL("tgammal")
+TLI_DEFINE_SIG_INTERNAL(LDbl, LDbl)
+
 /// int execl(const char *path, const char *arg, ...);
 TLI_DEFINE_ENUM_INTERNAL(execl)
 TLI_DEFINE_STRING_INTERNAL("execl")
diff --git a/llvm/lib/Transforms/Utils/BuildLibCalls.cpp b/llvm/lib/Transforms/Utils/BuildLibCalls.cpp
index 13323604eb514a..5fd4fd78c28a95 100644
--- a/llvm/lib/Transforms/Utils/BuildLibCalls.cpp
+++ b/llvm/lib/Transforms/Utils/BuildLibCalls.cpp
@@ -1179,6 +1179,9 @@ bool llvm::inferNonMandatoryLibFuncAttrs(Function &F,
   case LibFunc_erf:
   case LibFunc_erff:
   case LibFunc_erfl:
+  case LibFunc_tgamma:
+  case LibFunc_tgammaf:
+  case LibFunc_tgammal:
   case LibFunc_exp:
   case LibFunc_expf:
   case LibFunc_expl:
diff --git a/llvm/test/Transforms/InferFunctionAttrs/annotate.ll b/llvm/test/Transforms/InferFunctionAttrs/annotate.ll
index 3e9b2d94efda89..d8266f4c6703dd 100644
--- a/llvm/test/Transforms/InferFunctionAttrs/annotate.ll
+++ b/llvm/test/Transforms/InferFunctionAttrs/annotate.ll
@@ -667,6 +667,15 @@ declare float @logf(float)
 ; CHECK: declare x86_fp80 @logl(x86_fp80) [[NOFREE_NOUNWIND_WILLRETURN_WRITEONLY]]
 declare x86_fp80 @logl(x86_fp80)
 
+; CHECK: declare double @tgamma(double) [[NOFREE_NOUNWIND_WILLRETURN_WRITEONLY]]
+declare double @tgamma(double)
+
+; CHECK: declare float @tgammaf(float) [[NOFREE_NOUNWIND_WILLRETURN_WRITEONLY]]
+declare float @tgammaf(float)
+
+; CHECK: declare x86_fp80 @tgammal(x86_fp80) [[NOFREE_NOUNWIND_WILLRETURN_WRITEONLY]]
+declare x86_fp80 @tgammal(x86_fp80)
+
 ; CHECK: declare noundef i32 @lstat(ptr nocapture noundef readonly, ptr nocapture noundef) [[NOFREE_NOUNWIND]]
 declare i32 @lstat(ptr, 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 20e7e15e3efb55..408b9c39934286 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: 265
+# CHECK: == Total TLI yes SDK yes: 268
 #
 # 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: 264
+# WRONG_SUMMARY: == Total TLI yes SDK yes: 267
 #
 ## 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 516 symbols, 283 available
-# AVAIL-COUNT-283: {{^}} available
+# AVAIL: TLI knows 519 symbols, 286 available
+# AVAIL-COUNT-286: {{^}} available
 # AVAIL-NOT:       {{^}} available
 # UNAVAIL-COUNT-233: not available
 # UNAVAIL-NOT:       not available
@@ -390,6 +390,18 @@ DynamicSymbols:
     Type:            STT_FUNC
     Section:         .text
     Binding:         STB_GLOBAL
+  - Name:            tgamma
+    Type:            STT_FUNC
+    Section:         .text
+    Binding:         STB_GLOBAL
+  - Name:            tgammaf
+    Type:            STT_FUNC
+    Section:         .text
+    Binding:         STB_GLOBAL
+  - Name:            tgammal
+    Type:            STT_FUNC
+    Section:         .text
+    Binding:         STB_GLOBAL
   - Name:            exp
     Type:            STT_FUNC
     Section:         .text
diff --git a/llvm/unittests/Analysis/TargetLibraryInfoTest.cpp b/llvm/unittests/Analysis/TargetLibraryInfoTest.cpp
index 346940384aff91..98f8989d4e6e9e 100644
--- a/llvm/unittests/Analysis/TargetLibraryInfoTest.cpp
+++ b/llvm/unittests/Analysis/TargetLibraryInfoTest.cpp
@@ -303,6 +303,9 @@ TEST_F(TargetLibraryInfoTest, ValidProto) {
       "declare double @erf(double)\n"
       "declare float @erff(float)\n"
       "declare x86_fp80 @erfl(x86_fp80)\n"
+      "declare double @tgamma(double)\n"
+      "declare float @tgammaf(float)\n"
+      "declare x86_fp80 @tgammal(x86_fp80)\n"
       "declare i32 @printf(i8*, ...)\n"
       "declare i32 @putc(i32, %struct*)\n"
       "declare i32 @putc_unlocked(i32, %struct*)\n"

@c8ef c8ef merged commit 0c1c37b into llvm:main Oct 29, 2024
14 checks passed
@llvm-ci
Copy link
Collaborator

llvm-ci commented Oct 29, 2024

LLVM Buildbot has detected a new failure on builder llvm-clang-x86_64-darwin running on doug-worker-3 while building llvm at step 6 "test-build-unified-tree-check-all".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/23/builds/4254

Here is the relevant piece of the build log for the reference
Step 6 (test-build-unified-tree-check-all) failure: test (failure)
******************** TEST 'Clang-Unit :: libclang/./libclangTests/11/14' FAILED ********************
Script(shard):
--
GTEST_OUTPUT=json:/Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/tools/clang/unittests/libclang/./libclangTests-Clang-Unit-12944-11-14.json GTEST_SHUFFLE=0 GTEST_TOTAL_SHARDS=14 GTEST_SHARD_INDEX=11 /Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/tools/clang/unittests/libclang/./libclangTests
--

Script:
--
/Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/tools/clang/unittests/libclang/./libclangTests --gtest_filter=LibclangParseTest.UnaryOperator
--
/Users/buildbot/buildbot-root/x86_64-darwin/llvm-project/clang/unittests/libclang/TestUtils.h:39: Failure
Value of: llvm::sys::fs::createUniqueDirectory("libclang-test", Dir)
  Actual: true
Expected: false

/Users/buildbot/buildbot-root/x86_64-darwin/llvm-project/clang/unittests/libclang/TestUtils.h:56: Failure
Value of: fs::remove(TestDir, false)
  Actual: true
Expected: false


/Users/buildbot/buildbot-root/x86_64-darwin/llvm-project/clang/unittests/libclang/TestUtils.h:39
Value of: llvm::sys::fs::createUniqueDirectory("libclang-test", Dir)
  Actual: true
Expected: false

/Users/buildbot/buildbot-root/x86_64-darwin/llvm-project/clang/unittests/libclang/TestUtils.h:56
Value of: fs::remove(TestDir, false)
  Actual: true
Expected: false


Script:
--
/Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/tools/clang/unittests/libclang/./libclangTests --gtest_filter=LibclangStoreInMemoryEmptyPreambleStoragePathTest.CountPreambles
--
/Users/buildbot/buildbot-root/x86_64-darwin/llvm-project/clang/unittests/libclang/TestUtils.h:39: Failure
Value of: llvm::sys::fs::createUniqueDirectory("libclang-test", Dir)
  Actual: true
Expected: false

/Users/buildbot/buildbot-root/x86_64-darwin/llvm-project/clang/unittests/libclang/TestUtils.h:56: Failure
Value of: fs::remove(TestDir, false)
  Actual: true
Expected: false


/Users/buildbot/buildbot-root/x86_64-darwin/llvm-project/clang/unittests/libclang/TestUtils.h:39
Value of: llvm::sys::fs::createUniqueDirectory("libclang-test", Dir)
  Actual: true
...

@c8ef c8ef deleted the gamma branch October 29, 2024 03:02
NoumanAmir657 pushed a commit to NoumanAmir657/llvm-project that referenced this pull request Nov 4, 2024
This patch adds the `tgamma` libcall.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

floating-point Floating-point math llvm:analysis Includes value tracking, cost tables and constant folding llvm:transforms

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants