[PATCH] D31843: [LCSSA] Try to not walk the dominator tree more than necessary

Davide Italiano via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 10 11:07:28 PDT 2017


davide added a comment.

I realized part of the time spent by `blockDominatesAnExit` is doing *redundant* map lookups (and not doing the dominance check proper), which I think should always be constant time in this case as the dominator DFS numbering doesn't change. Precomputing the domtree nodes in advance saves a bit of computation and makes thing faster (at least on this testcase), but I'm unsure whether this would be a win in general (time goes down from 1:45m to 1:40).

Still a little disturbing that skipping the check entirely is *much* faster.

  --- a/lib/Transforms/Utils/LCSSA.cpp
  +++ b/lib/Transforms/Utils/LCSSA.cpp
  @@ -242,10 +242,10 @@ bool llvm::formLCSSAForInstructions(SmallVectorImpl<Instruction *> &Worklist,
   static bool
   blockDominatesAnExit(BasicBlock *BB,
                        DominatorTree &DT,
  -                     const SmallVectorImpl<BasicBlock *> &ExitBlocks) {
  +                     const SmallVectorImpl<DomTreeNode *> &ExitBlocks) {
     DomTreeNode *DomNode = DT.getNode(BB);
  -  return any_of(ExitBlocks, [&](BasicBlock *EB) {
  -    return DT.dominates(DomNode, DT.getNode(EB));
  +  return any_of(ExitBlocks, [&](DomTreeNode *EB) {
  +    return DT.dominates(DomNode, EB);
     });
   }
  
  @@ -260,6 +260,10 @@ bool llvm::formLCSSA(Loop &L, DominatorTree &DT, LoopInfo *LI,
     if (ExitBlocks.empty())
       return false;
  
  +  SmallVector<DomTreeNode *, 8> DomTreeNodeBlocks;
  +  for (auto *EBB : ExitBlocks)
  +    DomTreeNodeBlocks.push_back(DT.getNode(EBB));
  +
     SmallVector<Instruction *, 8> Worklist;
  
     // Look at all the instructions in the loop, checking to see if they have uses
  @@ -268,7 +272,7 @@ bool llvm::formLCSSA(Loop &L, DominatorTree &DT, LoopInfo *LI,
       // For large loops, avoid use-scanning by using dominance information:  In
       // particular, if a block does not dominate any of the loop exits, then none
       // of the values defined in the block could be used outside the loop.
  -    if (!blockDominatesAnExit(BB, DT, ExitBlocks))
  +    if (!blockDominatesAnExit(BB, DT, DomTreeNodeBlocks))
         continue;
  
       for (Instruction &I : *BB) {


https://reviews.llvm.org/D31843





More information about the llvm-commits mailing list