]> git.ipfire.org Git - thirdparty/gcc.git/commit
cfgcleanup: Support merging forwarder blocks with phis [PR122493]
authorAndrew Pinski <andrew.pinski@oss.qualcomm.com>
Tue, 11 Nov 2025 19:29:38 +0000 (11:29 -0800)
committerAndrew Pinski <andrew.pinski@oss.qualcomm.com>
Thu, 13 Nov 2025 20:56:54 +0000 (12:56 -0800)
commit1d8e2d51e5c5cbdb6ad6f455a050af869103dad4
tree365be97a3376cc0001d0aaa5a53e856c2e95dc6e
parent6c0f06cdba12eeb51d3ca0f035e6e370779027f8
cfgcleanup: Support merging forwarder blocks with phis [PR122493]

This adds support for merging forwarder blocks with phis in cleanupcfg.
This patch might seem small but that is because the previous patches were
done to build up to make it easier to add this support.

There is still one more patch to merge remove_forwarder_block
and remove_forwarder_block_with_phi since remove_forwarder_block_with_phi
supports splitting an edge which is not supported as an option in remove_forwarder_block.
The splitting edge option should not be enabled for cfgcleanup but only for mergephi.

Note r8-338-ge7d70c6c3bccb2 added always creating a preheader for loops so we should
protect them if we have a phi node as it goes back and forth here. And both the gimple
and RTL loop code likes to have this preheader in the case of having the same constant
value being starting of the loop.

explaination on testcase changes
gcc.target/i386/pr121062-1.c needed a small change because there is a basic block
which is not duplicated so only one `movq reg, -1` is there instead of 2.

uninit-pred-7_a.c is xfailed and filed as PR122660, some analysis in the PR already of
the difference now.

uninit-pred-5.C was actually a false positive because when
m_best_candidate is non-NULL, m_best_candidate_len is always initialized.
The log message on the testcase is wrong if you manually fall the path
you can notice that. With an extra jump threading after the merging of
some bbs, the false positive is now no longer happening. So change the
dg-warning to dg-bogus.

ssa-dom-thread-7.c now jump threads 12 times in thread2 instead of 8

Bootstrapped and tested on x86_64-linux-gnu.

PR tree-optimization/122493
gcc/ChangeLog:

* tree-cfgcleanup.cc (tree_forwarder_block_p): Change bool argument
to a must have phi and allow phis if it is false.
(remove_forwarder_block): Add support for merging of forwarder blocks
with phis.

gcc/testsuite/ChangeLog:

* gcc.target/i386/pr121062-1.c: Update count.
* gcc.dg/uninit-pred-7_a.c: xfail line 23.
* g++.dg/uninit-pred-5.C: Change dg-warning to dg-bogus.
* gcc.dg/tree-ssa/ssa-dom-thread-7.c: Update count of jump thread.

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
gcc/testsuite/g++.dg/uninit-pred-5.C
gcc/testsuite/gcc.dg/tree-ssa/ssa-dom-thread-7.c
gcc/testsuite/gcc.dg/uninit-pred-7_a.c
gcc/testsuite/gcc.target/i386/pr121062-1.c
gcc/tree-cfgcleanup.cc