restructure this a bit. Initialize the WeakVH with "I", the

instruction *after* the store.  The store will always be deleted
if the transformation kicks in, so we'd do an N^2 scan of every
loop block.  Whoops.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122805 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2011-01-04 07:27:30 +00:00
parent 645b1d2f12
commit b7e9ef0ed1

View File

@ -207,19 +207,22 @@ bool LoopIdiomRecognize::runOnLoopBlock(BasicBlock *BB, const SCEV *BECount,
bool MadeChange = false; bool MadeChange = false;
for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ) { for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ) {
// Look for store instructions, which may be memsets. Instruction *Inst = I++;
StoreInst *SI = dyn_cast<StoreInst>(I++); // Look for store instructions, which may be optimized to memset/memcpy.
if (SI == 0 || SI->isVolatile()) continue; if (StoreInst *SI = dyn_cast<StoreInst>(Inst)) {
if (SI->isVolatile()) continue;
WeakVH InstPtr(SI); WeakVH InstPtr(I);
if (!processLoopStore(SI, BECount)) continue; if (!processLoopStore(SI, BECount)) continue;
MadeChange = true; MadeChange = true;
// If processing the store invalidated our iterator, start over from the // If processing the store invalidated our iterator, start over from the
// head of the loop. // head of the loop.
if (InstPtr == 0) if (InstPtr == 0)
I = BB->begin(); I = BB->begin();
continue;
}
} }
return MadeChange; return MadeChange;