[PATCH] D30774: [SimplifyCFG] Merging duplicated basic blocks

Hiroshi Inoue via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 8 23:05:05 PST 2017


inouehrs created this revision.

This patch enables basic block deduplication, which finds duplicated basic blocks and merges them into one block, in SimplifyCFG pass.
Such basic block duplication is common and so Control Flow Optimizer (BranchFolding) does the similar optimization for Machine Function at last of the code generation. However, eliminating such duplication in an early phase increases optimization opportunities in other optimizers, such as shrink wrapping.
In SimplifyCFG, tail-sinking does similar optimization. But the tail-sinking can optimize basic blocks if all the incoming unconditional branches into one block have the duplicated instructions before the branch. The basic block deduplication can merge two (or more) BBs ending with unconditional branch into the same block regardless of the other incoming branches.
As long as I tested, this patch does not visibly increase the compilation time while compiling the LLVM source tree.

The original motivation of this patch is to optimize the hot method of tcmalloc. In which GCC can apply shrink wrapping, but LLVM cannot. By applying this patch and another patch on shrink wrapping I will post soon, LLVM can do shrink wrapping for this hot method.


https://reviews.llvm.org/D30774

Files:
  lib/Transforms/Utils/SimplifyCFG.cpp
  test/Transforms/SimplifyCFG/dedup-bb.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D30774.91129.patch
Type: text/x-patch
Size: 9908 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170309/a8d35f2c/attachment-0001.bin>


More information about the llvm-commits mailing list