diff options
author | Wei Mi <wmi@google.com> | 2017-09-08 16:44:52 +0000 |
---|---|---|
committer | Wei Mi <wmi@google.com> | 2017-09-08 16:44:52 +0000 |
commit | 5d84d9b35ccae7fc17acc08a15658bbc2884555e (patch) | |
tree | 81ce263c07bacfb7531ae7353d723b17d724a166 /llvm/lib/CodeGen/Analysis.cpp | |
parent | e85a7e7cd5aa8471d4bd93605162f911c2cbf947 (diff) | |
download | llvm-5d84d9b35ccae7fc17acc08a15658bbc2884555e.zip llvm-5d84d9b35ccae7fc17acc08a15658bbc2884555e.tar.gz llvm-5d84d9b35ccae7fc17acc08a15658bbc2884555e.tar.bz2 |
Fix a bug for rL312641.
rL312641 Allowed llvm.memcpy/memset/memmove to be tail calls when parent
function return the intrinsics's first argument. However on arm-none-eabi
platform, llvm.memcpy will be expanded to __aeabi_memcpy which doesn't
have return value. The fix is to check the libcall name after expansion
to match "memcpy/memset/memmove" before allowing those intrinsic to be
tail calls.
llvm-svn: 312799
Diffstat (limited to 'llvm/lib/CodeGen/Analysis.cpp')
-rw-r--r-- | llvm/lib/CodeGen/Analysis.cpp | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/llvm/lib/CodeGen/Analysis.cpp b/llvm/lib/CodeGen/Analysis.cpp index f561577..876cca4 100644 --- a/llvm/lib/CodeGen/Analysis.cpp +++ b/llvm/lib/CodeGen/Analysis.cpp @@ -565,13 +565,20 @@ 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. + // Intrinsic like llvm.memcpy has no return value, but the expanded + // libcall may or may not have return value. On most platforms, it + // will be expanded as memcpy in libc, which returns the first + // 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); if (Function *F = Call->getCalledFunction()) { Intrinsic::ID IID = F->getIntrinsicID(); - if ((IID == Intrinsic::memcpy || IID == Intrinsic::memmove || - IID == Intrinsic::memset) && + if (((IID == Intrinsic::memcpy && + TLI.getLibcallName(RTLIB::MEMCPY) == StringRef("memcpy")) || + (IID == Intrinsic::memmove && + TLI.getLibcallName(RTLIB::MEMMOVE) == StringRef("memmove")) || + (IID == Intrinsic::memset && + TLI.getLibcallName(RTLIB::MEMSET) == StringRef("memset"))) && RetVal == Call->getArgOperand(0)) return true; } |