From 818d50a93dbeb4a62140f72a0f89d0295b461177 Mon Sep 17 00:00:00 2001 From: Wei Mi Date: Wed, 6 Sep 2017 16:05:17 +0000 Subject: [TailCall] Allow llvm.memcpy/memset/memmove to be tail calls when parent function return the intrinsics's first argument. llvm.memcpy/memset/memmove return void but they will return the first argument after they are expanded as libcalls. Now if the parent function has any return value, llvm.memcpy cannot be turned into tail call after expansion. The patch is to handle that case in SelectionDAGBuilder so when caller function return the same value as the first argument of llvm.memcpy, tail call is allowed. Differential Revision: https://reviews.llvm.org/D37406 llvm-svn: 312641 --- llvm/lib/CodeGen/Analysis.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'llvm/lib/CodeGen/Analysis.cpp') diff --git a/llvm/lib/CodeGen/Analysis.cpp b/llvm/lib/CodeGen/Analysis.cpp index c2aecc651b7..f561577e1e2 100644 --- a/llvm/lib/CodeGen/Analysis.cpp +++ b/llvm/lib/CodeGen/Analysis.cpp @@ -565,6 +565,17 @@ bool llvm::returnTypeIsEligibleForTailCall(const Function *F, return false; const Value *RetVal = Ret->getOperand(0), *CallVal = I; + // Intrinsic like llvm.memcpy has no return value, but will return the + // first argument if it is expanded as libcall. + const CallInst *Call = cast(I); + if (Function *F = Call->getCalledFunction()) { + Intrinsic::ID IID = F->getIntrinsicID(); + if ((IID == Intrinsic::memcpy || IID == Intrinsic::memmove || + IID == Intrinsic::memset) && + RetVal == Call->getArgOperand(0)) + return true; + } + SmallVector RetPath, CallPath; SmallVector RetSubTypes, CallSubTypes; -- cgit v1.2.3