@@ -1403,14 +1403,17 @@ bool llvm::FoldBranchToCommonDest(BranchInst *BI) {
1403
1403
if (Cond == 0 || (!isa<CmpInst>(Cond) && !isa<BinaryOperator>(Cond)) ||
1404
1404
Cond->getParent () != BB || !Cond->hasOneUse ())
1405
1405
return false ;
1406
-
1406
+
1407
+ SmallVector<DbgInfoIntrinsic *, 8 > DbgValues;
1407
1408
// Only allow this if the condition is a simple instruction that can be
1408
1409
// executed unconditionally. It must be in the same block as the branch, and
1409
1410
// must be at the front of the block.
1410
1411
BasicBlock::iterator FrontIt = BB->front ();
1411
1412
// Ignore dbg intrinsics.
1412
- while (isa<DbgInfoIntrinsic>(FrontIt))
1413
+ while (DbgInfoIntrinsic *DBI = dyn_cast<DbgInfoIntrinsic>(FrontIt)) {
1414
+ DbgValues.push_back (DBI);
1413
1415
++FrontIt;
1416
+ }
1414
1417
1415
1418
// Allow a single instruction to be hoisted in addition to the compare
1416
1419
// that feeds the branch. We later ensure that any values that _it_ uses
@@ -1431,8 +1434,10 @@ bool llvm::FoldBranchToCommonDest(BranchInst *BI) {
1431
1434
// Make sure the instruction after the condition is the cond branch.
1432
1435
BasicBlock::iterator CondIt = Cond; ++CondIt;
1433
1436
// Ingore dbg intrinsics.
1434
- while (isa<DbgInfoIntrinsic>(CondIt))
1437
+ while (DbgInfoIntrinsic *DBI = dyn_cast<DbgInfoIntrinsic>(CondIt)) {
1438
+ DbgValues.push_back (DBI);
1435
1439
++CondIt;
1440
+ }
1436
1441
if (&*CondIt != BI) {
1437
1442
assert (!isa<DbgInfoIntrinsic>(CondIt) && " Hey do not forget debug info!" );
1438
1443
return false ;
@@ -1453,7 +1458,7 @@ bool llvm::FoldBranchToCommonDest(BranchInst *BI) {
1453
1458
BasicBlock *FalseDest = BI->getSuccessor (1 );
1454
1459
if (TrueDest == BB || FalseDest == BB)
1455
1460
return false ;
1456
-
1461
+
1457
1462
for (pred_iterator PI = pred_begin (BB), E = pred_end (BB); PI != E; ++PI) {
1458
1463
BasicBlock *PredBlock = *PI;
1459
1464
BranchInst *PBI = dyn_cast<BranchInst>(PredBlock->getTerminator ());
@@ -1566,6 +1571,14 @@ bool llvm::FoldBranchToCommonDest(BranchInst *BI) {
1566
1571
AddPredecessorToBlock (FalseDest, PredBlock, BB);
1567
1572
PBI->setSuccessor (1 , FalseDest);
1568
1573
}
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
+ }
1569
1582
return true ;
1570
1583
}
1571
1584
return false ;
0 commit comments