From f7cca7b8f8c53a7ede05917fc603d29e133e1720 Mon Sep 17 00:00:00 2001 From: Eli Friedman Date: Fri, 22 May 2009 03:22:46 +0000 Subject: [PATCH] Fix loop-index-split to correctly preserve dominance frontiers. Part of PR4238. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@72244 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Scalar/LoopIndexSplit.cpp | 29 ++++++++++-------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/lib/Transforms/Scalar/LoopIndexSplit.cpp b/lib/Transforms/Scalar/LoopIndexSplit.cpp index 40d2e4a9d8b..9c785968e1d 100644 --- a/lib/Transforms/Scalar/LoopIndexSplit.cpp +++ b/lib/Transforms/Scalar/LoopIndexSplit.cpp @@ -349,11 +349,8 @@ bool LoopIndexSplit::processOneIterationLoop() { // If BR operands are not IV or not loop invariants then skip this loop. Value *OPV = SplitCondition->getOperand(0); Value *SplitValue = SplitCondition->getOperand(1); - if (!L->isLoopInvariant(SplitValue)) { - Value *T = SplitValue; - SplitValue = OPV; - OPV = T; - } + if (!L->isLoopInvariant(SplitValue)) + std::swap(OPV, SplitValue); if (!L->isLoopInvariant(SplitValue)) return false; Instruction *OPI = dyn_cast(OPV); @@ -783,25 +780,23 @@ void LoopIndexSplit::moveExitCondition(BasicBlock *CondBB, BasicBlock *ActiveBB, // ExitBB is now dominated by CondBB DT->changeImmediateDominator(ExitBB, CondBB); DF->changeImmediateDominator(ExitBB, CondBB, DT); - - // Basicblocks dominated by ActiveBB may have ExitingBB or - // a basic block outside the loop in their DF list. If so, - // replace it with CondBB. - DomTreeNode *Node = DT->getNode(ActiveBB); - for (df_iterator DI = df_begin(Node), DE = df_end(Node); - DI != DE; ++DI) { - BasicBlock *BB = DI->getBlock(); - DominanceFrontier::iterator BBDF = DF->find(BB); + + // Blocks outside the loop may have been in the dominance frontier of blocks + // inside the condition; this is now impossible because the blocks inside the + // condition no loger dominate the exit. Remove the relevant blocks from + // the dominance frontiers. + for (Loop::block_iterator I = LP->block_begin(), E = LP->block_end(); + I != E; ++I) { + if (*I == CondBB || !DT->dominates(CondBB, *I)) continue; + DominanceFrontier::iterator BBDF = DF->find(*I); DominanceFrontier::DomSetType::iterator DomSetI = BBDF->second.begin(); DominanceFrontier::DomSetType::iterator DomSetE = BBDF->second.end(); while (DomSetI != DomSetE) { DominanceFrontier::DomSetType::iterator CurrentItr = DomSetI; ++DomSetI; BasicBlock *DFBB = *CurrentItr; - if (DFBB == ExitingBB || !L->contains(DFBB)) { + if (!LP->contains(DFBB)) BBDF->second.erase(DFBB); - BBDF->second.insert(CondBB); - } } } } -- 2.34.1