[llvm-commits] [llvm] r170335 - /llvm/trunk/lib/Transforms/Scalar/SimplifyCFGPass.cpp

Evgeniy Stepanov eugeni.stepanov at gmail.com
Mon Dec 17 06:28:00 PST 2012


Author: eugenis
Date: Mon Dec 17 08:28:00 2012
New Revision: 170335

URL: http://llvm.org/viewvc/llvm-project?rev=170335&view=rev
Log:
Optimize tree walking in markAliveBlocks.

Check whether a BB is known as reachable before adding it to the worklist.
This way BB's with multiple predecessors are added to the list no more than
once.

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

Modified: llvm/trunk/lib/Transforms/Scalar/SimplifyCFGPass.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/SimplifyCFGPass.cpp?rev=170335&r1=170334&r2=170335&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/SimplifyCFGPass.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/SimplifyCFGPass.cpp Mon Dec 17 08:28:00 2012
@@ -111,13 +111,11 @@
 
   SmallVector<BasicBlock*, 128> Worklist;
   Worklist.push_back(BB);
+  Reachable.insert(BB);
   bool Changed = false;
   do {
     BB = Worklist.pop_back_val();
 
-    if (!Reachable.insert(BB))
-      continue;
-
     // Do a quick scan of the basic block, turning any obviously unreachable
     // instructions into LLVM unreachable insts.  The instruction combining pass
     // canonicalizes unreachable insts into stores to null or undef.
@@ -176,7 +174,8 @@
 
     Changed |= ConstantFoldTerminator(BB, true);
     for (succ_iterator SI = succ_begin(BB), SE = succ_end(BB); SI != SE; ++SI)
-      Worklist.push_back(*SI);
+      if (Reachable.insert(*SI))
+        Worklist.push_back(*SI);
   } while (!Worklist.empty());
   return Changed;
 }





More information about the llvm-commits mailing list