[SimplifyCFG] FoldBranchToCommonDest(): bonus instrns must only be used by PHI nodes...
authorRoman Lebedev <lebedev.ri@gmail.com>
Sat, 12 Dec 2020 12:48:58 +0000 (15:48 +0300)
committerRoman Lebedev <lebedev.ri@gmail.com>
Sat, 12 Dec 2020 21:06:57 +0000 (00:06 +0300)
commitd38205144febf4dc42c9270c6aa3d978f1ef65e1
tree2e0e47f67d6dd5f5e254c6b1c1b207192e9ed65e
parentce4040a43d54b45c924b109d0e44f0064937e539
[SimplifyCFG] FoldBranchToCommonDest(): bonus instrns must only be used by PHI nodes in successors (PR48450)

In particular, if the successor block, which is about to get a new
predecessor block, currently only has a single predecessor,
then the bonus instructions will be directly used within said successor,
which is fine, since the block with bonus instructions dominates that
successor. But once there's a new predecessor, the IR is no longer valid,
and we don't fix it, because we only update PHI nodes.

Which means, the live-out bonus instructions must be exclusively used
by the PHI nodes in successor blocks. So we have to form trivial PHI nodes.
which will then be successfully updated to recieve cloned bonus instns.

This all works fine, except for the fact that we don't have access to
the dominator tree, and we don't ignore unreachable code,
so we sometimes do end up having to deal with some weird IR.

Fixes https://bugs.llvm.org/show_bug.cgi?id=48450
llvm/lib/Transforms/Utils/SimplifyCFG.cpp
llvm/test/Transforms/SimplifyCFG/fold-branch-to-common-dest.ll