diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp index bcf25958d0982..029eb025ff1de 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp @@ -9053,6 +9053,18 @@ static void checkAddrSpaceIsValidForLibcall(const TargetLowering *TLI, } } +static bool isInTailCallPositionWrapper(const CallInst *CI, + const SelectionDAG *SelDAG, + bool AllowReturnsFirstArg) { + if (!CI || !CI->isTailCall()) + return false; + // TODO: Fix "returns-first-arg" determination so it doesn't depend on which + // helper symbol we lower to. + return isInTailCallPosition(*CI, SelDAG->getTarget(), + AllowReturnsFirstArg && + funcReturnsFirstArgOfCall(*CI)); +} + std::pair SelectionDAG::getMemcmp(SDValue Chain, const SDLoc &dl, SDValue Mem0, SDValue Mem1, SDValue Size, const CallInst *CI) { @@ -9067,10 +9079,8 @@ SelectionDAG::getMemcmp(SDValue Chain, const SDLoc &dl, SDValue Mem0, {Size, getDataLayout().getIntPtrType(*getContext())}}; TargetLowering::CallLoweringInfo CLI(*this); - bool IsTailCall = false; - bool ReturnsFirstArg = CI && funcReturnsFirstArgOfCall(*CI); - IsTailCall = CI && CI->isTailCall() && - isInTailCallPosition(*CI, getTarget(), ReturnsFirstArg); + bool IsTailCall = + isInTailCallPositionWrapper(CI, this, /*AllowReturnsFirstArg*/ true); CLI.setDebugLoc(dl) .setChain(Chain) @@ -9148,10 +9158,7 @@ SDValue SelectionDAG::getMemcpy( IsTailCall = *OverrideTailCall; } else { bool LowersToMemcpy = StringRef(MemCpyName) == StringRef("memcpy"); - bool ReturnsFirstArg = CI && funcReturnsFirstArgOfCall(*CI); - IsTailCall = CI && CI->isTailCall() && - isInTailCallPosition(*CI, getTarget(), - ReturnsFirstArg && LowersToMemcpy); + IsTailCall = isInTailCallPositionWrapper(CI, this, LowersToMemcpy); } CLI.setDebugLoc(dl) @@ -9255,10 +9262,7 @@ SDValue SelectionDAG::getMemmove(SDValue Chain, const SDLoc &dl, SDValue Dst, } else { bool LowersToMemmove = TLI->getLibcallName(RTLIB::MEMMOVE) == StringRef("memmove"); - bool ReturnsFirstArg = CI && funcReturnsFirstArgOfCall(*CI); - IsTailCall = CI && CI->isTailCall() && - isInTailCallPosition(*CI, getTarget(), - ReturnsFirstArg && LowersToMemmove); + IsTailCall = isInTailCallPositionWrapper(CI, this, LowersToMemmove); } CLI.setDebugLoc(dl)