]> git.ipfire.org Git - thirdparty/gcc.git/commit
tree-cfgcleanup: Don't remove forwarder blocks (with phis) with phis that have abnorm...
authorAndrew Pinski <andrew.pinski@oss.qualcomm.com>
Wed, 20 May 2026 20:20:15 +0000 (13:20 -0700)
committerAndrew Pinski <andrew.pinski@oss.qualcomm.com>
Tue, 26 May 2026 20:00:07 +0000 (13:00 -0700)
commitec79b0779b6eeb9ef3b8a45f46a596cbb75a7844
treee0a995d5e54463d60cdb8c9016900a3c23066d5b
parentbd02a048e92a778c2d3fcc011b8a88e1ac6f8183
tree-cfgcleanup: Don't remove forwarder blocks (with phis) with phis that have abnormal uses [PR125396]

This was a latent bug in the checks for removing of a forwarder block which has a phi.

Take:
      <bb 15> [local count: 182536112]:
      # arr1$0_32 = PHI <arr1$0_36(ab)(11)>

      <bb 14> [local count: 206998870]:
      # arr1$0_43(ab) = PHI <arr1$0_25(ab)(13), 9(15)>
      # sj12_44(ab) = PHI <sj12_31(ab)(13), arr1$0_32(15)>
      f8 ();

Here bb 15 predecessor is a normal edge.
So when merging the forwarder bb 15 into bb14 we end up with:
      <bb 12> [local count: 206998870]:
      # arr1$0_42(ab) = PHI <arr1$0_24(ab)(11), 9(9)>
      # sj12_43(ab) = PHI <sj12_30(ab)(11), arr1$0_35(ab)(9)>
      f8 ();
and now there is an overlap of live range of arr1$0_35 and arr1$0_42.
So we need to reject the case where we have phis and the phi arguments that
use abnormal uses.

Changes since v1:
* v2: Look at phi arguments of the forwarder block rather than the dest bb
      having an abnormal edge out.
* v3: Fix bb_phis_references_abnormal_uses to use the gimple_phi_num_args to
      search over the phi arguments. Also fix the commit message which was wrong.

Bootstrapped and tested on x86_64-linux-gnu.

PR tree-optimization/125396

gcc/ChangeLog:

* tree-cfgcleanup.cc (bb_phis_references_abnormal_uses): New function.
(maybe_remove_forwarder_block): Check to make sure the
forwarder block does not have a phi that references ssa name that has
abnormal uses.

gcc/testsuite/ChangeLog:

* gcc.dg/torture/pr125396-1.c: New test.

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
gcc/testsuite/gcc.dg/torture/pr125396-1.c [new file with mode: 0644]
gcc/tree-cfgcleanup.cc