[llvm-commits] [llvm] r122869 - /llvm/trunk/lib/Transforms/Scalar/LoopInstSimplify.cpp

Cameron Zwarich zwarich at apple.com
Tue Jan 4 21:47:47 PST 2011


Author: zwarich
Date: Tue Jan  4 23:47:47 2011
New Revision: 122869

URL: http://llvm.org/viewvc/llvm-project?rev=122869&view=rev
Log:
Use a worklist for later iterations just like ordinary instsimplify. The next
step is to only process instructions in subloops if they have been modified by
an earlier simplification.

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

Modified: llvm/trunk/lib/Transforms/Scalar/LoopInstSimplify.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/LoopInstSimplify.cpp?rev=122869&r1=122868&r2=122869&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/LoopInstSimplify.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/LoopInstSimplify.cpp Tue Jan  4 23:47:47 2011
@@ -66,6 +66,8 @@
   L->getUniqueExitBlocks(ExitBlocks);
   array_pod_sort(ExitBlocks.begin(), ExitBlocks.end());
 
+  SmallPtrSet<const Instruction*, 8> S1, S2, *ToSimplify = &S1, *Next = &S2;
+
   SmallVector<BasicBlock*, 16> VisitStack;
   SmallPtrSet<BasicBlock*, 32> Visited;
 
@@ -86,10 +88,22 @@
       // Simplify instructions in the current basic block.
       for (BasicBlock::iterator BI = BB->begin(), BE = BB->end(); BI != BE;) {
         Instruction *I = BI++;
+
+        // The first time through the loop ToSimplify is empty and we try to
+        // simplify all instructions. On later iterations ToSimplify is not
+        // empty and we only bother simplifying instructions that are in it.
+        if (!ToSimplify->empty() && !ToSimplify->count(I))
+          continue;
+
         // Don't bother simplifying unused instructions.
         if (!I->use_empty()) {
           Value *V = SimplifyInstruction(I, TD, DT);
           if (V && LI->replacementPreservesLCSSAForm(I, V)) {
+            // Mark all uses for resimplification next time round the loop.
+            for (Value::use_iterator UI = I->use_begin(), UE = I->use_end();
+                 UI != UE; ++UI)
+              Next->insert(cast<Instruction>(*UI));
+
             I->replaceAllUsesWith(V);
             LocalChanged = true;
             ++NumSimplified;
@@ -109,6 +123,11 @@
       }
     }
 
+    // Place the list of instructions to simplify on the next loop iteration
+    // into ToSimplify.
+    std::swap(ToSimplify, Next);
+    Next->clear();
+
     Changed |= LocalChanged;
   } while (LocalChanged);
 





More information about the llvm-commits mailing list