While folding branch to a common destination into a predecessor, copy dbg values also.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@129035 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Devang Patel 2011-04-06 22:37:20 +00:00
parent f22eefba68
commit d418194036

View File

@ -1404,13 +1404,16 @@ bool llvm::FoldBranchToCommonDest(BranchInst *BI) {
Cond->getParent() != BB || !Cond->hasOneUse()) Cond->getParent() != BB || !Cond->hasOneUse())
return false; return false;
SmallVector<DbgInfoIntrinsic *, 8> DbgValues;
// Only allow this if the condition is a simple instruction that can be // Only allow this if the condition is a simple instruction that can be
// executed unconditionally. It must be in the same block as the branch, and // executed unconditionally. It must be in the same block as the branch, and
// must be at the front of the block. // must be at the front of the block.
BasicBlock::iterator FrontIt = BB->front(); BasicBlock::iterator FrontIt = BB->front();
// Ignore dbg intrinsics. // Ignore dbg intrinsics.
while (isa<DbgInfoIntrinsic>(FrontIt)) while (DbgInfoIntrinsic *DBI = dyn_cast<DbgInfoIntrinsic>(FrontIt)) {
DbgValues.push_back(DBI);
++FrontIt; ++FrontIt;
}
// Allow a single instruction to be hoisted in addition to the compare // Allow a single instruction to be hoisted in addition to the compare
// that feeds the branch. We later ensure that any values that _it_ uses // that feeds the branch. We later ensure that any values that _it_ uses
@ -1431,8 +1434,10 @@ bool llvm::FoldBranchToCommonDest(BranchInst *BI) {
// Make sure the instruction after the condition is the cond branch. // Make sure the instruction after the condition is the cond branch.
BasicBlock::iterator CondIt = Cond; ++CondIt; BasicBlock::iterator CondIt = Cond; ++CondIt;
// Ingore dbg intrinsics. // Ingore dbg intrinsics.
while(isa<DbgInfoIntrinsic>(CondIt)) while(DbgInfoIntrinsic *DBI = dyn_cast<DbgInfoIntrinsic>(CondIt)) {
DbgValues.push_back(DBI);
++CondIt; ++CondIt;
}
if (&*CondIt != BI) { if (&*CondIt != BI) {
assert (!isa<DbgInfoIntrinsic>(CondIt) && "Hey do not forget debug info!"); assert (!isa<DbgInfoIntrinsic>(CondIt) && "Hey do not forget debug info!");
return false; return false;
@ -1566,6 +1571,14 @@ bool llvm::FoldBranchToCommonDest(BranchInst *BI) {
AddPredecessorToBlock(FalseDest, PredBlock, BB); AddPredecessorToBlock(FalseDest, PredBlock, BB);
PBI->setSuccessor(1, FalseDest); PBI->setSuccessor(1, FalseDest);
} }
// Move dbg value intrinsics in PredBlock.
for (SmallVector<DbgInfoIntrinsic *, 8>::iterator DBI = DbgValues.begin(),
DBE = DbgValues.end(); DBI != DBE; ++DBI) {
DbgInfoIntrinsic *DB = *DBI;
DB->removeFromParent();
DB->insertBefore(PBI);
}
return true; return true;
} }
return false; return false;