From 66d3765c8d44af42b19fd21a48cb484658b0162e Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Mon, 20 Oct 2025 01:13:16 +0900 Subject: [PATCH 1/3] RuntimeLibcalls: Make sure _Unwind_Resume entries are mutually exclusive --- llvm/include/llvm/IR/RuntimeLibcalls.td | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/llvm/include/llvm/IR/RuntimeLibcalls.td b/llvm/include/llvm/IR/RuntimeLibcalls.td index ec16995a4f57c..9d394af83ee7f 100644 --- a/llvm/include/llvm/IR/RuntimeLibcalls.td +++ b/llvm/include/llvm/IR/RuntimeLibcalls.td @@ -59,6 +59,11 @@ def ExceptionModelIsNotNone : RuntimeLibcallPredicate< [{ExceptionModel != ExceptionHandling::None}] >; +def ExceptionModelHasUnwindResume : RuntimeLibcallPredicate< + [{ExceptionModel != ExceptionHandling::None && + ExceptionModel != ExceptionHandling::SjLj}] +>; + def ExceptionModelIsSjLj : RuntimeLibcallPredicate< [{ExceptionModel == ExceptionHandling::SjLj}] >; @@ -1153,8 +1158,10 @@ def __ssp_canary_word : RuntimeLibcallImpl; //===----------------------------------------------------------------------===// defvar ExceptionModelCalls = (add - LibcallImpls<(add DefaultExceptionHandlingLibcalls), + LibcallImpls<(add __cxa_end_cleanup), ExceptionModelIsNotNone>, + LibcallImpls<(add _Unwind_Resume), + ExceptionModelHasUnwindResume>, LibcallImpls<(add SjLjExceptionHandlingLibcalls), ExceptionModelIsSjLj> ); @@ -1396,8 +1403,10 @@ defset list WinArm64ECSjLjExceptionHandlingLibcalls = { } defvar ExceptionModelCallsArm64EC = (add - LibcallImpls<(add WinArm64ECDefaultExceptionHandlingLibcalls), + LibcallImpls<(add arm64ec___cxa_end_cleanup), ExceptionModelIsNotNone>, + LibcallImpls<(add arm64ec__Unwind_Resume), + ExceptionModelHasUnwindResume>, LibcallImpls<(add WinArm64ECSjLjExceptionHandlingLibcalls), ExceptionModelIsSjLj> ); From a84fbd5ff20026d1054f87f8a25a41f4a12eb8ae Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Wed, 22 Oct 2025 16:30:46 +0900 Subject: [PATCH 2/3] X86: Make sure compiler-rt div calls are not added for msvc The current predicate system is primitive, we ought to have a way to list a chain of alternatives. --- llvm/include/llvm/IR/RuntimeLibcalls.td | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/llvm/include/llvm/IR/RuntimeLibcalls.td b/llvm/include/llvm/IR/RuntimeLibcalls.td index 9d394af83ee7f..04e0ea3ee75a9 100644 --- a/llvm/include/llvm/IR/RuntimeLibcalls.td +++ b/llvm/include/llvm/IR/RuntimeLibcalls.td @@ -2452,6 +2452,11 @@ def _aullrem : RuntimeLibcallImpl; def _allmul : RuntimeLibcallImpl; } +// FIXME: Should have utility function to filter by known provider. +defvar WindowsDivRemMulLibcallOverrides = [ + __divdi3, __udivdi3, __moddi3, __umoddi3, __muldi3 +]; + //===----------------------------------------------------------------------===// // X86 Runtime Libcalls //===----------------------------------------------------------------------===// @@ -2473,7 +2478,7 @@ defvar X86_F128_Libcalls = LibcallImpls<(add LibmF128Libcalls, LibmF128FiniteLib defvar SinCosF32F64Libcalls = LibcallImpls<(add sincosf, sincos), hasSinCos_f32_f64>; defvar X86CommonLibcalls = - (add WinDefaultLibcallImpls, + (add (sub WinDefaultLibcallImpls, WindowsDivRemMulLibcallOverrides), DarwinSinCosStret, DarwinExp10, X86_F128_Libcalls, LibmHasSinCosF80, // FIXME: Depends on long double @@ -2496,10 +2501,15 @@ defvar Windows32DivRemMulCalls = LibcallsWithCC<(add WindowsDivRemMulLibcalls), X86_STDCALL, RuntimeLibcallPredicate<"TT.isWindowsMSVCEnvironment() || TT.isWindowsItaniumEnvironment()">>; +defvar NotWindows32DivRemMulCalls = + LibcallImpls<(add WindowsDivRemMulLibcallOverrides), + RuntimeLibcallPredicate<"!TT.isWindowsMSVCEnvironment() && !TT.isWindowsItaniumEnvironment()">>; + def X86_32SystemLibrary : SystemRuntimeLibrary; + NotWindows32DivRemMulCalls, + Windows32DivRemMulCalls)>; def X86_64SystemLibrary : SystemRuntimeLibrary Date: Thu, 23 Oct 2025 15:00:05 +0900 Subject: [PATCH 3/3] ARM: Avoid adding default libcalls overridden by AEABI functions Avoids adding alternative libcall impls for the same libcall. I'm not sure if the default names exist or not, or are just not preferred. compiler-rt appears to define aliases for all of these, so I'm not sure why we bother distinguishing these in the first place. --- llvm/include/llvm/IR/RuntimeLibcalls.td | 43 ++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/llvm/include/llvm/IR/RuntimeLibcalls.td b/llvm/include/llvm/IR/RuntimeLibcalls.td index 04e0ea3ee75a9..7be1b654ca727 100644 --- a/llvm/include/llvm/IR/RuntimeLibcalls.td +++ b/llvm/include/llvm/IR/RuntimeLibcalls.td @@ -1508,6 +1508,41 @@ def __aeabi_ddiv : RuntimeLibcallImpl; // CallingConv::ARM_AAPCS def __aeabi_dmul : RuntimeLibcallImpl; // CallingConv::ARM_AAPCS def __aeabi_dsub : RuntimeLibcallImpl; // CallingConv::ARM_AAPCS +defvar AEABIOverrides = [ + __eqsf2, __eqdf2, + __nesf2, __nedf2, + __ltsf2, __ltdf2, + __lesf2, __ledf2, + __gesf2, __gedf2, + __gtsf2, __gtdf2, + __unordsf2, __unorddf2, + + __addsf3, __adddf3, + __divsf3, __divdf3, + __mulsf3, __muldf3, + __subsf3, __subdf3, + + __fixdfsi, __fixunsdfsi, + __fixdfdi, __fixunsdfdi, + __fixsfsi, __fixunssfsi, + __fixsfdi, __fixunssfdi, + + __floatsidf, __floatunsidf, + __floatdidf, __floatundidf, + __floatsisf, __floatunsisf, + __floatdisf, __floatundisf, + + __muldi3, __ashldi3, + __lshrdi3, __ashrdi3, + + __divsi3, __udivsi3 + + // Half conversion cases are a mess and handled separately. + // __truncdfsf2, __truncdfhf2, + // __extendsfdf2, + // __truncsfhf2, __extendhfsf2 +]; + // Double-precision floating-point comparison helper functions // RTABI chapter 4.1.2, Table 3 def __aeabi_dcmpeq__oeq : RuntimeLibcallImpl; // CallingConv::ARM_AAPCS, CmpInst::ICMP_NE @@ -1793,7 +1828,8 @@ def ARMSystemLibrary : SystemRuntimeLibrary, LibmHasFrexpF32, LibmHasLdexpF32, LibmHasFrexpF128, LibmHasLdexpF128, @@ -1812,6 +1848,11 @@ def ARMSystemLibrary GNUEABIHalfConvertCalls, ARMDoubleToHalfCalls, + LibcallImpls<(add AEABIOverrides), + RuntimeLibcallPredicate<[{ + (!hasAEABILibcalls(TT) || !isAAPCS_ABI(TT, ABIName)) && + !TT.isOSWindows() + }]>>, // Use divmod compiler-rt calls for iOS 5.0 and later. LibcallImpls<(add __divmodsi4, __udivmodsi4), RuntimeLibcallPredicate<[{TT.isOSBinFormatMachO() &&