Fix dom frontier update. This fixes PR4667.

Patch by Jakub Staszak.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78388 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Devang Patel
2009-08-07 17:16:44 +00:00
parent bdab0e9695
commit b7f40c1a2a

View File

@@ -511,26 +511,30 @@ void LoopRotate::preserveCanonicalLoopForm(LPPassManager &LPM) {
DF->addBasicBlock(L->getHeader(), LatchSet); DF->addBasicBlock(L->getHeader(), LatchSet);
} }
// If a loop block dominates new loop latch then its frontier is // If a loop block dominates new loop latch then add to its frontiers
// new header and Exit. // new header and Exit and remove new latch (which is equal to original
// header).
BasicBlock *NewLatch = L->getLoopLatch(); BasicBlock *NewLatch = L->getLoopLatch();
DominatorTree *DT = getAnalysisIfAvailable<DominatorTree>();
for (Loop::block_iterator BI = L->block_begin(), BE = L->block_end(); assert(NewLatch == OrigHeader && "NewLatch is inequal to OrigHeader");
BI != BE; ++BI) {
BasicBlock *B = *BI; if (DominatorTree *DT = getAnalysisIfAvailable<DominatorTree>()) {
if (DT->dominates(B, NewLatch)) { for (Loop::block_iterator BI = L->block_begin(), BE = L->block_end();
DominanceFrontier::iterator BDFI = DF->find(B); BI != BE; ++BI) {
if (BDFI != DF->end()) { BasicBlock *B = *BI;
DominanceFrontier::DomSetType &BSet = BDFI->second; if (DT->dominates(B, NewLatch)) {
BSet = BDFI->second; DominanceFrontier::iterator BDFI = DF->find(B);
BSet.clear(); if (BDFI != DF->end()) {
BSet.insert(L->getHeader()); DominanceFrontier::DomSetType &BSet = BDFI->second;
BSet.insert(Exit); BSet.erase(NewLatch);
} else { BSet.insert(L->getHeader());
DominanceFrontier::DomSetType BSet; BSet.insert(Exit);
BSet.insert(L->getHeader()); } else {
BSet.insert(Exit); DominanceFrontier::DomSetType BSet;
DF->addBasicBlock(B, BSet); BSet.insert(L->getHeader());
BSet.insert(Exit);
DF->addBasicBlock(B, BSet);
}
} }
} }
} }