[SimplifyCFG] Fix inconsistency in block size assessment for threading
authorMax Kazantsev <mkazantsev@azul.com>
Tue, 30 Jun 2020 05:38:15 +0000 (12:38 +0700)
committerMax Kazantsev <mkazantsev@azul.com>
Tue, 30 Jun 2020 05:40:07 +0000 (12:40 +0700)
commitf01d9e6fc3e291a2faed8c9b7dcbabf760f32bd6
tree48a9611d2fca97c97c1068a2114751490c4d984b
parent11cd9770174603aa62deabbe96c7d0db64d07058
[SimplifyCFG] Fix inconsistency in block size assessment for threading

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 will remove it
   by performing jump threading;
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.

Differential Revision: https://reviews.llvm.org/D81835
Reviewed By: asbirlea, nikic
llvm/lib/Transforms/Utils/SimplifyCFG.cpp
llvm/test/Transforms/SimplifyCFG/unprofitable-pr.ll