[PATCH] D59078: memcpy is not tailcalled

Ramakota Reddy via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 7 01:45:57 PST 2019


ramred01 created this revision.
ramred01 added reviewers: wmi, mkuper.

In library routines like memcpy, memmove, memset, etc., the first argument that is passed is returned as the return value.  LLVM was not able to tailcall these functions.  This patch fixes the issue.


https://reviews.llvm.org/D59078

Files:
  lib/CodeGen/Analysis.cpp


Index: lib/CodeGen/Analysis.cpp
===================================================================
--- lib/CodeGen/Analysis.cpp
+++ lib/CodeGen/Analysis.cpp
@@ -590,6 +590,7 @@
   // argument. On other platforms like arm-none-eabi, memcpy may be
   // expanded as library call without return value, like __aeabi_memcpy.
   const CallInst *Call = cast<CallInst>(I);
+  auto *BitCastIn = dyn_cast<BitCastInst>(Call->getArgOperand(0));
   if (Function *F = Call->getCalledFunction()) {
     Intrinsic::ID IID = F->getIntrinsicID();
     if (((IID == Intrinsic::memcpy &&
@@ -598,7 +599,10 @@
           TLI.getLibcallName(RTLIB::MEMMOVE) == StringRef("memmove")) ||
          (IID == Intrinsic::memset &&
           TLI.getLibcallName(RTLIB::MEMSET) == StringRef("memset"))) &&
-        RetVal == Call->getArgOperand(0))
+        (RetVal == Call->getArgOperand(0) || 
+         (BitCastIn && RetVal == BitCastIn->getOperand(0) && 
+          Call->getArgOperand(0)->getType()->isPointerTy() &&
+          BitCastIn->getOperand(0)->getType()->isPointerTy())))
       return true;
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D59078.189662.patch
Type: text/x-patch
Size: 1084 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190307/76c01177/attachment.bin>


More information about the llvm-commits mailing list