[PATCH] D143120: alternative to https://reviews.llvm.org/D108928

Nick Desaulniers via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 1 16:23:30 PST 2023


nickdesaulniers created this revision.
Herald added subscribers: pengfei, hiraditya.
Herald added a project: All.
nickdesaulniers requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

https://discourse.llvm.org/t/proposal-split-built-ins-from-the-rest-of-compiler-rt/67978


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D143120

Files:
  llvm/include/llvm/TargetParser/Triple.h
  llvm/lib/Target/X86/X86ISelLowering.cpp
  llvm/lib/TargetParser/Triple.cpp
  llvm/test/CodeGen/X86/overflow-intrinsic-optimizations.ll


Index: llvm/test/CodeGen/X86/overflow-intrinsic-optimizations.ll
===================================================================
--- llvm/test/CodeGen/X86/overflow-intrinsic-optimizations.ll
+++ 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)
Index: llvm/lib/TargetParser/Triple.cpp
===================================================================
--- llvm/lib/TargetParser/Triple.cpp
+++ 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();
 
Index: llvm/lib/Target/X86/X86ISelLowering.cpp
===================================================================
--- llvm/lib/Target/X86/X86ISelLowering.cpp
+++ 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 &&
Index: llvm/include/llvm/TargetParser/Triple.h
===================================================================
--- llvm/include/llvm/TargetParser/Triple.h
+++ 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() != "";


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D143120.494105.patch
Type: text/x-patch
Size: 2991 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230202/a98226ff/attachment.bin>


More information about the llvm-commits mailing list