Be much more careful about how we update instructions outside of the loop

using instructions inside of the loop.  This should fix the MishaTest failure
from last night.

llvm-svn: 13038
This commit is contained in:
Chris Lattner 2004-04-18 17:32:39 +00:00
parent 3796974563
commit 230bcb6b35
1 changed files with 15 additions and 9 deletions

View File

@ -210,16 +210,22 @@ bool LoopUnroll::visitLoop(Loop *L) {
} }
// If there was more than one iteration, replace any uses of values computed // If there was more than one iteration, replace any uses of values computed
// in the loop with values computed during last iteration of the loop. // in the loop with values computed during the last iteration of the loop.
if (TripCount != 1) if (TripCount != 1) {
for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I) { std::set<User*> Users;
std::vector<User*> Users(I->use_begin(), I->use_end()); for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I)
for (unsigned i = 0, e = Users.size(); i != e; ++i) { Users.insert(I->use_begin(), I->use_end());
Instruction *UI = cast<Instruction>(Users[i]);
if (UI->getParent() != BB && UI->getParent() != NewBlock) // We don't want to reprocess entries with PHI nodes in them. For this
UI->replaceUsesOfWith(I, LastValueMap[I]); // reason, we look at each operand of each user exactly once, performing the
} // stubstitution exactly once.
for (std::set<User*>::iterator UI = Users.begin(), E = Users.end(); UI != E;
++UI) {
Instruction *I = cast<Instruction>(*UI);
if (I->getParent() != BB && I->getParent() != NewBlock)
RemapInstruction(I, LastValueMap);
} }
}
// Now that we cloned the block as many times as we needed, stitch the new // Now that we cloned the block as many times as we needed, stitch the new
// code into the original block and delete the temporary block. // code into the original block and delete the temporary block.