[llvm-commits] [llvm] r46767 - /llvm/trunk/lib/Transforms/Utils/PromoteMemoryToRegister.cpp

Chris Lattner sabre at nondot.org
Tue Feb 5 13:26:24 PST 2008


Author: lattner
Date: Tue Feb  5 15:26:23 2008
New Revision: 46767

URL: http://llvm.org/viewvc/llvm-project?rev=46767&view=rev
Log:
Make RenamePass faster by making the 'is this a new phi node'
check more intelligent.  This speeds up mem2reg from 5.29s to 
0.79s on a synthetic testcase with tons of predecessors and
phi nodes.

Modified:
    llvm/trunk/lib/Transforms/Utils/PromoteMemoryToRegister.cpp

Modified: llvm/trunk/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/PromoteMemoryToRegister.cpp?rev=46767&r1=46766&r2=46767&view=diff

==============================================================================
--- llvm/trunk/lib/Transforms/Utils/PromoteMemoryToRegister.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/PromoteMemoryToRegister.cpp Tue Feb  5 15:26:23 2008
@@ -849,7 +849,6 @@
   return true;
 }
 
-
 // RenamePass - Recursively traverse the CFG of the function, renaming loads and
 // stores to the allocas which we are promoting.  IncomingVals indicates what
 // value each Alloca contains on exit from the predecessor block Pred.
@@ -877,6 +876,14 @@
     // If we have PHI nodes to update, compute the number of edges from Pred to
     // BB.
     if (!HasPredEntries) {
+      // We want to be able to distinguish between PHI nodes being inserted by
+      // this invocation of mem2reg from those phi nodes that already existed in
+      // the IR before mem2reg was run.  We determine that APN is being inserted
+      // because it is missing incoming edges.  All other PHI nodes being
+      // inserted by this pass of mem2reg will have the same number of incoming
+      // operands so far.  Remember this count.
+      unsigned NewPHINumOperands = APN->getNumOperands();
+      
       TerminatorInst *PredTerm = Pred->getTerminator();
       unsigned NumEdges = 0;
       for (unsigned i = 0, e = PredTerm->getNumSuccessors(); i != e; ++i) {
@@ -902,16 +909,9 @@
         APN = dyn_cast<PHINode>(PNI);
         if (APN == 0) break;
         
-        // Verify it doesn't already have entries for Pred.  If it does, it is
-        // not being inserted by this mem2reg invocation.
-        HasPredEntries = false;
-        for (unsigned i = 0, e = APN->getNumIncomingValues(); i != e; ++i) {
-          if (APN->getIncomingBlock(i) == Pred) {
-            HasPredEntries = true;
-            break;
-          }
-        }
-      } while (!HasPredEntries);
+        // Verify that it is missing entries.  If not, it is not being inserted
+        // by this mem2reg invocation so we want to ignore it.
+      } while (APN->getNumOperands() == NewPHINumOperands);
     }
   }
   





More information about the llvm-commits mailing list