From e991b5fdd5ab583531300097cf35e1087d479ef0 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Mon, 13 Dec 2010 02:38:13 +0000 Subject: simplify code and reduce indentation git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@121670 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Scalar/JumpThreading.cpp | 62 ++++++++++++++++----------------- 1 file changed, 30 insertions(+), 32 deletions(-) (limited to 'lib/Transforms/Scalar/JumpThreading.cpp') diff --git a/lib/Transforms/Scalar/JumpThreading.cpp b/lib/Transforms/Scalar/JumpThreading.cpp index 84dbb1a475..b44bc5efef 100644 --- a/lib/Transforms/Scalar/JumpThreading.cpp +++ b/lib/Transforms/Scalar/JumpThreading.cpp @@ -168,40 +168,38 @@ bool JumpThreading::runOnFunction(Function &F) { LVI->eraseBlock(BB); DeleteDeadBlock(BB); Changed = true; - } else if (BranchInst *BI = dyn_cast(BB->getTerminator())) { - // Can't thread an unconditional jump, but if the block is "almost - // empty", we can replace uses of it with uses of the successor and make - // this dead. - if (BI->isUnconditional() && - BB != &BB->getParent()->getEntryBlock()) { - BasicBlock::iterator BBI = BB->getFirstNonPHI(); - // Ignore dbg intrinsics. - while (isa(BBI)) - ++BBI; + continue; + } + + BranchInst *BI = dyn_cast(BB->getTerminator()); + + // Can't thread an unconditional jump, but if the block is "almost + // empty", we can replace uses of it with uses of the successor and make + // this dead. + if (BI && BI->isUnconditional() && + BB != &BB->getParent()->getEntryBlock() && // If the terminator is the only non-phi instruction, try to nuke it. - if (BBI->isTerminator()) { - // Since TryToSimplifyUncondBranchFromEmptyBlock may delete the - // block, we have to make sure it isn't in the LoopHeaders set. We - // reinsert afterward if needed. - bool ErasedFromLoopHeaders = LoopHeaders.erase(BB); - BasicBlock *Succ = BI->getSuccessor(0); - - // FIXME: It is always conservatively correct to drop the info - // for a block even if it doesn't get erased. This isn't totally - // awesome, but it allows us to use AssertingVH to prevent nasty - // dangling pointer issues within LazyValueInfo. - LVI->eraseBlock(BB); - if (TryToSimplifyUncondBranchFromEmptyBlock(BB)) { - Changed = true; - // If we deleted BB and BB was the header of a loop, then the - // successor is now the header of the loop. - BB = Succ; - } - - if (ErasedFromLoopHeaders) - LoopHeaders.insert(BB); - } + BB->getFirstNonPHIOrDbg()->isTerminator()) { + // Since TryToSimplifyUncondBranchFromEmptyBlock may delete the + // block, we have to make sure it isn't in the LoopHeaders set. We + // reinsert afterward if needed. + bool ErasedFromLoopHeaders = LoopHeaders.erase(BB); + BasicBlock *Succ = BI->getSuccessor(0); + + // FIXME: It is always conservatively correct to drop the info + // for a block even if it doesn't get erased. This isn't totally + // awesome, but it allows us to use AssertingVH to prevent nasty + // dangling pointer issues within LazyValueInfo. + LVI->eraseBlock(BB); + if (TryToSimplifyUncondBranchFromEmptyBlock(BB)) { + Changed = true; + // If we deleted BB and BB was the header of a loop, then the + // successor is now the header of the loop. + BB = Succ; } + + if (ErasedFromLoopHeaders) + LoopHeaders.insert(BB); } } EverChanged |= Changed; -- cgit v1.2.3