forked from OSchip/llvm-project
CodeGenPrepare: Move ret duplication out of the instruction iteration loop.
It can delete the block, and the loop continues on free'd memory. No change in output. Found by valgrind. llvm-svn: 168525
This commit is contained in:
parent
bef254ab16
commit
455fa35e51
|
@ -125,7 +125,7 @@ namespace {
|
|||
bool MoveExtToFormExtLoad(Instruction *I);
|
||||
bool OptimizeExtUses(Instruction *I);
|
||||
bool OptimizeSelectInst(SelectInst *SI);
|
||||
bool DupRetToEnableTailCallOpts(ReturnInst *RI);
|
||||
bool DupRetToEnableTailCallOpts(BasicBlock *BB);
|
||||
bool PlaceDbgValues(Function &F);
|
||||
};
|
||||
}
|
||||
|
@ -689,10 +689,14 @@ bool CodeGenPrepare::OptimizeCallInst(CallInst *CI) {
|
|||
/// %tmp2 = tail call i32 @f2()
|
||||
/// ret i32 %tmp2
|
||||
/// @endcode
|
||||
bool CodeGenPrepare::DupRetToEnableTailCallOpts(ReturnInst *RI) {
|
||||
bool CodeGenPrepare::DupRetToEnableTailCallOpts(BasicBlock *BB) {
|
||||
if (!TLI)
|
||||
return false;
|
||||
|
||||
ReturnInst *RI = dyn_cast<ReturnInst>(BB->getTerminator());
|
||||
if (!RI)
|
||||
return false;
|
||||
|
||||
PHINode *PN = 0;
|
||||
BitCastInst *BCI = 0;
|
||||
Value *V = RI->getReturnValue();
|
||||
|
@ -706,7 +710,6 @@ bool CodeGenPrepare::DupRetToEnableTailCallOpts(ReturnInst *RI) {
|
|||
return false;
|
||||
}
|
||||
|
||||
BasicBlock *BB = RI->getParent();
|
||||
if (PN && PN->getParent() != BB)
|
||||
return false;
|
||||
|
||||
|
@ -1319,9 +1322,6 @@ bool CodeGenPrepare::OptimizeInst(Instruction *I) {
|
|||
if (CallInst *CI = dyn_cast<CallInst>(I))
|
||||
return OptimizeCallInst(CI);
|
||||
|
||||
if (ReturnInst *RI = dyn_cast<ReturnInst>(I))
|
||||
return DupRetToEnableTailCallOpts(RI);
|
||||
|
||||
if (SelectInst *SI = dyn_cast<SelectInst>(I))
|
||||
return OptimizeSelectInst(SI);
|
||||
|
||||
|
@ -1339,6 +1339,8 @@ bool CodeGenPrepare::OptimizeBlock(BasicBlock &BB) {
|
|||
while (CurInstIterator != BB.end())
|
||||
MadeChange |= OptimizeInst(CurInstIterator++);
|
||||
|
||||
MadeChange |= DupRetToEnableTailCallOpts(&BB);
|
||||
|
||||
return MadeChange;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue