Skip to content

Conversation

@arsenm
Copy link
Contributor

@arsenm arsenm commented Nov 4, 2025

Eventually this should be generated by tablegen for all functions.
For now add a manually implementation for sincos_stret, which I
have an immediate use for. This will allow pulling repeated code
across targets into shared call sequence code.

Also add sqrt just to make sure we can handle adding return attributes
on the declaration.

Eventually this should be generated by tablegen for all functions.
For now add a manually implementation for sincos_stret, which I
have an immediate use for. This will allow pulling repeated code
across targets into shared call sequence code.

Also add sqrt just to make sure we can handle adding return attributes
on the declaration.
Copy link
Contributor Author

arsenm commented Nov 4, 2025

@llvmbot
Copy link
Member

llvmbot commented Nov 4, 2025

@llvm/pr-subscribers-llvm-transforms

@llvm/pr-subscribers-llvm-ir

Author: Matt Arsenault (arsenm)

Changes

Eventually this should be generated by tablegen for all functions.
For now add a manually implementation for sincos_stret, which I
have an immediate use for. This will allow pulling repeated code
across targets into shared call sequence code.

Also add sqrt just to make sure we can handle adding return attributes
on the declaration.


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

7 Files Affected:

  • (modified) llvm/include/llvm/IR/RuntimeLibcalls.h (+7)
  • (modified) llvm/lib/IR/RuntimeLibcalls.cpp (+79)
  • (modified) llvm/lib/Transforms/Utils/DeclareRuntimeLibcalls.cpp (+44-4)
  • (modified) llvm/test/Transforms/Util/DeclareRuntimeLibcalls/basic.ll (+4)
  • (added) llvm/test/Transforms/Util/DeclareRuntimeLibcalls/merge_attributes.ll (+11)
  • (added) llvm/test/Transforms/Util/DeclareRuntimeLibcalls/sincos_stret.ll (+23)
  • (added) llvm/test/Transforms/Util/DeclareRuntimeLibcalls/wrong_declaration.ll (+21)
diff --git a/llvm/include/llvm/IR/RuntimeLibcalls.h b/llvm/include/llvm/IR/RuntimeLibcalls.h
index 01359894b0421..ab14ed44fed52 100644
--- a/llvm/include/llvm/IR/RuntimeLibcalls.h
+++ b/llvm/include/llvm/IR/RuntimeLibcalls.h
@@ -186,6 +186,13 @@ struct RuntimeLibcallsInfo {
     return RTLIB::Unsupported;
   }
 
+  /// \returns the function type and attributes for the \p LibcallImpl,
+  /// depending on the target \p TT. If the function has incomplete type
+  /// information, return nullptr for the function type.
+  std::pair<FunctionType *, AttributeList>
+  getFunctionTy(LLVMContext &Ctx, const Triple &TT, const DataLayout &DL,
+                RTLIB::LibcallImpl LibcallImpl) const;
+
 private:
   LLVM_ABI static iota_range<RTLIB::LibcallImpl>
   lookupLibcallImplNameImpl(StringRef Name);
diff --git a/llvm/lib/IR/RuntimeLibcalls.cpp b/llvm/lib/IR/RuntimeLibcalls.cpp
index 77af29b9d70f6..2ce5719228a0d 100644
--- a/llvm/lib/IR/RuntimeLibcalls.cpp
+++ b/llvm/lib/IR/RuntimeLibcalls.cpp
@@ -7,7 +7,9 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/IR/RuntimeLibcalls.h"
+#include "llvm/ADT/FloatingPointMode.h"
 #include "llvm/ADT/StringTable.h"
+#include "llvm/IR/DataLayout.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/xxhash.h"
 #include "llvm/TargetParser/ARMTargetParser.h"
@@ -72,3 +74,80 @@ bool RuntimeLibcallsInfo::darwinHasExp10(const Triple &TT) {
     return false;
   }
 }
+
+std::pair<FunctionType *, AttributeList>
+RuntimeLibcallsInfo::getFunctionTy(LLVMContext &Ctx, const Triple &TT,
+                                   const DataLayout &DL,
+                                   RTLIB::LibcallImpl LibcallImpl) const {
+  static constexpr Attribute::AttrKind CommonFnAttrs[] = {
+      Attribute::NoCallback, Attribute::NoFree, Attribute::NoSync,
+      Attribute::NoUnwind, Attribute::WillReturn};
+
+  switch (LibcallImpl) {
+  case RTLIB::impl___sincos_stret:
+  case RTLIB::impl___sincosf_stret: {
+    if (!darwinHasSinCosStret(TT)) // Non-darwin currently unexpected
+      return {};
+
+    Type *ScalarTy = LibcallImpl == RTLIB::impl___sincosf_stret
+                         ? Type::getFloatTy(Ctx)
+                         : Type::getDoubleTy(Ctx);
+
+    AttrBuilder FuncAttrBuilder(Ctx);
+    for (Attribute::AttrKind Attr : CommonFnAttrs)
+      FuncAttrBuilder.addAttribute(Attr);
+
+    const bool UseSret =
+        TT.isX86_32() || ((TT.isARM() || TT.isThumb()) &&
+                          ARM::computeTargetABI(TT) == ARM::ARM_ABI_APCS);
+
+    FuncAttrBuilder.addMemoryAttr(MemoryEffects::argumentOrErrnoMemOnly(
+        UseSret ? ModRefInfo::Mod : ModRefInfo::NoModRef, ModRefInfo::Mod));
+
+    AttributeList Attrs;
+    Attrs = Attrs.addFnAttributes(Ctx, FuncAttrBuilder);
+
+    if (UseSret) {
+      AttrBuilder AttrBuilder(Ctx);
+      StructType *StructTy = StructType::get(ScalarTy, ScalarTy);
+      AttrBuilder.addStructRetAttr(StructTy);
+      AttrBuilder.addAlignmentAttr(DL.getABITypeAlign(StructTy));
+      FunctionType *FuncTy = FunctionType::get(
+          Type::getVoidTy(Ctx), {DL.getAllocaPtrType(Ctx), ScalarTy}, false);
+
+      return {FuncTy, Attrs.addParamAttributes(Ctx, 0, AttrBuilder)};
+    }
+
+    Type *RetTy =
+        LibcallImpl == RTLIB::impl___sincosf_stret && TT.isX86_64()
+            ? static_cast<Type *>(FixedVectorType::get(ScalarTy, 2))
+            : static_cast<Type *>(StructType::get(ScalarTy, ScalarTy));
+
+    return {FunctionType::get(RetTy, {ScalarTy}, false), Attrs};
+  }
+  case RTLIB::impl_sqrtf:
+  case RTLIB::impl_sqrt: {
+    AttrBuilder FuncAttrBuilder(Ctx);
+
+    for (Attribute::AttrKind Attr : CommonFnAttrs)
+      FuncAttrBuilder.addAttribute(Attr);
+    FuncAttrBuilder.addMemoryAttr(MemoryEffects::errnoMemOnly(ModRefInfo::Mod));
+
+    AttributeList Attrs;
+    Attrs = Attrs.addFnAttributes(Ctx, FuncAttrBuilder);
+
+    Type *ScalarTy = LibcallImpl == RTLIB::impl_sqrtf ? Type::getFloatTy(Ctx)
+                                                      : Type::getDoubleTy(Ctx);
+    FunctionType *FuncTy = FunctionType::get(ScalarTy, {ScalarTy}, false);
+
+    Attrs = Attrs.addRetAttribute(
+        Ctx, Attribute::getWithNoFPClass(Ctx, fcNegInf | fcNegSubnormal |
+                                                  fcNegNormal));
+    return {FuncTy, Attrs};
+  }
+  default:
+    return {};
+  }
+
+  return {};
+}
diff --git a/llvm/lib/Transforms/Utils/DeclareRuntimeLibcalls.cpp b/llvm/lib/Transforms/Utils/DeclareRuntimeLibcalls.cpp
index 0642d51cd2c21..6d4436b92c119 100644
--- a/llvm/lib/Transforms/Utils/DeclareRuntimeLibcalls.cpp
+++ b/llvm/lib/Transforms/Utils/DeclareRuntimeLibcalls.cpp
@@ -16,22 +16,62 @@
 
 using namespace llvm;
 
+static void mergeAttributes(LLVMContext &Ctx, const Module &M,
+                            const DataLayout &DL, const Triple &TT,
+                            Function *Func, FunctionType *FuncTy,
+                            AttributeList FuncAttrs) {
+  AttributeList OldAttrs = Func->getAttributes();
+  AttributeList NewAttrs = OldAttrs;
+
+  {
+    AttrBuilder OldBuilder(Ctx, OldAttrs.getFnAttrs());
+    AttrBuilder NewBuilder(Ctx, FuncAttrs.getFnAttrs());
+    OldBuilder.merge(NewBuilder);
+    NewAttrs = NewAttrs.addFnAttributes(Ctx, OldBuilder);
+  }
+
+  {
+    AttrBuilder OldBuilder(Ctx, OldAttrs.getRetAttrs());
+    AttrBuilder NewBuilder(Ctx, FuncAttrs.getRetAttrs());
+    OldBuilder.merge(NewBuilder);
+    NewAttrs = NewAttrs.addRetAttributes(Ctx, OldBuilder);
+  }
+
+  for (unsigned I = 0, E = FuncTy->getNumParams(); I != E; ++I) {
+    AttrBuilder OldBuilder(Ctx, OldAttrs.getParamAttrs(I));
+    AttrBuilder NewBuilder(Ctx, FuncAttrs.getParamAttrs(I));
+    OldBuilder.merge(NewBuilder);
+    NewAttrs = NewAttrs.addParamAttributes(Ctx, I, OldBuilder);
+  }
+
+  Func->setAttributes(NewAttrs);
+}
+
 PreservedAnalyses DeclareRuntimeLibcallsPass::run(Module &M,
                                                   ModuleAnalysisManager &MAM) {
   RTLIB::RuntimeLibcallsInfo RTLCI(M.getTargetTriple());
   LLVMContext &Ctx = M.getContext();
+  const DataLayout &DL = M.getDataLayout();
+  const Triple &TT = M.getTargetTriple();
 
   for (RTLIB::LibcallImpl Impl : RTLCI.getLibcallImpls()) {
     if (Impl == RTLIB::Unsupported)
       continue;
 
-    // TODO: Declare with correct type, calling convention, and attributes.
+    auto [FuncTy, FuncAttrs] = RTLCI.getFunctionTy(Ctx, TT, DL, Impl);
 
-    FunctionType *FuncTy =
-        FunctionType::get(Type::getVoidTy(Ctx), {}, /*IsVarArgs=*/true);
+    // TODO: Declare with correct type, calling convention, and attributes.
+    if (!FuncTy)
+      FuncTy = FunctionType::get(Type::getVoidTy(Ctx), {}, /*IsVarArgs=*/true);
 
     StringRef FuncName = RTLCI.getLibcallImplName(Impl);
-    M.getOrInsertFunction(FuncName, FuncTy);
+
+    Function *Func =
+        cast<Function>(M.getOrInsertFunction(FuncName, FuncTy).getCallee());
+    if (Func->getFunctionType() == FuncTy) {
+      mergeAttributes(Ctx, M, DL, TT, Func, FuncTy, FuncAttrs);
+      Func->setCallingConv(RTLCI.getLibcallImplCallingConv(Impl));
+    }
   }
 
   return PreservedAnalyses::none();
diff --git a/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/basic.ll b/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/basic.ll
index ee3a0539bf300..c005316f07f06 100644
--- a/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/basic.ll
+++ b/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/basic.ll
@@ -11,5 +11,9 @@ define float @sinf(float %x) {
 }
 
 ; CHECK: declare void @acosf(...)
+
+; CHECK: declare nofpclass(ninf nsub nnorm) float @sqrtf(float) [[SQRT_ATTRS:#[0-9]+]]
+; CHECK: declare nofpclass(ninf nsub nnorm) double @sqrt(double) [[SQRT_ATTRS:#[0-9]+]]
+
 ; CHECK: declare void @__umodti3(...)
 
diff --git a/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/merge_attributes.ll b/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/merge_attributes.ll
new file mode 100644
index 0000000000000..ffbf11d4106dc
--- /dev/null
+++ b/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/merge_attributes.ll
@@ -0,0 +1,11 @@
+; RUN: opt -S -passes=declare-runtime-libcalls -mtriple=x86_64-unknown-linux-gnu < %s | FileCheck %s
+
+define noundef nofpclass(nan) float @sqrtf(float %x) "foo" {
+  %ret = call float asm "; $0 = sqrt($1)", "=r,r"(float %x)
+  ret float %ret
+}
+
+; FIXME: Individual fields of nofpclass not merged
+; CHECK: define noundef nofpclass(ninf nsub nnorm) float @sqrtf(float %x) [[SQRT_ATTR:#[0-9]+]] {
+
+; CHECK: attributes [[SQRT_ATTR]] = { nocallback nofree nosync nounwind willreturn memory(errnomem: write) "foo" }
diff --git a/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/sincos_stret.ll b/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/sincos_stret.ll
new file mode 100644
index 0000000000000..0d0e3da25eea7
--- /dev/null
+++ b/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/sincos_stret.ll
@@ -0,0 +1,23 @@
+; RUN: opt -S -passes=declare-runtime-libcalls -mtriple=x86_64-apple-macos10.9 < %s | FileCheck -check-prefixes=CHECK,X64 %s
+; RUN: opt -S -passes=declare-runtime-libcalls -mtriple=arm64-apple-macos10.9 < %s | FileCheck -check-prefixes=CHECK,STRUCT %s
+; RUN: opt -S -passes=declare-runtime-libcalls -mtriple=thumbv7k-apple-watchos2.0 < %s | FileCheck -check-prefixes=CHECK,STRUCT %s
+; RUN: opt -S -passes=declare-runtime-libcalls -mtriple=armv7-apple-ios7 < %s | FileCheck -check-prefix=SRET %s
+; RUN: opt -S -passes=declare-runtime-libcalls -mtriple=thumbv7-apple-ios7 < %s | FileCheck -check-prefix=SRET %s
+
+; RUN: opt -S -passes=declare-runtime-libcalls -mtriple=armv7-apple-ios6 < %s | FileCheck -check-prefix=NONE %s
+; RUN: opt -S -passes=declare-runtime-libcalls -mtriple=x86_64-apple-macos10.8 < %s | FileCheck -check-prefix=NONE %s
+
+; X64: declare <2 x float> @__sincosf_stret(float) [[SINCOS_ATTRS:#[0-9]+]]
+; X64: declare { double, double } @__sincos_stret(double) [[SINCOS_ATTRS:#[0-9]+]]
+
+; STRUCT: declare { float, float } @__sincosf_stret(float) [[SINCOS_ATTRS:#[0-9]+]]
+; STRUCT: declare { double, double } @__sincos_stret(double) [[SINCOS_ATTRS:#[0-9]+]]
+
+; SRET: declare void @__sincosf_stret(ptr sret({ float, float }) align 4, float) [[SINCOS_ATTRS:#[0-9]+]]
+; SRET: declare void @__sincos_stret(ptr sret({ double, double }) align 4, double) [[SINCOS_ATTRS:#[0-9]+]]
+
+; CHECK: attributes [[SINCOS_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(errnomem: write) }
+; SRET: attributes [[SINCOS_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(argmem: write, errnomem: write) }
+
+; NONE-NOT: __sincos_stret
+; NONE-NOT: __sincosf_stret
diff --git a/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/wrong_declaration.ll b/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/wrong_declaration.ll
new file mode 100644
index 0000000000000..2451010df5b75
--- /dev/null
+++ b/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/wrong_declaration.ll
@@ -0,0 +1,21 @@
+; RUN: opt -S -passes=declare-runtime-libcalls -mtriple=x86_64-apple-macos10.9 < %s | FileCheck %s
+
+; Make sure there is no crash if there are definitions or declarations
+; with the wrong type signature.
+
+; CHECK: define void @sqrtf() {
+define void @sqrtf() {
+  ret void
+}
+
+; CHECK: define float @sqrt(float %0) {
+define float @sqrt(float) {
+  ret float 0.0
+}
+
+; CHECK: declare double @__sincos_stret(double)
+declare double @__sincos_stret(double)
+
+; CHECK: declare { float, float } @__sincosf_stret(float)
+declare { float, float } @__sincosf_stret(float)
+

@arsenm arsenm merged commit fb21f16 into main Nov 4, 2025
16 checks passed
@arsenm arsenm deleted the users/arsenm/runtime-libcalls/add-sincos-stret-type-info branch November 4, 2025 18:06
@Kewen12
Copy link
Contributor

Kewen12 commented Nov 4, 2025

Hello, we see a test failure in our bot. It seems related to this PR. Could you please take a look? Thanks!

bot: https://lab.llvm.org/buildbot/#/builders/10/builds/16663

| Input was:
# | <<<<<<
# |             .
# |             .
# |             .
# |           597: declare void @sincospi(...) 
# |           598:  
# |           599: declare void @sincospil(...) 
# |           600:  
# |           601: ; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: write, errnomem: write) 
# |           602: declare void @__sincosf_stret(ptr sret({ float, float }) align 4, float) #0 
# | check:17'0                                                                                X error: no match found
# |           603:  
# | check:17'0     ~
# |           604: ; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: write, errnomem: write) 
# | check:17'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |           605: declare void @__sincos_stret(ptr sret({ double, double }) align 8, double) #0 
# | check:17'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | check:17'1     ?                                                                              possible intended match
# |           606:  
# | check:17'0     ~
# |           607: declare void @sinhf(...) 
# | check:17'0     ~~~~~~~~~~~~~~~~~~~~~~~~~
# |           608:  
# | check:17'0     ~
# |           609: declare void @sinh(...) 
# | check:17'0     ~~~~~~~~~~~~~~~~~~~~~~~~
# |           610:  
# | check:17'0     ~
# |             .
# |             .
# |             .
# | >>>>>>
# `-----------------------------
# error: command failed with exit status: 1

@llvm-ci
Copy link
Collaborator

llvm-ci commented Nov 4, 2025

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

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

Here is the relevant piece of the build log for the reference
Step 6 (test-build-unified-tree-check-all) failure: test (failure)
******************** TEST 'LLVM :: Transforms/Util/DeclareRuntimeLibcalls/sincos_stret.ll' FAILED ********************
Exit Code: 1

Command Output (stdout):
--
# RUN: at line 1
/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/opt -S -passes=declare-runtime-libcalls -mtriple=x86_64-apple-macos10.9 < /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/sincos_stret.ll | /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/FileCheck -check-prefixes=CHECK,X64 /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/sincos_stret.ll
# executed command: /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/opt -S -passes=declare-runtime-libcalls -mtriple=x86_64-apple-macos10.9
# note: command had no output on stdout or stderr
# executed command: /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/FileCheck -check-prefixes=CHECK,X64 /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/sincos_stret.ll
# note: command had no output on stdout or stderr
# RUN: at line 2
/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/opt -S -passes=declare-runtime-libcalls -mtriple=arm64-apple-macos10.9 < /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/sincos_stret.ll | /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/FileCheck -check-prefixes=CHECK,STRUCT /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/sincos_stret.ll
# executed command: /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/opt -S -passes=declare-runtime-libcalls -mtriple=arm64-apple-macos10.9
# .---command stderr------------
# | /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/opt: warning: failed to infer data layout: unable to get target for 'arm64-apple-macos10.9', see --version and --triple.
# | /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/opt: WARNING: failed to create target machine for 'arm64-apple-macos10.9': unable to get target for 'arm64-apple-macos10.9', see --version and --triple.
# `-----------------------------
# executed command: /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/FileCheck -check-prefixes=CHECK,STRUCT /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/sincos_stret.ll
# note: command had no output on stdout or stderr
# RUN: at line 3
/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/opt -S -passes=declare-runtime-libcalls -mtriple=thumbv7k-apple-watchos2.0 < /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/sincos_stret.ll | /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/FileCheck -check-prefixes=CHECK,STRUCT /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/sincos_stret.ll
# executed command: /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/opt -S -passes=declare-runtime-libcalls -mtriple=thumbv7k-apple-watchos2.0
# .---command stderr------------
# | /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/opt: warning: failed to infer data layout: unable to get target for 'thumbv7k-apple-watchos2.0', see --version and --triple.
# | /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/opt: WARNING: failed to create target machine for 'thumbv7k-apple-watchos2.0': unable to get target for 'thumbv7k-apple-watchos2.0', see --version and --triple.
# `-----------------------------
# executed command: /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/FileCheck -check-prefixes=CHECK,STRUCT /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/sincos_stret.ll
# note: command had no output on stdout or stderr
# RUN: at line 4
/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/opt -S -passes=declare-runtime-libcalls -mtriple=armv7-apple-ios7 < /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/sincos_stret.ll | /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/FileCheck -check-prefix=SRET /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/sincos_stret.ll
# executed command: /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/opt -S -passes=declare-runtime-libcalls -mtriple=armv7-apple-ios7
# .---command stderr------------
# | /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/opt: warning: failed to infer data layout: unable to get target for 'armv7-apple-ios7', see --version and --triple.
# | /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/opt: WARNING: failed to create target machine for 'armv7-apple-ios7': unable to get target for 'armv7-apple-ios7', see --version and --triple.
# `-----------------------------
# executed command: /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/FileCheck -check-prefix=SRET /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/sincos_stret.ll
# .---command stderr------------
# | �[1m/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/sincos_stret.ll:17:9: �[0m�[0;1;31merror: �[0m�[1mSRET: expected string not found in input
�[0m# | �[1m�[0m; SRET: declare void @__sincos_stret(ptr sret({ double, double }) align 4, double) [[SINCOS_ATTRS:#[0-9]+]]
# | �[0;1;32m        ^
�[0m# | �[0;1;32m�[0m�[1m<stdin>:602:76: �[0m�[0;1;30mnote: �[0m�[1mscanning from here
�[0m# | �[1m�[0mdeclare void @__sincosf_stret(ptr sret({ float, float }) align 4, float) #0
# | �[0;1;32m                                                                           ^
�[0m# | �[0;1;32m�[0m�[1m<stdin>:605:1: �[0m�[0;1;30mnote: �[0m�[1mpossible intended match here
�[0m# | �[1m�[0mdeclare void @__sincos_stret(ptr sret({ double, double }) align 8, double) #0
# | �[0;1;32m^
�[0m# | �[0;1;32m�[0m
# | Input file: <stdin>
# | Check file: /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/sincos_stret.ll
...

@arsenm
Copy link
Contributor Author

arsenm commented Nov 4, 2025

Hello, we see a test failure in our bot. It seems related to this PR. Could you please take a look? Thanks!

bot: https://lab.llvm.org/buildbot/#/builders/10/builds/16663

| Input was:
# | <<<<<<
# |             .
# |             .
# |             .
# |           597: declare void @sincospi(...) 
# |           598:  
# |           599: declare void @sincospil(...) 
# |           600:  
# |           601: ; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: write, errnomem: write) 
# |           602: declare void @__sincosf_stret(ptr sret({ float, float }) align 4, float) #0 
# | check:17'0                                                                                X error: no match found
# |           603:  
# | check:17'0     ~
# |           604: ; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: write, errnomem: write) 
# | check:17'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |           605: declare void @__sincos_stret(ptr sret({ double, double }) align 8, double) #0 
# | check:17'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | check:17'1     ?                                                                              possible intended match
# |           606:  
# | check:17'0     ~
# |           607: declare void @sinhf(...) 
# | check:17'0     ~~~~~~~~~~~~~~~~~~~~~~~~~
# |           608:  
# | check:17'0     ~
# |           609: declare void @sinh(...) 
# | check:17'0     ~~~~~~~~~~~~~~~~~~~~~~~~
# |           610:  
# | check:17'0     ~
# |             .
# |             .
# |             .
# | >>>>>>
# `-----------------------------
# error: command failed with exit status: 1

Should be fixed by e5f191e

@llvm-ci
Copy link
Collaborator

llvm-ci commented Nov 4, 2025

LLVM Buildbot has detected a new failure on builder llvm-nvptx-nvidia-ubuntu running on as-builder-7 while building llvm at step 6 "test-build-unified-tree-check-llvm".

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

Here is the relevant piece of the build log for the reference
Step 6 (test-build-unified-tree-check-llvm) failure: test (failure)
******************** TEST 'LLVM :: Transforms/Util/DeclareRuntimeLibcalls/sincos_stret.ll' FAILED ********************
Exit Code: 1

Command Output (stdout):
--
# RUN: at line 1
/home/buildbot/worker/as-builder-7/llvm-nvptx-nvidia-ubuntu/build/bin/opt -S -passes=declare-runtime-libcalls -mtriple=x86_64-apple-macos10.9 < /home/buildbot/worker/as-builder-7/llvm-nvptx-nvidia-ubuntu/llvm-project/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/sincos_stret.ll | /home/buildbot/worker/as-builder-7/llvm-nvptx-nvidia-ubuntu/build/bin/FileCheck -check-prefixes=CHECK,X64 /home/buildbot/worker/as-builder-7/llvm-nvptx-nvidia-ubuntu/llvm-project/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/sincos_stret.ll
# executed command: /home/buildbot/worker/as-builder-7/llvm-nvptx-nvidia-ubuntu/build/bin/opt -S -passes=declare-runtime-libcalls -mtriple=x86_64-apple-macos10.9
# executed command: /home/buildbot/worker/as-builder-7/llvm-nvptx-nvidia-ubuntu/build/bin/FileCheck -check-prefixes=CHECK,X64 /home/buildbot/worker/as-builder-7/llvm-nvptx-nvidia-ubuntu/llvm-project/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/sincos_stret.ll
# RUN: at line 2
/home/buildbot/worker/as-builder-7/llvm-nvptx-nvidia-ubuntu/build/bin/opt -S -passes=declare-runtime-libcalls -mtriple=arm64-apple-macos10.9 < /home/buildbot/worker/as-builder-7/llvm-nvptx-nvidia-ubuntu/llvm-project/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/sincos_stret.ll | /home/buildbot/worker/as-builder-7/llvm-nvptx-nvidia-ubuntu/build/bin/FileCheck -check-prefixes=CHECK,STRUCT /home/buildbot/worker/as-builder-7/llvm-nvptx-nvidia-ubuntu/llvm-project/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/sincos_stret.ll
# executed command: /home/buildbot/worker/as-builder-7/llvm-nvptx-nvidia-ubuntu/build/bin/opt -S -passes=declare-runtime-libcalls -mtriple=arm64-apple-macos10.9
# .---command stderr------------
# | /home/buildbot/worker/as-builder-7/llvm-nvptx-nvidia-ubuntu/build/bin/opt: warning: failed to infer data layout: unable to get target for 'arm64-apple-macos10.9', see --version and --triple.
# | /home/buildbot/worker/as-builder-7/llvm-nvptx-nvidia-ubuntu/build/bin/opt: WARNING: failed to create target machine for 'arm64-apple-macos10.9': unable to get target for 'arm64-apple-macos10.9', see --version and --triple.
# `-----------------------------
# executed command: /home/buildbot/worker/as-builder-7/llvm-nvptx-nvidia-ubuntu/build/bin/FileCheck -check-prefixes=CHECK,STRUCT /home/buildbot/worker/as-builder-7/llvm-nvptx-nvidia-ubuntu/llvm-project/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/sincos_stret.ll
# RUN: at line 3
/home/buildbot/worker/as-builder-7/llvm-nvptx-nvidia-ubuntu/build/bin/opt -S -passes=declare-runtime-libcalls -mtriple=thumbv7k-apple-watchos2.0 < /home/buildbot/worker/as-builder-7/llvm-nvptx-nvidia-ubuntu/llvm-project/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/sincos_stret.ll | /home/buildbot/worker/as-builder-7/llvm-nvptx-nvidia-ubuntu/build/bin/FileCheck -check-prefixes=CHECK,STRUCT /home/buildbot/worker/as-builder-7/llvm-nvptx-nvidia-ubuntu/llvm-project/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/sincos_stret.ll
# executed command: /home/buildbot/worker/as-builder-7/llvm-nvptx-nvidia-ubuntu/build/bin/opt -S -passes=declare-runtime-libcalls -mtriple=thumbv7k-apple-watchos2.0
# .---command stderr------------
# | /home/buildbot/worker/as-builder-7/llvm-nvptx-nvidia-ubuntu/build/bin/opt: warning: failed to infer data layout: unable to get target for 'thumbv7k-apple-watchos2.0', see --version and --triple.
# | /home/buildbot/worker/as-builder-7/llvm-nvptx-nvidia-ubuntu/build/bin/opt: WARNING: failed to create target machine for 'thumbv7k-apple-watchos2.0': unable to get target for 'thumbv7k-apple-watchos2.0', see --version and --triple.
# `-----------------------------
# executed command: /home/buildbot/worker/as-builder-7/llvm-nvptx-nvidia-ubuntu/build/bin/FileCheck -check-prefixes=CHECK,STRUCT /home/buildbot/worker/as-builder-7/llvm-nvptx-nvidia-ubuntu/llvm-project/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/sincos_stret.ll
# RUN: at line 4
/home/buildbot/worker/as-builder-7/llvm-nvptx-nvidia-ubuntu/build/bin/opt -S -passes=declare-runtime-libcalls -mtriple=armv7-apple-ios7 < /home/buildbot/worker/as-builder-7/llvm-nvptx-nvidia-ubuntu/llvm-project/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/sincos_stret.ll | /home/buildbot/worker/as-builder-7/llvm-nvptx-nvidia-ubuntu/build/bin/FileCheck -check-prefix=SRET /home/buildbot/worker/as-builder-7/llvm-nvptx-nvidia-ubuntu/llvm-project/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/sincos_stret.ll
# executed command: /home/buildbot/worker/as-builder-7/llvm-nvptx-nvidia-ubuntu/build/bin/opt -S -passes=declare-runtime-libcalls -mtriple=armv7-apple-ios7
# .---command stderr------------
# | /home/buildbot/worker/as-builder-7/llvm-nvptx-nvidia-ubuntu/build/bin/opt: warning: failed to infer data layout: unable to get target for 'armv7-apple-ios7', see --version and --triple.
# | /home/buildbot/worker/as-builder-7/llvm-nvptx-nvidia-ubuntu/build/bin/opt: WARNING: failed to create target machine for 'armv7-apple-ios7': unable to get target for 'armv7-apple-ios7', see --version and --triple.
# `-----------------------------
# executed command: /home/buildbot/worker/as-builder-7/llvm-nvptx-nvidia-ubuntu/build/bin/FileCheck -check-prefix=SRET /home/buildbot/worker/as-builder-7/llvm-nvptx-nvidia-ubuntu/llvm-project/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/sincos_stret.ll
# .---command stderr------------
# | /home/buildbot/worker/as-builder-7/llvm-nvptx-nvidia-ubuntu/llvm-project/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/sincos_stret.ll:17:9: error: SRET: expected string not found in input
# | ; SRET: declare void @__sincos_stret(ptr sret({ double, double }) align 4, double) [[SINCOS_ATTRS:#[0-9]+]]
# |         ^
# | <stdin>:602:76: note: scanning from here
# | declare void @__sincosf_stret(ptr sret({ float, float }) align 4, float) #0
# |                                                                            ^
# | <stdin>:605:1: note: possible intended match here
# | declare void @__sincos_stret(ptr sret({ double, double }) align 8, double) #0
# | ^
# | 
# | Input file: <stdin>
# | Check file: /home/buildbot/worker/as-builder-7/llvm-nvptx-nvidia-ubuntu/llvm-project/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/sincos_stret.ll
# | 
# | -dump-input=help explains the following input dump.
# | 
# | Input was:
...

@llvm-ci
Copy link
Collaborator

llvm-ci commented Nov 4, 2025

LLVM Buildbot has detected a new failure on builder llvm-nvptx64-nvidia-ubuntu running on as-builder-7 while building llvm at step 6 "test-build-unified-tree-check-llvm".

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

Here is the relevant piece of the build log for the reference
Step 6 (test-build-unified-tree-check-llvm) failure: test (failure)
******************** TEST 'LLVM :: Transforms/Util/DeclareRuntimeLibcalls/sincos_stret.ll' FAILED ********************
Exit Code: 1

Command Output (stdout):
--
# RUN: at line 1
/home/buildbot/worker/as-builder-7/llvm-nvptx64-nvidia-ubuntu/build/bin/opt -S -passes=declare-runtime-libcalls -mtriple=x86_64-apple-macos10.9 < /home/buildbot/worker/as-builder-7/llvm-nvptx64-nvidia-ubuntu/llvm-project/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/sincos_stret.ll | /home/buildbot/worker/as-builder-7/llvm-nvptx64-nvidia-ubuntu/build/bin/FileCheck -check-prefixes=CHECK,X64 /home/buildbot/worker/as-builder-7/llvm-nvptx64-nvidia-ubuntu/llvm-project/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/sincos_stret.ll
# executed command: /home/buildbot/worker/as-builder-7/llvm-nvptx64-nvidia-ubuntu/build/bin/opt -S -passes=declare-runtime-libcalls -mtriple=x86_64-apple-macos10.9
# executed command: /home/buildbot/worker/as-builder-7/llvm-nvptx64-nvidia-ubuntu/build/bin/FileCheck -check-prefixes=CHECK,X64 /home/buildbot/worker/as-builder-7/llvm-nvptx64-nvidia-ubuntu/llvm-project/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/sincos_stret.ll
# RUN: at line 2
/home/buildbot/worker/as-builder-7/llvm-nvptx64-nvidia-ubuntu/build/bin/opt -S -passes=declare-runtime-libcalls -mtriple=arm64-apple-macos10.9 < /home/buildbot/worker/as-builder-7/llvm-nvptx64-nvidia-ubuntu/llvm-project/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/sincos_stret.ll | /home/buildbot/worker/as-builder-7/llvm-nvptx64-nvidia-ubuntu/build/bin/FileCheck -check-prefixes=CHECK,STRUCT /home/buildbot/worker/as-builder-7/llvm-nvptx64-nvidia-ubuntu/llvm-project/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/sincos_stret.ll
# executed command: /home/buildbot/worker/as-builder-7/llvm-nvptx64-nvidia-ubuntu/build/bin/opt -S -passes=declare-runtime-libcalls -mtriple=arm64-apple-macos10.9
# .---command stderr------------
# | /home/buildbot/worker/as-builder-7/llvm-nvptx64-nvidia-ubuntu/build/bin/opt: warning: failed to infer data layout: unable to get target for 'arm64-apple-macos10.9', see --version and --triple.
# | /home/buildbot/worker/as-builder-7/llvm-nvptx64-nvidia-ubuntu/build/bin/opt: WARNING: failed to create target machine for 'arm64-apple-macos10.9': unable to get target for 'arm64-apple-macos10.9', see --version and --triple.
# `-----------------------------
# executed command: /home/buildbot/worker/as-builder-7/llvm-nvptx64-nvidia-ubuntu/build/bin/FileCheck -check-prefixes=CHECK,STRUCT /home/buildbot/worker/as-builder-7/llvm-nvptx64-nvidia-ubuntu/llvm-project/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/sincos_stret.ll
# RUN: at line 3
/home/buildbot/worker/as-builder-7/llvm-nvptx64-nvidia-ubuntu/build/bin/opt -S -passes=declare-runtime-libcalls -mtriple=thumbv7k-apple-watchos2.0 < /home/buildbot/worker/as-builder-7/llvm-nvptx64-nvidia-ubuntu/llvm-project/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/sincos_stret.ll | /home/buildbot/worker/as-builder-7/llvm-nvptx64-nvidia-ubuntu/build/bin/FileCheck -check-prefixes=CHECK,STRUCT /home/buildbot/worker/as-builder-7/llvm-nvptx64-nvidia-ubuntu/llvm-project/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/sincos_stret.ll
# executed command: /home/buildbot/worker/as-builder-7/llvm-nvptx64-nvidia-ubuntu/build/bin/opt -S -passes=declare-runtime-libcalls -mtriple=thumbv7k-apple-watchos2.0
# .---command stderr------------
# | /home/buildbot/worker/as-builder-7/llvm-nvptx64-nvidia-ubuntu/build/bin/opt: warning: failed to infer data layout: unable to get target for 'thumbv7k-apple-watchos2.0', see --version and --triple.
# | /home/buildbot/worker/as-builder-7/llvm-nvptx64-nvidia-ubuntu/build/bin/opt: WARNING: failed to create target machine for 'thumbv7k-apple-watchos2.0': unable to get target for 'thumbv7k-apple-watchos2.0', see --version and --triple.
# `-----------------------------
# executed command: /home/buildbot/worker/as-builder-7/llvm-nvptx64-nvidia-ubuntu/build/bin/FileCheck -check-prefixes=CHECK,STRUCT /home/buildbot/worker/as-builder-7/llvm-nvptx64-nvidia-ubuntu/llvm-project/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/sincos_stret.ll
# RUN: at line 4
/home/buildbot/worker/as-builder-7/llvm-nvptx64-nvidia-ubuntu/build/bin/opt -S -passes=declare-runtime-libcalls -mtriple=armv7-apple-ios7 < /home/buildbot/worker/as-builder-7/llvm-nvptx64-nvidia-ubuntu/llvm-project/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/sincos_stret.ll | /home/buildbot/worker/as-builder-7/llvm-nvptx64-nvidia-ubuntu/build/bin/FileCheck -check-prefix=SRET /home/buildbot/worker/as-builder-7/llvm-nvptx64-nvidia-ubuntu/llvm-project/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/sincos_stret.ll
# executed command: /home/buildbot/worker/as-builder-7/llvm-nvptx64-nvidia-ubuntu/build/bin/opt -S -passes=declare-runtime-libcalls -mtriple=armv7-apple-ios7
# .---command stderr------------
# | /home/buildbot/worker/as-builder-7/llvm-nvptx64-nvidia-ubuntu/build/bin/opt: warning: failed to infer data layout: unable to get target for 'armv7-apple-ios7', see --version and --triple.
# | /home/buildbot/worker/as-builder-7/llvm-nvptx64-nvidia-ubuntu/build/bin/opt: WARNING: failed to create target machine for 'armv7-apple-ios7': unable to get target for 'armv7-apple-ios7', see --version and --triple.
# `-----------------------------
# executed command: /home/buildbot/worker/as-builder-7/llvm-nvptx64-nvidia-ubuntu/build/bin/FileCheck -check-prefix=SRET /home/buildbot/worker/as-builder-7/llvm-nvptx64-nvidia-ubuntu/llvm-project/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/sincos_stret.ll
# .---command stderr------------
# | /home/buildbot/worker/as-builder-7/llvm-nvptx64-nvidia-ubuntu/llvm-project/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/sincos_stret.ll:17:9: error: SRET: expected string not found in input
# | ; SRET: declare void @__sincos_stret(ptr sret({ double, double }) align 4, double) [[SINCOS_ATTRS:#[0-9]+]]
# |         ^
# | <stdin>:602:76: note: scanning from here
# | declare void @__sincosf_stret(ptr sret({ float, float }) align 4, float) #0
# |                                                                            ^
# | <stdin>:605:1: note: possible intended match here
# | declare void @__sincos_stret(ptr sret({ double, double }) align 8, double) #0
# | ^
# | 
# | Input file: <stdin>
# | Check file: /home/buildbot/worker/as-builder-7/llvm-nvptx64-nvidia-ubuntu/llvm-project/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/sincos_stret.ll
# | 
# | -dump-input=help explains the following input dump.
# | 
# | Input was:
...

@mahesh-attarde
Copy link
Contributor

@arsenm I have sincos related failure downstream, i am trying to fix in X86/WIN case. Do you intend to specialize this api for target in future?

@arsenm
Copy link
Contributor Author

arsenm commented Nov 7, 2025

@arsenm I have sincos related failure downstream, i am trying to fix in X86/WIN case. Do you intend to specialize this api for target in future?

It already is

@mahesh-attarde
Copy link
Contributor

@arsenm I have sincos related failure downstream, i am trying to fix in X86/WIN case. Do you intend to specialize this api for target in future?

It already is

I am refering to RuntimeLibcallsInfo::getFunctionTy function. It has Target specific "if" checks, i see you intend to use tablegen predicates for OS. What do you intend to do with say sse feature, since TargetTriple wont give that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants