[PATCH] D81835: [SimplifyCFG] Fix inconsistency in block size assessment for threading

Max Kazantsev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 15 03:46:43 PDT 2020


mkazantsev created this revision.
mkazantsev added reviewers: xbolva00, arsenm, jnspaulsson, spatel, asbirlea.
Herald added subscribers: llvm-commits, hiraditya, wdng.
Herald added a project: LLVM.
mkazantsev updated this revision to Diff 270709.
mkazantsev added a comment.
mkazantsev added a child revision: D81375: [InstCombine] Simplify boolean Phis with const inputs using CFG.

clang-format


Sometimes SimplifyCFG may decide to perform jump threading. In order
to do it, it follows the following algorithm:

1. Checks if the block is small enough for threading;
2. If yes, inserts a PR Phi relying that the next iteration
3. The next iteration checks the block again and performs the threading.

This logic has a corner case: inserting the PR Phi increases block's size
by 1. If the block size at first check was max possible, one more Phi will
exceed this size, and we will neither perform threading nor remove the
created Phi node. As result, we will end up with worse IR than before.

This patch fixes this situation by excluding Phis from block size computation.
Excluding Phis from size computation for threading also makes sense by
itself because in case of threadign all those Phis will be removed.


https://reviews.llvm.org/D81835

Files:
  llvm/lib/Transforms/Utils/SimplifyCFG.cpp
  llvm/test/Transforms/PhaseOrdering/inlining-alignment-assumptions.ll
  llvm/test/Transforms/SimplifyCFG/unprofitable-pr.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D81835.270709.patch
Type: text/x-patch
Size: 9168 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200615/0986bcc2/attachment.bin>


More information about the llvm-commits mailing list