[llvm-commits] [llvm] r128197 - in /llvm/trunk: lib/Transforms/Scalar/CodeGenPrepare.cpp test/CodeGen/X86/tailcall-returndup-void.ll
Frits van Bommel
fvbommel at gmail.com
Thu Mar 24 01:56:04 PDT 2011
On Thu, Mar 24, 2011 at 5:52 AM, Cameron Zwarich <zwarich at apple.com> wrote:
> + // Make sure there are no instructions between the PHI and return, or that the
> + // return is the first instruction in the block.
> + if (PN) {
> + BasicBlock::iterator BI = BB->begin();
> + do { ++BI; } while (isa<DbgInfoIntrinsic>(BI));
> + if (&*BI != RI)
> + return false;
> + } else {
> + if (&*BB->begin() != RI)
> + return false;
'void' returns don't get to ignore debug intrinsics?
> + }
>
> /// Only dup the ReturnInst if the CallInst is likely to be emitted as a tail
> /// call.
> SmallVector<CallInst*, 4> TailCalls;
> - for (unsigned I = 0, E = PN->getNumIncomingValues(); I != E; ++I) {
> - CallInst *CI = dyn_cast<CallInst>(PN->getIncomingValue(I));
> - // Make sure the phi value is indeed produced by the tail call.
> - if (CI && CI->hasOneUse() && CI->getParent() == PN->getIncomingBlock(I) &&
> - TLI->mayBeEmittedAsTailCall(CI))
> - TailCalls.push_back(CI);
> + if (PN) {
> + for (unsigned I = 0, E = PN->getNumIncomingValues(); I != E; ++I) {
> + CallInst *CI = dyn_cast<CallInst>(PN->getIncomingValue(I));
> + // Make sure the phi value is indeed produced by the tail call.
> + if (CI && CI->hasOneUse() && CI->getParent() == PN->getIncomingBlock(I) &&
> + TLI->mayBeEmittedAsTailCall(CI))
> + TailCalls.push_back(CI);
> + }
> + } else {
> + SmallPtrSet<BasicBlock*, 4> VisitedBBs;
> + for (pred_iterator PI = pred_begin(BB), PE = pred_end(BB); PI != PE; ++PI) {
> + if (!VisitedBBs.insert(*PI))
> + continue;
> +
> + BasicBlock::InstListType &InstList = (*PI)->getInstList();
> + BasicBlock::InstListType::reverse_iterator RI = InstList.rbegin();
> + BasicBlock::InstListType::reverse_iterator RE = InstList.rend();
> + if (++RI == RE)
> + continue;
> + CallInst *CI = dyn_cast<CallInst>(&*RI);
> + if (CI && CI->getType()->isVoidTy() && TLI->mayBeEmittedAsTailCall(CI))
> + TailCalls.push_back(CI);
I don't think the 'isVoidTy()' check is necessary -- since void
functions don't return a value they shouldn't care about what value
their tail-callee returns (as long as it doesn't use sret).
For instance, a void function calling an int function should still be
able to use a tail call if the other conditions are met.
More information about the llvm-commits
mailing list