From d418194036e9e05f47154535ddb9f1f1c8bc592b Mon Sep 17 00:00:00 2001 From: Devang Patel Date: Wed, 6 Apr 2011 22:37:20 +0000 Subject: [PATCH] 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 --- lib/Transforms/Utils/SimplifyCFG.cpp | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/lib/Transforms/Utils/SimplifyCFG.cpp b/lib/Transforms/Utils/SimplifyCFG.cpp index c12f9d810f5..a181e3e2c7d 100644 --- a/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/lib/Transforms/Utils/SimplifyCFG.cpp @@ -1403,14 +1403,17 @@ bool llvm::FoldBranchToCommonDest(BranchInst *BI) { if (Cond == 0 || (!isa(Cond) && !isa(Cond)) || Cond->getParent() != BB || !Cond->hasOneUse()) return false; - + + SmallVector DbgValues; // 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 // must be at the front of the block. BasicBlock::iterator FrontIt = BB->front(); // Ignore dbg intrinsics. - while (isa(FrontIt)) + while (DbgInfoIntrinsic *DBI = dyn_cast(FrontIt)) { + DbgValues.push_back(DBI); ++FrontIt; + } // 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 @@ -1431,8 +1434,10 @@ bool llvm::FoldBranchToCommonDest(BranchInst *BI) { // Make sure the instruction after the condition is the cond branch. BasicBlock::iterator CondIt = Cond; ++CondIt; // Ingore dbg intrinsics. - while(isa(CondIt)) + while(DbgInfoIntrinsic *DBI = dyn_cast(CondIt)) { + DbgValues.push_back(DBI); ++CondIt; + } if (&*CondIt != BI) { assert (!isa(CondIt) && "Hey do not forget debug info!"); return false; @@ -1453,7 +1458,7 @@ bool llvm::FoldBranchToCommonDest(BranchInst *BI) { BasicBlock *FalseDest = BI->getSuccessor(1); if (TrueDest == BB || FalseDest == BB) return false; - + for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) { BasicBlock *PredBlock = *PI; BranchInst *PBI = dyn_cast(PredBlock->getTerminator()); @@ -1566,6 +1571,14 @@ bool llvm::FoldBranchToCommonDest(BranchInst *BI) { AddPredecessorToBlock(FalseDest, PredBlock, BB); PBI->setSuccessor(1, FalseDest); } + + // Move dbg value intrinsics in PredBlock. + for (SmallVector::iterator DBI = DbgValues.begin(), + DBE = DbgValues.end(); DBI != DBE; ++DBI) { + DbgInfoIntrinsic *DB = *DBI; + DB->removeFromParent(); + DB->insertBefore(PBI); + } return true; } return false; -- 2.11.0