diff options
-rw-r--r-- | lib/Transforms/Scalar/LoopIdiomRecognize.cpp | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/lib/Transforms/Scalar/LoopIdiomRecognize.cpp b/lib/Transforms/Scalar/LoopIdiomRecognize.cpp index fc707755e9..d67f6c1e95 100644 --- a/lib/Transforms/Scalar/LoopIdiomRecognize.cpp +++ b/lib/Transforms/Scalar/LoopIdiomRecognize.cpp @@ -207,19 +207,22 @@ bool LoopIdiomRecognize::runOnLoopBlock(BasicBlock *BB, const SCEV *BECount, bool MadeChange = false; for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ) { - // Look for store instructions, which may be memsets. - StoreInst *SI = dyn_cast<StoreInst>(I++); - if (SI == 0 || SI->isVolatile()) continue; + Instruction *Inst = I++; + // Look for store instructions, which may be optimized to memset/memcpy. + if (StoreInst *SI = dyn_cast<StoreInst>(Inst)) { + if (SI->isVolatile()) continue; - WeakVH InstPtr(SI); - if (!processLoopStore(SI, BECount)) continue; - - MadeChange = true; + WeakVH InstPtr(I); + if (!processLoopStore(SI, BECount)) continue; + MadeChange = true; + + // If processing the store invalidated our iterator, start over from the + // head of the loop. + if (InstPtr == 0) + I = BB->begin(); + continue; + } - // If processing the store invalidated our iterator, start over from the - // head of the loop. - if (InstPtr == 0) - I = BB->begin(); } return MadeChange; |