restructure this a bit. Initialize the WeakVH with "I", the
authorChris Lattner <sabre@nondot.org>
Tue, 4 Jan 2011 07:27:30 +0000 (07:27 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 4 Jan 2011 07:27:30 +0000 (07:27 +0000)
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

lib/Transforms/Scalar/LoopIdiomRecognize.cpp

index fc707755e9d275156b512904c879f5e7139f7f72..d67f6c1e95bd4bb95c4a62b8f6437c37715d6340 100644 (file)
@@ -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;