Use an early return instead of a long if block.

llvm-svn: 128196
This commit is contained in:
Cameron Zwarich 2011-03-24 04:52:07 +00:00
parent dd84bcce8f
commit 0e331c05ae
1 changed files with 55 additions and 55 deletions

View File

@ -597,7 +597,10 @@ bool CodeGenPrepare::DupRetToEnableTailCallOpts(ReturnInst *RI) {
if (!V) if (!V)
return false; return false;
if (PHINode *PN = dyn_cast<PHINode>(V)) { PHINode *PN = dyn_cast<PHINode>(V);
if (!PN)
return false;
BasicBlock *BB = RI->getParent(); BasicBlock *BB = RI->getParent();
if (PN->getParent() != BB) if (PN->getParent() != BB)
return false; return false;
@ -615,8 +618,8 @@ bool CodeGenPrepare::DupRetToEnableTailCallOpts(ReturnInst *RI) {
if (&*BI != RI) if (&*BI != RI)
return false; return false;
/// Only dup the ReturnInst if the CallInst is likely to be emitted as a /// Only dup the ReturnInst if the CallInst is likely to be emitted as a tail
/// tail call. /// call.
SmallVector<CallInst*, 4> TailCalls; SmallVector<CallInst*, 4> TailCalls;
for (unsigned I = 0, E = PN->getNumIncomingValues(); I != E; ++I) { for (unsigned I = 0, E = PN->getNumIncomingValues(); I != E; ++I) {
CallInst *CI = dyn_cast<CallInst>(PN->getIncomingValue(I)); CallInst *CI = dyn_cast<CallInst>(PN->getIncomingValue(I));
@ -631,14 +634,14 @@ bool CodeGenPrepare::DupRetToEnableTailCallOpts(ReturnInst *RI) {
CallInst *CI = TailCalls[i]; CallInst *CI = TailCalls[i];
CallSite CS(CI); CallSite CS(CI);
// Conservatively require the attributes of the call to match those of // Conservatively require the attributes of the call to match those of the
// the return. Ignore noalias because it doesn't affect the call sequence. // return. Ignore noalias because it doesn't affect the call sequence.
unsigned CalleeRetAttr = CS.getAttributes().getRetAttributes(); unsigned CalleeRetAttr = CS.getAttributes().getRetAttributes();
if ((CalleeRetAttr ^ CallerRetAttr) & ~Attribute::NoAlias) if ((CalleeRetAttr ^ CallerRetAttr) & ~Attribute::NoAlias)
continue; continue;
// Make sure the call instruction is followed by an unconditional branch // Make sure the call instruction is followed by an unconditional branch to
// to the return block. // the return block.
BasicBlock *CallBB = CI->getParent(); BasicBlock *CallBB = CI->getParent();
BranchInst *BI = dyn_cast<BranchInst>(CallBB->getTerminator()); BranchInst *BI = dyn_cast<BranchInst>(CallBB->getTerminator());
if (!BI || !BI->isUnconditional() || BI->getSuccessor(0) != BB) if (!BI || !BI->isUnconditional() || BI->getSuccessor(0) != BB)
@ -655,9 +658,6 @@ bool CodeGenPrepare::DupRetToEnableTailCallOpts(ReturnInst *RI) {
BB->eraseFromParent(); BB->eraseFromParent();
return Changed; return Changed;
}
return false;
} }
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//