https://gcc.gnu.org/g:398c6ddf1e81ba0cfd14a600ff8ceb4611fc8cf6

commit r16-625-g398c6ddf1e81ba0cfd14a600ff8ceb4611fc8cf6
Author: Andrew Pinski <quic_apin...@quicinc.com>
Date:   Mon Apr 21 16:33:04 2025 -0700

    forwprop: Move around the marking bb for eh to after the local 
non-fold_stmt optimizations
    
    When moving the optimize_memcpy_to_memset optimization to forwprop from 
fold_stmt, the marking
    of the bb to purge for eh cleanup was not happening for the local 
optimizations but only after
    the fold_stmt, this causes g++.dg/torture/except-2.C to fail.
    So this patch moves the marking of the bbs for cleanups after the local 
forwprop optimizations
    instead of before.
    
    There was already code to add to to_purge after 
forward_propagate_into_comparison and removes
    that as it is now redundant.
    
    gcc/ChangeLog:
    
            * tree-ssa-forwprop.cc (pass_forwprop::execute): Move marking of 
to_purge bb
            and marking of fixup statements to after the local optimizations.
    
    Signed-off-by: Andrew Pinski <quic_apin...@quicinc.com>

Diff:
---
 gcc/tree-ssa-forwprop.cc | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/gcc/tree-ssa-forwprop.cc b/gcc/tree-ssa-forwprop.cc
index bcdec1aadc3e..4ec5b6a6ba1a 100644
--- a/gcc/tree-ssa-forwprop.cc
+++ b/gcc/tree-ssa-forwprop.cc
@@ -4497,6 +4497,8 @@ pass_forwprop::execute (function *fun)
                    }
                }
            }
+         if (substituted_p)
+           update_stmt (stmt);
          if (substituted_p
              && is_gimple_assign (stmt)
              && gimple_assign_rhs_code (stmt) == ADDR_EXPR)
@@ -4536,17 +4538,7 @@ pass_forwprop::execute (function *fun)
                          && !SSA_NAME_IS_DEFAULT_DEF (use))
                        bitmap_set_bit (simple_dce_worklist,
                                        SSA_NAME_VERSION (use));
-               }
-
-             if (changed || substituted_p)
-               {
-                 if (maybe_clean_or_replace_eh_stmt (orig_stmt, stmt))
-                   bitmap_set_bit (to_purge, bb->index);
-                 if (!was_noreturn
-                     && is_gimple_call (stmt) && gimple_call_noreturn_p (stmt))
-                   to_fixup.safe_push (stmt);
                  update_stmt (stmt);
-                 substituted_p = false;
                }
 
              switch (gimple_code (stmt))
@@ -4560,8 +4552,6 @@ pass_forwprop::execute (function *fun)
                      {
                        int did_something;
                        did_something = forward_propagate_into_comparison 
(&gsi);
-                       if (maybe_clean_or_replace_eh_stmt (stmt, gsi_stmt 
(gsi)))
-                         bitmap_set_bit (to_purge, bb->index);
                        if (did_something == 2)
                          cfg_changed = true;
                        changed |= did_something != 0;
@@ -4613,6 +4603,16 @@ pass_forwprop::execute (function *fun)
                default:;
                }
 
+             if (changed || substituted_p)
+               {
+                 substituted_p = false;
+                 stmt = gsi_stmt (gsi);
+                 if (maybe_clean_or_replace_eh_stmt (orig_stmt, stmt))
+                   bitmap_set_bit (to_purge, bb->index);
+                 if (!was_noreturn
+                     && is_gimple_call (stmt) && gimple_call_noreturn_p (stmt))
+                   to_fixup.safe_push (stmt);
+               }
              if (changed)
                {
                  /* If the stmt changed then re-visit it and the statements

Reply via email to