Skip to content

XCore: Declare libcalls used for align 4 memcpy #144976

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

arsenm
Copy link
Contributor

@arsenm arsenm commented Jun 20, 2025

This usage was hidden in XCoreSelectionDAGInfo and bypassed
the usual libcall system, so define these for later use.

@llvmbot
Copy link
Member

llvmbot commented Jun 20, 2025

@llvm/pr-subscribers-llvm-ir

Author: Matt Arsenault (arsenm)

Changes

This usage was hidden in XCoreSelectionDAGInfo and bypassed
the usual libcall system, so define these for later use.


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

3 Files Affected:

  • (modified) llvm/include/llvm/IR/RuntimeLibcalls.td (+9)
  • (modified) llvm/lib/IR/RuntimeLibcalls.cpp (+3)
  • (modified) llvm/lib/Target/XCore/XCoreSelectionDAGInfo.cpp (+8-5)
diff --git a/llvm/include/llvm/IR/RuntimeLibcalls.td b/llvm/include/llvm/IR/RuntimeLibcalls.td
index 2efe823a760db..57ad6f09e8b57 100644
--- a/llvm/include/llvm/IR/RuntimeLibcalls.td
+++ b/llvm/include/llvm/IR/RuntimeLibcalls.td
@@ -371,6 +371,9 @@ def AEABI_MEMCLR8 : RuntimeLibcall;
 // Hexagon calls
 def HEXAGON_MEMCPY_LIKELY_ALIGNED_MIN32BYTES_MULT8BYTES : RuntimeLibcall;
 
+// XCore calls
+def MEMCPY_ALIGN_4 : RuntimeLibcall;
+
 //--------------------------------------------------------------------
 // Define implementation default libcalls
 //--------------------------------------------------------------------
@@ -1544,6 +1547,12 @@ def _allrem : RuntimeLibcallImpl<SREM_I64>; // CallingConv::X86_StdCall
 def _aullrem : RuntimeLibcallImpl<UREM_I64>; // CallingConv::X86_StdCall
 def _allmul : RuntimeLibcallImpl<MUL_I64>; // CallingConv::X86_StdCall
 
+//===----------------------------------------------------------------------===//
+// XCore Runtime Libcalls
+//===----------------------------------------------------------------------===//
+
+def __memcpy_4 : RuntimeLibcallImpl<MEMCPY_ALIGN_4>;
+
 //===----------------------------------------------------------------------===//
 // ZOS Runtime Libcalls
 //===----------------------------------------------------------------------===//
diff --git a/llvm/lib/IR/RuntimeLibcalls.cpp b/llvm/lib/IR/RuntimeLibcalls.cpp
index 873ee6b509e2d..0f92371f05529 100644
--- a/llvm/lib/IR/RuntimeLibcalls.cpp
+++ b/llvm/lib/IR/RuntimeLibcalls.cpp
@@ -627,4 +627,7 @@ void RuntimeLibcallsInfo::initLibcalls(const Triple &TT,
 
   if (TT.isSystemZ() && TT.isOSzOS())
     setZOSLibCallNameOverrides();
+
+  if (TT.getArch() == Triple::ArchType::xcore)
+    setLibcallImpl(RTLIB::MEMCPY_ALIGN_4, RTLIB::__memcpy_4);
 }
diff --git a/llvm/lib/Target/XCore/XCoreSelectionDAGInfo.cpp b/llvm/lib/Target/XCore/XCoreSelectionDAGInfo.cpp
index bc34ab4319690..1bd92a2b49475 100644
--- a/llvm/lib/Target/XCore/XCoreSelectionDAGInfo.cpp
+++ b/llvm/lib/Target/XCore/XCoreSelectionDAGInfo.cpp
@@ -39,14 +39,17 @@ SDValue XCoreSelectionDAGInfo::EmitTargetCodeForMemcpy(
     Entry.Node = Src; Args.push_back(Entry);
     Entry.Node = Size; Args.push_back(Entry);
 
+    const char *MemcpyAlign4Name = TLI.getLibcallName(RTLIB::MEMCPY_ALIGN_4);
+    CallingConv::ID CC = TLI.getLibcallCallingConv(RTLIB::MEMCPY_ALIGN_4);
+
     TargetLowering::CallLoweringInfo CLI(DAG);
     CLI.setDebugLoc(dl)
         .setChain(Chain)
-        .setLibCallee(TLI.getLibcallCallingConv(RTLIB::MEMCPY),
-                      Type::getVoidTy(*DAG.getContext()),
-                      DAG.getExternalSymbol(
-                          "__memcpy_4", TLI.getPointerTy(DAG.getDataLayout())),
-                      std::move(Args))
+        .setLibCallee(
+            CC, Type::getVoidTy(*DAG.getContext()),
+            DAG.getExternalSymbol(MemcpyAlign4Name,
+                                  TLI.getPointerTy(DAG.getDataLayout())),
+            std::move(Args))
         .setDiscardResult();
 
     std::pair<SDValue,SDValue> CallResult = TLI.LowerCallTo(CLI);

Copy link
Contributor

@nigelp-xmos nigelp-xmos left a comment

Choose a reason for hiding this comment

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

LGTM

@arsenm arsenm force-pushed the users/arsenm/xcore/add-runtime-libcall-definitions-special-memcpy branch from 99598fb to e6005bd Compare June 23, 2025 13:27
@arsenm arsenm force-pushed the users/arsenm/hexagon/add-libcall-definitions-special-memcpy branch from a845b0e to 2a403de Compare June 23, 2025 13:27
@arsenm arsenm force-pushed the users/arsenm/xcore/add-runtime-libcall-definitions-special-memcpy branch from e6005bd to 5c9eff4 Compare June 25, 2025 12:42
@arsenm arsenm force-pushed the users/arsenm/hexagon/add-libcall-definitions-special-memcpy branch from 2a403de to 4632467 Compare June 25, 2025 12:42
@arsenm arsenm force-pushed the users/arsenm/xcore/add-runtime-libcall-definitions-special-memcpy branch from 5c9eff4 to 6854ef6 Compare June 27, 2025 07:31
@arsenm arsenm force-pushed the users/arsenm/hexagon/add-libcall-definitions-special-memcpy branch from 4632467 to d3f44e8 Compare June 27, 2025 07:32
Copy link
Contributor Author

arsenm commented Jun 27, 2025

Merge activity

  • Jun 27, 8:33 AM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Jun 27, 8:47 AM UTC: Graphite rebased this pull request as part of a merge.
  • Jun 27, 8:50 AM UTC: @arsenm merged this pull request with Graphite.

@arsenm arsenm force-pushed the users/arsenm/hexagon/add-libcall-definitions-special-memcpy branch from d3f44e8 to 944736b Compare June 27, 2025 08:44
Base automatically changed from users/arsenm/hexagon/add-libcall-definitions-special-memcpy to main June 27, 2025 08:46
This usage was hidden in XCoreSelectionDAGInfo and bypassed
the usual libcall system, so define these for later use.
@arsenm arsenm force-pushed the users/arsenm/xcore/add-runtime-libcall-definitions-special-memcpy branch from 6854ef6 to 2fdc886 Compare June 27, 2025 08:46
@arsenm arsenm merged commit 779f724 into main Jun 27, 2025
5 of 7 checks passed
@arsenm arsenm deleted the users/arsenm/xcore/add-runtime-libcall-definitions-special-memcpy branch June 27, 2025 08:50
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.

3 participants