]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
cfgcleanup: Move check for dest containing non-local label/eh landing pad to tree_for...
authorAndrew Pinski <andrew.pinski@oss.qualcomm.com>
Sun, 9 Nov 2025 22:07:15 +0000 (14:07 -0800)
committerAndrew Pinski <andrew.pinski@oss.qualcomm.com>
Thu, 13 Nov 2025 20:32:24 +0000 (12:32 -0800)
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 <andrew.pinski@oss.qualcomm.com>
gcc/tree-cfgcleanup.cc

index 6f97c7e41ad21b9a3c968b1d27a8a80b3b35eee1..2f4fa0a7b8a87918076516b6fc627f1851a56d74 100644 (file)
@@ -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;