https://gcc.gnu.org/g:88db06d7da393f901aace95511f380657b9cbc9d

commit r16-5250-g88db06d7da393f901aace95511f380657b9cbc9d
Author: Andrew Pinski <[email protected]>
Date:   Sun Nov 9 14:07:15 2025 -0800

    cfgcleanup: Move check for dest containing non-local label/eh landing pad 
to tree_forwarder_block_p
    
    I noticed this check was in both remove_forwarder_block and 
remove_forwarder_block_with_phi but
    were slightly different in that eh landing pad was not being checked for 
remove_forwarder_block_with_phi
    when it definite should be.
    This folds the check into tree_forwarder_block_p instead as it is called 
right before hand anyways.
    
    The eh landing pad check was added to the non-phi one by 
r0-98233-g28e5ca15b76773 but missed the phi variant;
    I am not sure if it could show up there but it is better to have one common 
code than having two copies of
    slightly different checks.
    
    Bootstrapped and tested on x86_64-linux-gnu.
    
    gcc/ChangeLog:
    
            * tree-cfgcleanup.cc (remove_forwarder_block_with_phi): Remove 
check on non-local label.
            (remove_forwarder_block): Remove check on non-label/eh landing pad.
            (tree_forwarder_block_p): Add check on lable for an eh landing pad.
    
    Signed-off-by: Andrew Pinski <[email protected]>

Diff:
---
 gcc/tree-cfgcleanup.cc | 25 ++++---------------------
 1 file changed, 4 insertions(+), 21 deletions(-)

diff --git a/gcc/tree-cfgcleanup.cc b/gcc/tree-cfgcleanup.cc
index 6f97c7e41ad2..2f4fa0a7b8a8 100644
--- a/gcc/tree-cfgcleanup.cc
+++ b/gcc/tree-cfgcleanup.cc
@@ -425,6 +425,8 @@ tree_forwarder_block_p (basic_block bb, bool phi_wanted)
        return false;
   }
 
+  basic_block dest = single_succ_edge (bb)->dest;
+
   /* Now walk through the statements backward.  We can ignore labels,
      anything else means this is not a forwarder block.  */
   for (gsi = gsi_last_bb (bb); !gsi_end_p (gsi); gsi_prev (&gsi))
@@ -434,7 +436,8 @@ tree_forwarder_block_p (basic_block bb, bool phi_wanted)
       switch (gimple_code (stmt))
        {
        case GIMPLE_LABEL:
-         if (DECL_NONLOCAL (gimple_label_label (as_a <glabel *> (stmt))))
+         if (DECL_NONLOCAL (gimple_label_label (as_a <glabel *> (stmt)))
+             || EH_LANDING_PAD_NR (gimple_label_label (as_a <glabel *> 
(stmt))))
            return false;
          if (!optimize
              && (gimple_has_location (stmt)
@@ -455,12 +458,10 @@ tree_forwarder_block_p (basic_block bb, bool phi_wanted)
 
   if (current_loops)
     {
-      basic_block dest;
       /* Protect loop headers.  */
       if (bb_loop_header_p (bb))
        return false;
 
-      dest = EDGE_SUCC (bb, 0)->dest;
       /* Protect loop preheaders and latches if requested.  */
       if (dest->loop_father->header == dest)
        {
@@ -582,15 +583,6 @@ remove_forwarder_block (basic_block bb)
   edge_iterator ei;
   gimple_stmt_iterator gsi, gsi_to;
 
-  /* If the destination block consists of a nonlocal label or is a
-     EH landing pad, do not merge it.  */
-  stmt = first_stmt (dest);
-  if (stmt)
-    if (glabel *label_stmt = dyn_cast <glabel *> (stmt))
-      if (DECL_NONLOCAL (gimple_label_label (label_stmt))
-         || EH_LANDING_PAD_NR (gimple_label_label (label_stmt)) != 0)
-       return false;
-
   /* If there is an abnormal edge to basic block BB, but not into
      dest, problems might occur during removal of the phi node at out
      of ssa due to overlapping live ranges of registers.
@@ -1253,17 +1245,8 @@ remove_forwarder_block_with_phi (basic_block bb)
 {
   edge succ = single_succ_edge (bb);
   basic_block dest = succ->dest;
-  gimple *label;
   basic_block dombb, domdest, dom;
 
-  /* If the destination block consists of a nonlocal label, do not
-     merge it.  */
-  label = first_stmt (dest);
-  if (label)
-    if (glabel *label_stmt = dyn_cast <glabel *> (label))
-      if (DECL_NONLOCAL (gimple_label_label (label_stmt)))
-       return false;
-
   /* Record BB's single pred in case we need to update the father
      loop's latch information later.  */
   basic_block pred = NULL;

Reply via email to