Skip to content

Conversation

@arsenm
Copy link
Contributor

@arsenm arsenm commented Nov 8, 2025

This is one of the easier cases to comprehend in TargetLibraryInfo's
setup.

Copy link
Contributor Author

arsenm commented Nov 8, 2025

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@arsenm arsenm requested a review from topperc November 8, 2025 03:29
@arsenm arsenm marked this pull request as ready for review November 8, 2025 03:29
@llvmbot
Copy link
Member

llvmbot commented Nov 8, 2025

@llvm/pr-subscribers-llvm-selectiondag
@llvm/pr-subscribers-llvm-ir

@llvm/pr-subscribers-llvm-transforms

Author: Matt Arsenault (arsenm)

Changes

This is one of the easier cases to comprehend in TargetLibraryInfo's
setup.


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

3 Files Affected:

  • (modified) llvm/include/llvm/IR/RuntimeLibcalls.h (+10)
  • (modified) llvm/include/llvm/IR/RuntimeLibcalls.td (+9-3)
  • (added) llvm/test/Transforms/Util/DeclareRuntimeLibcalls/darwin.ll (+22)
diff --git a/llvm/include/llvm/IR/RuntimeLibcalls.h b/llvm/include/llvm/IR/RuntimeLibcalls.h
index 0afe32a4ecc3c..adc0c777f0030 100644
--- a/llvm/include/llvm/IR/RuntimeLibcalls.h
+++ b/llvm/include/llvm/IR/RuntimeLibcalls.h
@@ -209,6 +209,16 @@ struct RuntimeLibcallsInfo {
     return true;
   }
 
+  static bool darwinHasMemsetPattern(const Triple &TT) {
+    // memset_pattern{4,8,16} is only available on iOS 3.0 and Mac OS X 10.5 and
+    // later. All versions of watchOS support it.
+    if (TT.isMacOSX())
+      return !TT.isMacOSXVersionLT(10, 5);
+    if (TT.isiOS())
+      return !TT.isOSVersionLT(3, 0);
+    return TT.isWatchOS();
+  }
+
   static bool hasAEABILibcalls(const Triple &TT) {
     return TT.isTargetAEABI() || TT.isTargetGNUAEABI() ||
            TT.isTargetMuslAEABI() || TT.isOSFuchsia() || TT.isAndroid();
diff --git a/llvm/include/llvm/IR/RuntimeLibcalls.td b/llvm/include/llvm/IR/RuntimeLibcalls.td
index 5f52014247060..d67aeb3757ea9 100644
--- a/llvm/include/llvm/IR/RuntimeLibcalls.td
+++ b/llvm/include/llvm/IR/RuntimeLibcalls.td
@@ -50,6 +50,7 @@ def isWindowsMSVCOrItaniumEnvironment : RuntimeLibcallPredicate<
 def isGNUEnvironment : RuntimeLibcallPredicate<"TT.isGNUEnvironment()">;
 def darwinHasSinCosStret : RuntimeLibcallPredicate<"darwinHasSinCosStret(TT)">;
 def darwinHasExp10 : RuntimeLibcallPredicate<"darwinHasExp10(TT)">;
+def darwinHasMemsetPattern : RuntimeLibcallPredicate<[{darwinHasMemsetPattern(TT)}]>;
 
 def hasExp10 : RuntimeLibcallPredicate<[{!TT.isOSDarwin()}]>;
 
@@ -1976,6 +1977,11 @@ defvar DarwinSinCosStret = LibcallImpls<(add __sincosf_stret, __sincos_stret,
                                         darwinHasSinCosStret>;
 defvar DarwinExp10 = LibcallImpls<(add __exp10f, __exp10), darwinHasExp10>;
 
+defvar DarwinMemsetPattern = LibcallImpls<(add memset_pattern4,
+                                               memset_pattern8,
+                                               memset_pattern16),
+                                               darwinHasMemsetPattern>;
+
 defvar SecurityCheckCookieIfWinMSVC =
     LibcallImpls<(add __security_check_cookie, __security_cookie),
                  isWindowsMSVCOrItaniumEnvironment>;
@@ -2133,7 +2139,7 @@ def AArch64SystemLibrary : SystemRuntimeLibrary<
        AArch64LibcallImpls,
        LibcallImpls<(add Int128RTLibcalls), isAArch64_ILP64>,
        LibcallImpls<(add bzero), isOSDarwin>,
-       DarwinExp10, DarwinSinCosStret,
+       DarwinExp10, DarwinSinCosStret, DarwinMemsetPattern,
        LibmHasSinCosF32, LibmHasSinCosF64, LibmHasSinCosF128,
        DefaultLibmExp10,
        DefaultStackProtector,
@@ -2603,7 +2609,7 @@ def ARMSystemLibrary
            WindowARMFPIntCasts,
            SecurityCheckCookieIfWinMSVC,
            AEABIDivRemCalls,
-           DarwinSinCosStret, DarwinExp10,
+           DarwinSinCosStret, DarwinExp10, DarwinMemsetPattern,
            LibmHasSinCosF32, LibmHasSinCosF64, LibmHasSinCosF128,
            DefaultLibmExp10,
 
@@ -3288,7 +3294,7 @@ defvar MemChkLibcalls = [__memcpy_chk, __memset_chk, __memmove_chk];
 
 defvar X86CommonLibcalls =
   (add (sub WinDefaultLibcallImpls, WindowsDivRemMulLibcallOverrides, MemChkLibcalls),
-       DarwinSinCosStret, DarwinExp10,
+       DarwinSinCosStret, DarwinExp10, DarwinMemsetPattern,
        X86_F128_Libcalls,
        LibmHasSinCosF80, // FIXME: Depends on long double
        SinCosF32F64Libcalls,
diff --git a/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/darwin.ll b/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/darwin.ll
new file mode 100644
index 0000000000000..bc8a24cc51bf7
--- /dev/null
+++ b/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/darwin.ll
@@ -0,0 +1,22 @@
+; REQUIRES: aarch64-registered-target, arm-registered-target, x86-registered-target
+
+; RUN: opt -S -passes=declare-runtime-libcalls -mtriple=i386-apple-macosx10.5 < %s | FileCheck -check-prefix=HAS-MEMSET-PATTERN %s
+; RUN: opt -S -passes=declare-runtime-libcalls -mtriple=i386-apple-macosx10.4 < %s | FileCheck -check-prefix=NO-MEMSET-PATTERN %s
+
+; RUN: opt -S -passes=declare-runtime-libcalls -mtriple=x86_64-apple-macosx10.5 < %s | FileCheck -check-prefix=HAS-MEMSET-PATTERN %s
+; RUN: opt -S -passes=declare-runtime-libcalls -mtriple=x86_64-apple-macosx10.4 < %s | FileCheck -check-prefix=NO-MEMSET-PATTERN %s
+
+; RUN: opt -S -passes=declare-runtime-libcalls -mtriple=arm64-apple-ios3 < %s | FileCheck -check-prefix=HAS-MEMSET-PATTERN %s
+; RUN: opt -S -passes=declare-runtime-libcalls -mtriple=arm64-apple-ios2 < %s | FileCheck -check-prefix=NO-MEMSET-PATTERN %s
+
+; RUN: opt -S -passes=declare-runtime-libcalls -mtriple=thumbv7-apple-ios3 < %s | FileCheck -check-prefix=HAS-MEMSET-PATTERN %s
+; RUN: opt -S -passes=declare-runtime-libcalls -mtriple=thumbv7-apple-ios2 < %s | FileCheck -check-prefix=NO-MEMSET-PATTERN %s
+
+ ; RUN: opt -S -passes=declare-runtime-libcalls  -mtriple=arm64_32-apple-watchos < %s | FileCheck -check-prefix=HAS-MEMSET-PATTERN %s
+; RUN: opt -S -passes=declare-runtime-libcalls -mtriple=armv7k-apple-watchos < %s | FileCheck -check-prefix=HAS-MEMSET-PATTERN %s
+
+; HAS-MEMSET-PATTERN: declare void @memset_pattern16(...)
+; HAS-MEMSET-PATTERN: declare void @memset_pattern4(...)
+; HAS-MEMSET-PATTERN: declare void @memset_pattern8(...)
+
+; NO-MEMSET-PATTERN-NOT: memset_pattern

@arsenm arsenm force-pushed the users/arsenm/runtime-libcalls/add-memset-pattern-darwin branch from 7fc2bd9 to 640cf80 Compare November 8, 2025 03:42
@arsenm arsenm force-pushed the users/arsenm/runtime-libcalls/add-more-entries-from-targetlibraryinfo branch from 06d0094 to a25d7fe Compare November 10, 2025 18:18
@arsenm arsenm force-pushed the users/arsenm/runtime-libcalls/add-memset-pattern-darwin branch from 640cf80 to 6ee0ec3 Compare November 10, 2025 18:18
@arsenm arsenm force-pushed the users/arsenm/runtime-libcalls/add-more-entries-from-targetlibraryinfo branch from a25d7fe to 61c70b5 Compare November 10, 2025 19:22
@arsenm arsenm force-pushed the users/arsenm/runtime-libcalls/add-memset-pattern-darwin branch 2 times, most recently from 28d3aa9 to abfd3b2 Compare November 12, 2025 00:57
@arsenm arsenm force-pushed the users/arsenm/runtime-libcalls/add-more-entries-from-targetlibraryinfo branch from 61c70b5 to d787eb1 Compare November 12, 2025 00:57
@arsenm arsenm force-pushed the users/arsenm/runtime-libcalls/add-memset-pattern-darwin branch from abfd3b2 to 9150bc5 Compare November 12, 2025 02:11
@arsenm arsenm force-pushed the users/arsenm/runtime-libcalls/add-more-entries-from-targetlibraryinfo branch from d787eb1 to 5c9ed73 Compare November 12, 2025 02:11
This is one of the easier cases to comprehend in TargetLibraryInfo's
setup.
@arsenm arsenm force-pushed the users/arsenm/runtime-libcalls/add-memset-pattern-darwin branch from 9150bc5 to 4ab6bb5 Compare November 12, 2025 03:24
@arsenm arsenm force-pushed the users/arsenm/runtime-libcalls/add-more-entries-from-targetlibraryinfo branch from 5c9ed73 to 03dc81d Compare November 12, 2025 03:24
Copy link
Contributor

@fhahn fhahn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants