]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
cfglceanup: Fix check for preheaders
authorAndrew Pinski <andrew.pinski@oss.qualcomm.com>
Sat, 15 Nov 2025 22:51:32 +0000 (14:51 -0800)
committerAndrew Pinski <andrew.pinski@oss.qualcomm.com>
Sun, 16 Nov 2025 18:02:03 +0000 (10:02 -0800)
I had messed up the check in r16-5258-g1d8e2d51e5c5cb for preheaders
where return to remvoe the forwarder preheader block even if LOOPS_HAVE_PREHEADERS
was set. I am not sure how often this happens because most of the time the pre-header
will have an incoming phi block anyways but it is safer not to remove it in this case.

Bootstrapped and tested on x86_64-linux-gnu.

gcc/ChangeLog:

* tree-cfgcleanup.cc (tree_forwarder_block_p): Restore check on
LOOPS_HAVE_PREHEADERS.

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
gcc/tree-cfgcleanup.cc

index ac1394ac1d48c334a3e8a48e0c2a2673b37c29b2..a78b711d82c31e75dbbef7ff23c79731ef3926be 100644 (file)
@@ -519,11 +519,14 @@ tree_forwarder_block_p (basic_block bb)
            }
          /* cleanup_tree_cfg_noloop just created the loop preheader, don't
             remove it if it has phis.  */
-         else if (bb->loop_father == loop_outer (dest->loop_father))
-           return gimple_seq_empty_p (phi_nodes (bb));
-         /* Always preserve other edges into loop headers that are
-            not simple latches or preheaders.  */
-         return false;
+         else if (bb->loop_father == loop_outer (dest->loop_father)
+                  && gimple_seq_empty_p (phi_nodes (bb))
+                  && !loops_state_satisfies_p (LOOPS_HAVE_PREHEADERS))
+           ;
+         else
+           /* Always preserve other edges into loop headers that are
+              not simple latches or preheaders.  */
+           return false;
        }
     }