[PATCH] D35028: [GlobalOpt] Remove unreachable blocks before optimizing a function

Davide Italiano via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Jul 9 06:14:34 PDT 2017


davide added a comment.

In https://reviews.llvm.org/D35028#800177, @dberlin wrote:

> Actually, thinking about this more, i'm confused.
>
> removeUnreachableBlocks does silly things (it computes liveness and blah blah blah blah) and modifies the CFG, but those silly things are irrelevant to the problem here.
>
> The following should suffice to fix these bugs without explicitly recalculating the dom tree:
>
>   Walk blocks using  RPO iterator, put them in Live set
>  
>   For each block in function not in Live:
>     if (Processed.count(X)) skip it.
>  
>     for X in depth_first (DT->getNode(block)):
>          Processed.insert(X)
>           for (BasicBlock *Successor : successors(X))
>             Successor->removePredecessor(X);
>           if (LVI)
>             LVI->eraseBlock(X);
>           DT->eraseBlock(DT->getNode(X))
>           X->dropAllReferences();
>           X->eraseFromParent();
>  
>
>
> You have to erase the blocks in the dom tree leaves first.
>
> Otherwise, this is just "find forward unreachable blocks, delete them" (the code is from removeUnreachableBlocks)
>
> By definition, any block dominated by an unreachable block is also forward unreachable, so we just process them as part of the depth first walk.


This is https://reviews.llvm.org/D35142


Repository:
  rL LLVM

https://reviews.llvm.org/D35028





More information about the llvm-commits mailing list