Skip to content

Commit d715ec8

Browse files
author
Devang Patel
committed
While folding branch to a common destination into a predecessor, copy dbg values also.
llvm-svn: 129035
1 parent 6ade7e0 commit d715ec8

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

llvm/lib/Transforms/Utils/SimplifyCFG.cpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,14 +1403,17 @@ bool llvm::FoldBranchToCommonDest(BranchInst *BI) {
14031403
if (Cond == 0 || (!isa<CmpInst>(Cond) && !isa<BinaryOperator>(Cond)) ||
14041404
Cond->getParent() != BB || !Cond->hasOneUse())
14051405
return false;
1406-
1406+
1407+
SmallVector<DbgInfoIntrinsic *, 8> DbgValues;
14071408
// Only allow this if the condition is a simple instruction that can be
14081409
// executed unconditionally. It must be in the same block as the branch, and
14091410
// must be at the front of the block.
14101411
BasicBlock::iterator FrontIt = BB->front();
14111412
// Ignore dbg intrinsics.
1412-
while (isa<DbgInfoIntrinsic>(FrontIt))
1413+
while (DbgInfoIntrinsic *DBI = dyn_cast<DbgInfoIntrinsic>(FrontIt)) {
1414+
DbgValues.push_back(DBI);
14131415
++FrontIt;
1416+
}
14141417

14151418
// Allow a single instruction to be hoisted in addition to the compare
14161419
// that feeds the branch. We later ensure that any values that _it_ uses
@@ -1431,8 +1434,10 @@ bool llvm::FoldBranchToCommonDest(BranchInst *BI) {
14311434
// Make sure the instruction after the condition is the cond branch.
14321435
BasicBlock::iterator CondIt = Cond; ++CondIt;
14331436
// Ingore dbg intrinsics.
1434-
while(isa<DbgInfoIntrinsic>(CondIt))
1437+
while(DbgInfoIntrinsic *DBI = dyn_cast<DbgInfoIntrinsic>(CondIt)) {
1438+
DbgValues.push_back(DBI);
14351439
++CondIt;
1440+
}
14361441
if (&*CondIt != BI) {
14371442
assert (!isa<DbgInfoIntrinsic>(CondIt) && "Hey do not forget debug info!");
14381443
return false;
@@ -1453,7 +1458,7 @@ bool llvm::FoldBranchToCommonDest(BranchInst *BI) {
14531458
BasicBlock *FalseDest = BI->getSuccessor(1);
14541459
if (TrueDest == BB || FalseDest == BB)
14551460
return false;
1456-
1461+
14571462
for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) {
14581463
BasicBlock *PredBlock = *PI;
14591464
BranchInst *PBI = dyn_cast<BranchInst>(PredBlock->getTerminator());
@@ -1566,6 +1571,14 @@ bool llvm::FoldBranchToCommonDest(BranchInst *BI) {
15661571
AddPredecessorToBlock(FalseDest, PredBlock, BB);
15671572
PBI->setSuccessor(1, FalseDest);
15681573
}
1574+
1575+
// Move dbg value intrinsics in PredBlock.
1576+
for (SmallVector<DbgInfoIntrinsic *, 8>::iterator DBI = DbgValues.begin(),
1577+
DBE = DbgValues.end(); DBI != DBE; ++DBI) {
1578+
DbgInfoIntrinsic *DB = *DBI;
1579+
DB->removeFromParent();
1580+
DB->insertBefore(PBI);
1581+
}
15691582
return true;
15701583
}
15711584
return false;

0 commit comments

Comments
 (0)