diff options
author | Chris Lattner <sabre@nondot.org> | 2011-01-04 07:27:30 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2011-01-04 07:27:30 +0000 |
commit | a62b01dc3771615cd3b7fdbdd6cfd529379dbb77 (patch) | |
tree | 7b9871c9ace10e163616f6d8f3de8a3a0ac1739b /llvm/lib/Transforms | |
parent | e0cee6a8b00cd48e3bf060a1ff479a08601049f9 (diff) | |
download | bcm5719-llvm-a62b01dc3771615cd3b7fdbdd6cfd529379dbb77.tar.gz bcm5719-llvm-a62b01dc3771615cd3b7fdbdd6cfd529379dbb77.zip |
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.
llvm-svn: 122805
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r-- | llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp b/llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp index fc707755e9d..d67f6c1e95b 100644 --- a/llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp +++ b/llvm/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; |