diff --git a/llvm/include/llvm/TargetParser/Triple.h b/llvm/include/llvm/TargetParser/Triple.h --- a/llvm/include/llvm/TargetParser/Triple.h +++ b/llvm/include/llvm/TargetParser/Triple.h @@ -288,6 +288,13 @@ Wasm, XCOFF, }; + enum RTLibType { + UnknownRTLib, + + COMPILER_RT, + LIB_GCC, + WINDOWS_RT, + }; private: std::string Data; @@ -363,6 +370,9 @@ /// Get the parsed operating system type of this triple. OSType getOS() const { return OS; } + /// Get the rtlib implied by this triple. + RTLibType getRTLib() const; + /// Does this triple have the optional environment (fourth) component? bool hasEnvironment() const { return getEnvironmentName() != ""; diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp --- a/llvm/lib/Target/X86/X86ISelLowering.cpp +++ b/llvm/lib/Target/X86/X86ISelLowering.cpp @@ -2307,10 +2307,12 @@ setLibcallName(RTLIB::SRA_I128, nullptr); setLibcallName(RTLIB::MUL_I128, nullptr); // The MULO libcall is not part of libgcc, only compiler-rt. - setLibcallName(RTLIB::MULO_I64, nullptr); + if (Subtarget.getTargetTriple().getRTLib() != Triple::COMPILER_RT) + setLibcallName(RTLIB::MULO_I64, nullptr); } // The MULO libcall is not part of libgcc, only compiler-rt. - setLibcallName(RTLIB::MULO_I128, nullptr); + if (Subtarget.getTargetTriple().getRTLib() != Triple::COMPILER_RT) + setLibcallName(RTLIB::MULO_I128, nullptr); // Combine sin / cos into _sincos_stret if it is available. if (getLibcallName(RTLIB::SINCOS_STRET_F32) != nullptr && diff --git a/llvm/lib/TargetParser/Triple.cpp b/llvm/lib/TargetParser/Triple.cpp --- a/llvm/lib/TargetParser/Triple.cpp +++ b/llvm/lib/TargetParser/Triple.cpp @@ -1225,6 +1225,15 @@ return parseVersionFromName(OSName); } +Triple::RTLibType Triple::getRTLib() const { + if (isGNUEnvironment()) + return LIB_GCC; + if (isOSWindows()) + return WINDOWS_RT; + // or more conditions and default return UnknownRTLib + return COMPILER_RT; +} + bool Triple::getMacOSXVersion(VersionTuple &Version) const { Version = getOSVersion(); diff --git a/llvm/test/CodeGen/X86/overflow-intrinsic-optimizations.ll b/llvm/test/CodeGen/X86/overflow-intrinsic-optimizations.ll --- a/llvm/test/CodeGen/X86/overflow-intrinsic-optimizations.ll +++ b/llvm/test/CodeGen/X86/overflow-intrinsic-optimizations.ll @@ -1,8 +1,10 @@ -; RUN: llc %s -mtriple=i386 -o - | FileCheck %s +; RUN: llc %s -mtriple=i386-linux-gnu -o - | FileCheck %s --check-prefix=CHECK-LIBGCC +; RUN: llc %s -mtriple=i386 -o - | FileCheck %s --check-prefix=CHECK-COMPILERRT define i1 @no__mulodi4(i32 %a, i64 %b, ptr %c) { ; CHECK-LABEL: no__mulodi4: -; CHECK-NOT: calll __mulodi4 +; CHECK-LIBGCC-NOT: calll __mulodi4 +; CHECK-COMPILERRT: calll __mulodi4 entry: %0 = sext i32 %a to i64 %1 = call { i64, i1 } @llvm.smul.with.overflow.i64(i64 %0, i64 %b)