diff --git a/llvm/include/llvm/IR/RuntimeLibcalls.td b/llvm/include/llvm/IR/RuntimeLibcalls.td index b40b7f199f9e5..11e6127e0741d 100644 --- a/llvm/include/llvm/IR/RuntimeLibcalls.td +++ b/llvm/include/llvm/IR/RuntimeLibcalls.td @@ -35,6 +35,9 @@ def isNotOSLinuxAndNotOSOpenBSD : RuntimeLibcallPredicate< def isNotOSAIXAndNotOSOpenBSD : RuntimeLibcallPredicate< [{!TT.isOSAIX() && !TT.isOSOpenBSD()}]>; +def isNotPS : RuntimeLibcallPredicate< + [{!TT.isPS()}]>; + // OpenBSD uses __guard_local. AIX uses __ssp_canary_word, MSVC/Windows // Itanium uses __security_cookie def hasStackChkFail : RuntimeLibcallPredicate< @@ -149,6 +152,8 @@ foreach FPTy = ["F32", "F64", "F80", "F128", "PPCF128"] in { def ATAN_#FPTy : RuntimeLibcall; def ATAN2_#FPTy : RuntimeLibcall; def SINCOS_#FPTy : RuntimeLibcall; + def REMQUO_#FPTy : RuntimeLibcall; + def FDIM_#FPTy : RuntimeLibcall; } foreach FPTy = [ "F32", "F64" ] in { @@ -180,6 +185,12 @@ foreach FPTy = ["F32", "F64", "F80", "F128", "PPCF128"] in { def FREXP_#FPTy : RuntimeLibcall; def SINCOSPI_#FPTy : RuntimeLibcall; def MODF_#FPTy : RuntimeLibcall; + def NAN_#FPTy : RuntimeLibcall; + def NEXTTOWARD_#FPTy : RuntimeLibcall; + def REMAINDER_#FPTy : RuntimeLibcall; + def SCALBLN_#FPTy : RuntimeLibcall; + def SCALBN_#FPTy : RuntimeLibcall; + def TGAMMA_#FPTy : RuntimeLibcall; } defvar F32VectorSuffixes = ["V2F32", "V4F32", "V8F32", "V16F32", "NXV4F32"]; @@ -366,8 +377,11 @@ foreach FPTy = ["F32", "F64", "F128", "PPCF128"] in { // Memory def MEMCMP : RuntimeLibcall; def MEMCPY : RuntimeLibcall; +def MEMCPY_CHK : RuntimeLibcall; def MEMMOVE : RuntimeLibcall; +def MEMMOVE_CHK : RuntimeLibcall; def MEMSET : RuntimeLibcall; +def MEMSET_CHK : RuntimeLibcall; def CALLOC : RuntimeLibcall; def BZERO : RuntimeLibcall; def STRLEN : RuntimeLibcall; @@ -1034,6 +1048,38 @@ def modff : RuntimeLibcallImpl; def modf : RuntimeLibcallImpl; defm modfl : LibmLongDoubleLibCall; +def nanf : RuntimeLibcallImpl; +def nan : RuntimeLibcallImpl; +defm nanl : LibmLongDoubleLibCall; + +def nexttowardf : RuntimeLibcallImpl; +def nexttoward : RuntimeLibcallImpl; +defm nexttowardl : LibmLongDoubleLibCall; + +def remainderf : RuntimeLibcallImpl; +def remainder : RuntimeLibcallImpl; +defm remainderl : LibmLongDoubleLibCall; + +def remquof : RuntimeLibcallImpl; +def remquo : RuntimeLibcallImpl; +defm remquol : LibmLongDoubleLibCall; + +def fdimf : RuntimeLibcallImpl; +def fdim : RuntimeLibcallImpl; +defm fdiml : LibmLongDoubleLibCall; + +def scalbnf : RuntimeLibcallImpl; +def scalbn : RuntimeLibcallImpl; +defm scalbnl : LibmLongDoubleLibCall; + +def scalblnf : RuntimeLibcallImpl; +def scalbln : RuntimeLibcallImpl; +defm scalblnl : LibmLongDoubleLibCall; + +def tgammaf : RuntimeLibcallImpl; +def tgamma : RuntimeLibcallImpl; +defm tgammal : LibmLongDoubleLibCall; + // Floating point environment def fegetenv : RuntimeLibcallImpl; def fesetenv : RuntimeLibcallImpl; @@ -1051,6 +1097,10 @@ def memcpy : RuntimeLibcallImpl; def memmove : RuntimeLibcallImpl; def memset : RuntimeLibcallImpl; +def __memcpy_chk : RuntimeLibcallImpl; +def __memmove_chk : RuntimeLibcallImpl; +def __memset_chk : RuntimeLibcallImpl; + // DSEPass can emit calloc if it finds a pair of malloc/memset def calloc : RuntimeLibcallImpl; @@ -2584,8 +2634,10 @@ defvar X86_F128_Libcalls = LibcallImpls<(add LibmF128Libcalls, LibmF128FiniteLib defvar SinCosF32F64Libcalls = LibcallImpls<(add sincosf, sincos), hasSinCos_f32_f64>; +defvar MemChkLibcalls = [__memcpy_chk, __memset_chk, __memmove_chk]; + defvar X86CommonLibcalls = - (add (sub WinDefaultLibcallImpls, WindowsDivRemMulLibcallOverrides), + (add (sub WinDefaultLibcallImpls, WindowsDivRemMulLibcallOverrides, MemChkLibcalls), DarwinSinCosStret, DarwinExp10, X86_F128_Libcalls, LibmHasSinCosF80, // FIXME: Depends on long double @@ -2601,7 +2653,8 @@ defvar X86CommonLibcalls = // FIXME: MSVCRT doesn't have powi. The f128 case is added as a // hack for one test relying on it. __powitf2_f128, - DefaultStackProtector + DefaultStackProtector, + LibcallImpls<(add MemChkLibcalls), isNotPS> ); defvar Windows32DivRemMulCalls = diff --git a/llvm/lib/IR/RuntimeLibcalls.cpp b/llvm/lib/IR/RuntimeLibcalls.cpp index 12d050329a302..cbe7a7b9f77f4 100644 --- a/llvm/lib/IR/RuntimeLibcalls.cpp +++ b/llvm/lib/IR/RuntimeLibcalls.cpp @@ -135,8 +135,8 @@ 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}; + Attribute::MustProgress, Attribute::NoCallback, Attribute::NoFree, + Attribute::NoSync, Attribute::NoUnwind, Attribute::WillReturn}; static constexpr Attribute::AttrKind CommonPtrArgAttrs[] = { Attribute::NoAlias, Attribute::WriteOnly, Attribute::NonNull}; diff --git a/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/armpl.ll b/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/armpl.ll index e79e89c95c14a..c40cdf803474e 100644 --- a/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/armpl.ll +++ b/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/armpl.ll @@ -26,4 +26,4 @@ ; CHECK: declare aarch64_vector_pcs void @armpl_vsincosq_f64(<2 x double>, ptr noalias nonnull writeonly align 16, ptr noalias nonnull writeonly align 16) [[ATTRS]] -; CHECK: attributes [[ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(argmem: write) } +; CHECK: attributes [[ATTRS]] = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: write) } diff --git a/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/basic.ll b/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/basic.ll index 4c8c829a59f3c..db0cc24c287bc 100644 --- a/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/basic.ll +++ b/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/basic.ll @@ -12,13 +12,49 @@ define float @sinf(float %x) { ; CHECK: declare void @_Unwind_Resume(...) +; CHECK: declare void @__memcpy_chk(...) +; CHECK: declare void @__memmove_chk(...) +; CHECK: declare void @__memset_chk(...) + ; CHECK: declare void @__umodti3(...) ; CHECK: declare void @acosf(...) +; CHECK: declare void @fdim(...) +; CHECK: declare void @fdimf(...) +; CHECK: declare void @fdiml(...) + +; CHECK: declare void @nan(...) +; CHECK: declare void @nanf(...) +; CHECK: declare void @nanl(...) + +; CHECK: declare void @nexttoward(...) +; CHECK: declare void @nexttowardf(...) +; CHECK: declare void @nexttowardl(...) + +; CHECK: declare void @remainder(...) +; CHECK: declare void @remainderf(...) +; CHECK: declare void @remainderl(...) + +; CHECK: declare void @remquo(...) +; CHECK: declare void @remquof(...) +; CHECK: declare void @remquol(...) + +; CHECK: declare void @scalbln(...) +; CHECK: declare void @scalblnf(...) +; CHECK: declare void @scalblnl(...) + +; CHECK: declare void @scalbn(...) +; CHECK: declare void @scalbnf(...) +; CHECK: declare void @scalbnl(...) + ; CHECK: declare nofpclass(ninf nsub nnorm) double @sqrt(double) [[SQRT_ATTRS:#[0-9]+]] ; CHECK: declare nofpclass(ninf nsub nnorm) float @sqrtf(float) [[SQRT_ATTRS:#[0-9]+]] +; CHECK: declare void @tgamma(...) +; CHECK: declare void @tgammaf(...) +; CHECK: declare void @tgammal(...) + ; CHECK: declare void @truncl(...) diff --git a/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/merge_attributes.ll b/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/merge_attributes.ll index ffbf11d4106dc..af876a7988d4e 100644 --- a/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/merge_attributes.ll +++ b/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/merge_attributes.ll @@ -8,4 +8,4 @@ define noundef nofpclass(nan) float @sqrtf(float %x) "foo" { ; 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" } +; CHECK: attributes [[SQRT_ATTR]] = { mustprogress nocallback nofree nosync nounwind willreturn memory(errnomem: write) "foo" } diff --git a/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/ps.ll b/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/ps.ll new file mode 100644 index 0000000000000..bcdcc63400f72 --- /dev/null +++ b/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/ps.ll @@ -0,0 +1,6 @@ +; RUN: opt -S -passes=declare-runtime-libcalls -mtriple=x86_64-scei-ps4 < %s | FileCheck %s +; RUN: opt -S -passes=declare-runtime-libcalls -mtriple=x86_64-scei-ps5 < %s | FileCheck %s + +; CHECK-NOT: __memcpy_chk +; CHECK-NOT: __memset_chk +; CHECK-NOT: __memmove_chk diff --git a/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/sincos_stret.ll b/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/sincos_stret.ll index 57cb016bcb7f3..c7da97d410a9f 100644 --- a/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/sincos_stret.ll +++ b/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/sincos_stret.ll @@ -16,8 +16,8 @@ ; SRET: declare void @__sincos_stret(ptr sret({ double, double }) align 4, double) [[SINCOS_ATTRS:#[0-9]+]] ; SRET: declare void @__sincosf_stret(ptr sret({ float, float }) align 4, float) [[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) } +; CHECK: attributes [[SINCOS_ATTRS]] = { mustprogress nocallback nofree nosync nounwind willreturn memory(errnomem: write) } +; SRET: attributes [[SINCOS_ATTRS]] = { mustprogress 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/sleef.ll b/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/sleef.ll index ef2481111087f..e0d8489f7b94e 100644 --- a/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/sleef.ll +++ b/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/sleef.ll @@ -25,4 +25,4 @@ ; CHECK: declare void @_ZGVsNxvl8l8_sincospi(, ptr noalias nonnull writeonly align 16, ptr noalias nonnull writeonly align 16) [[ATTRS]] -; CHECK: attributes [[ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(argmem: write) } +; CHECK: attributes [[ATTRS]] = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: write) }