Skip to content

RuntimeLibcalls: Invert handling of 64-bit only libcalls #148571

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

Conversation

arsenm
Copy link
Contributor

@arsenm arsenm commented Jul 14, 2025

Switch the default set to exclude these conditionally available
calls, so they are opt-in instead of opt-out.

@arsenm arsenm added the llvm:ir label Jul 14, 2025 — with Graphite App
@llvmbot
Copy link
Member

llvmbot commented Jul 14, 2025

@llvm/pr-subscribers-llvm-ir

Author: Matt Arsenault (arsenm)

Changes

Switch the default set to exclude these conditionally available
calls, so they are opt-in instead of opt-out.


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

2 Files Affected:

  • (modified) llvm/include/llvm/IR/RuntimeLibcalls.td (+5-5)
  • (modified) llvm/lib/IR/RuntimeLibcalls.cpp (+11-9)
diff --git a/llvm/include/llvm/IR/RuntimeLibcalls.td b/llvm/include/llvm/IR/RuntimeLibcalls.td
index 53eea97bf1ea9..b0651a8ac9920 100644
--- a/llvm/include/llvm/IR/RuntimeLibcalls.td
+++ b/llvm/include/llvm/IR/RuntimeLibcalls.td
@@ -439,26 +439,21 @@ let IsDefault = true in {
 def __ashlhi3 : RuntimeLibcallImpl<SHL_I16>;
 def __ashlsi3 : RuntimeLibcallImpl<SHL_I32>;
 def __ashldi3 : RuntimeLibcallImpl<SHL_I64>;
-def __ashlti3 : RuntimeLibcallImpl<SHL_I128>;
 
 def __lshrhi3 : RuntimeLibcallImpl<SRL_I16>;
 def __lshrsi3 : RuntimeLibcallImpl<SRL_I32>;
 def __lshrdi3 : RuntimeLibcallImpl<SRL_I64>;
-def __lshrti3 : RuntimeLibcallImpl<SRL_I128>;
 
 def __ashrhi3 : RuntimeLibcallImpl<SRA_I16>;
 def __ashrsi3 : RuntimeLibcallImpl<SRA_I32>;
 def __ashrdi3 : RuntimeLibcallImpl<SRA_I64>;
-def __ashrti3 : RuntimeLibcallImpl<SRA_I128>;
 
 def __mulqi3 : RuntimeLibcallImpl<MUL_I8>;
 def __mulhi3 : RuntimeLibcallImpl<MUL_I16>;
 def __mulsi3 : RuntimeLibcallImpl<MUL_I32>;
 def __muldi3 : RuntimeLibcallImpl<MUL_I64>;
-def __multi3 : RuntimeLibcallImpl<MUL_I128>;
 
 def __mulosi4 : RuntimeLibcallImpl<MULO_I32>;
-def __mulodi4 : RuntimeLibcallImpl<MULO_I64>;
 
 def __divqi3 : RuntimeLibcallImpl<SDIV_I8>;
 def __divhi3 : RuntimeLibcallImpl<SDIV_I16>;
@@ -938,6 +933,11 @@ def calloc : RuntimeLibcallImpl<CALLOC>;
 // compiler-rt, not available for most architectures
 //--------------------------------------------------------------------
 
+def __ashlti3 : RuntimeLibcallImpl<SHL_I128>;
+def __lshrti3 : RuntimeLibcallImpl<SRL_I128>;
+def __ashrti3 : RuntimeLibcallImpl<SRA_I128>;
+def __multi3 : RuntimeLibcallImpl<MUL_I128>;
+def __mulodi4 : RuntimeLibcallImpl<MULO_I64>;
 def __muloti4 : RuntimeLibcallImpl<MULO_I128>;
 
 //--------------------------------------------------------------------
diff --git a/llvm/lib/IR/RuntimeLibcalls.cpp b/llvm/lib/IR/RuntimeLibcalls.cpp
index 3dd894ad6c50e..004d2758cb963 100644
--- a/llvm/lib/IR/RuntimeLibcalls.cpp
+++ b/llvm/lib/IR/RuntimeLibcalls.cpp
@@ -139,6 +139,10 @@ void RuntimeLibcallsInfo::initLibcalls(const Triple &TT,
                                        EABI EABIVersion, StringRef ABIName) {
   setTargetRuntimeLibcallSets(TT, FloatABI);
 
+  // Early exit for targets that have fully ported to tablegen.
+  if (TT.isAMDGPU() || TT.isNVPTX())
+    return;
+
   // Use the f128 variants of math functions on x86
   if (TT.isX86() && TT.isGNUEnvironment())
     setLongDoubleIsF128Libm(*this, /*FiniteOnlyFuncs=*/true);
@@ -241,15 +245,13 @@ void RuntimeLibcallsInfo::initLibcalls(const Triple &TT,
   if (TT.isARM() || TT.isThumb())
     setARMLibcallNames(*this, TT, FloatABI, EABIVersion);
 
-  if (!TT.isWasm()) {
-    // These libcalls are only available in compiler-rt, not libgcc.
-    if (TT.isArch32Bit()) {
-      setLibcallImpl(RTLIB::SHL_I128, RTLIB::Unsupported);
-      setLibcallImpl(RTLIB::SRL_I128, RTLIB::Unsupported);
-      setLibcallImpl(RTLIB::SRA_I128, RTLIB::Unsupported);
-      setLibcallImpl(RTLIB::MUL_I128, RTLIB::Unsupported);
-      setLibcallImpl(RTLIB::MULO_I64, RTLIB::Unsupported);
-    }
+  // These libcalls are only available in compiler-rt, not libgcc.
+  if (TT.isArch64Bit()) {
+    setLibcallImpl(RTLIB::SHL_I128, RTLIB::__ashlti3);
+    setLibcallImpl(RTLIB::SRL_I128, RTLIB::__lshrti3);
+    setLibcallImpl(RTLIB::SRA_I128, RTLIB::__ashrti3);
+    setLibcallImpl(RTLIB::MUL_I128, RTLIB::__multi3);
+    setLibcallImpl(RTLIB::MULO_I64, RTLIB::__mulodi4);
   }
 
   if (TT.getArch() == Triple::ArchType::msp430) {

@arsenm arsenm marked this pull request as ready for review July 14, 2025 06:40
@arsenm arsenm force-pushed the users/arsenm/runtime-libcalls/switch-compiler-rt-64-libcalls-opt-in branch from 650ac1e to 2f195de Compare July 14, 2025 06:55
def __ashlti3 : RuntimeLibcallImpl<SHL_I128>;
def __lshrti3 : RuntimeLibcallImpl<SRL_I128>;
def __ashrti3 : RuntimeLibcallImpl<SRA_I128>;
def __multi3 : RuntimeLibcallImpl<MUL_I128>;
Copy link
Contributor

Choose a reason for hiding this comment

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

Not in the right category? Only __mulodi4 is compiler-rt only, the others are 64-bit only?

Also shouldn't the listremove for these get dropped now?

@arsenm arsenm force-pushed the users/arsenm/runtime-libcalls/remove-muloti4-default-calls branch from 18ca551 to 19c269f Compare July 14, 2025 10:15
@arsenm arsenm force-pushed the users/arsenm/runtime-libcalls/switch-compiler-rt-64-libcalls-opt-in branch from 2f195de to e933483 Compare July 14, 2025 10:15
Copy link
Contributor

@nikic nikic left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor Author

arsenm commented Jul 14, 2025

Merge activity

  • Jul 14, 3:51 PM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Jul 14, 3:56 PM UTC: Graphite rebased this pull request as part of a merge.
  • Jul 14, 3:59 PM UTC: @arsenm merged this pull request with Graphite.

@arsenm arsenm force-pushed the users/arsenm/runtime-libcalls/remove-muloti4-default-calls branch from 19c269f to 953c476 Compare July 14, 2025 15:53
Base automatically changed from users/arsenm/runtime-libcalls/remove-muloti4-default-calls to main July 14, 2025 15:56
arsenm added 2 commits July 14, 2025 15:56
Switch the default set to exclude these conditionally available
calls, so they are opt-in instead of opt-out.
@arsenm arsenm force-pushed the users/arsenm/runtime-libcalls/switch-compiler-rt-64-libcalls-opt-in branch from e933483 to b1cc318 Compare July 14, 2025 15:56
@arsenm arsenm merged commit 301a1d5 into main Jul 14, 2025
7 of 9 checks passed
@arsenm arsenm deleted the users/arsenm/runtime-libcalls/switch-compiler-rt-64-libcalls-opt-in branch July 14, 2025 15:59
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.

3 participants