[PATCH] D106401: [CUDA, MemCpyOpt] Add a flag to force-enable memcpyopt and use it for CUDA.

Artem Belevich via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 20 15:15:18 PDT 2021


tra updated this revision to Diff 360293.
tra edited the summary of this revision.
tra added a comment.

Fixed the option name.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D106401/new/

https://reviews.llvm.org/D106401

Files:
  clang/lib/Driver/ToolChains/Cuda.cpp
  llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp


Index: llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
+++ llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
@@ -67,6 +67,10 @@
 
 #define DEBUG_TYPE "memcpyopt"
 
+static cl::opt<bool> EnableMemCpyOptWithoutLibcalls(
+    "enable-memcpyopt-without-libcalls", cl::init(false), cl::Hidden,
+    cl::desc("Enable memcpyopt even when libcalls are disabled"));
+
 static cl::opt<bool>
     EnableMemorySSA("enable-memcpyopt-memoryssa", cl::init(true), cl::Hidden,
                     cl::desc("Use MemorySSA-backed MemCpyOpt."));
@@ -1757,7 +1761,16 @@
   // If we don't have at least memset and memcpy, there is little point of doing
   // anything here.  These are required by a freestanding implementation, so if
   // even they are disabled, there is no point in trying hard.
-  if (!TLI->has(LibFunc_memset) || !TLI->has(LibFunc_memcpy))
+  bool ShoudRunMemCpyOpt =
+      (TLI->has(LibFunc_memset) && TLI->has(LibFunc_memcpy))
+      // Some targets have libcalls disabled, but still want to run the pass.
+      // TODO: the pass should not depend on libcall availability as the targets
+      // should provide alternative ways of lowering standard LLVM
+      // intrinsics. Alas, there are existing users that can't currently handle
+      // `memset` intrinsic materialized by this pass.  See
+      // https://reviews.llvm.org/D104801 for the details.
+      || EnableMemCpyOptWithoutLibcalls;
+  if (!ShoudRunMemCpyOpt)
     return false;
 
   while (true) {
Index: clang/lib/Driver/ToolChains/Cuda.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Cuda.cpp
+++ clang/lib/Driver/ToolChains/Cuda.cpp
@@ -686,7 +686,8 @@
          "Only OpenMP or CUDA offloading kinds are supported for NVIDIA GPUs.");
 
   if (DeviceOffloadingKind == Action::OFK_Cuda) {
-    CC1Args.push_back("-fcuda-is-device");
+    CC1Args.append(
+        {"-fcuda-is-device", "-mllvm", "-enable-memcpyopt-without-libcalls"});
 
     if (DriverArgs.hasFlag(options::OPT_fcuda_approx_transcendentals,
                            options::OPT_fno_cuda_approx_transcendentals, false))


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D106401.360293.patch
Type: text/x-patch
Size: 2233 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210720/b8fbebab/attachment-0001.bin>


More information about the cfe-commits mailing list