[llvm-commits] [llvm] r122805 - /llvm/trunk/lib/Transforms/Scalar/LoopIdiomRecognize.cpp

Chris Lattner sabre at nondot.org
Mon Jan 3 23:27:30 PST 2011


Author: lattner
Date: Tue Jan  4 01:27:30 2011
New Revision: 122805

URL: http://llvm.org/viewvc/llvm-project?rev=122805&view=rev
Log:
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.


Modified:
    llvm/trunk/lib/Transforms/Scalar/LoopIdiomRecognize.cpp

Modified: llvm/trunk/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/LoopIdiomRecognize.cpp?rev=122805&r1=122804&r2=122805&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/LoopIdiomRecognize.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/LoopIdiomRecognize.cpp Tue Jan  4 01:27:30 2011
@@ -207,19 +207,22 @@
   
   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;
+      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;
+    }
     
-    MadeChange = true;
-    
-    // If processing the store invalidated our iterator, start over from the
-    // head of the loop.
-    if (InstPtr == 0)
-      I = BB->begin();
   }
   
   return MadeChange;





More information about the llvm-commits mailing list