> Am 18.05.2025 um 08:26 schrieb Andrew Pinski <quic_apin...@quicinc.com>:
>
> Right now phiopt has the same code as mark_lhs_in_seq_for_dce
> inlined into match_simplify_replacement. Instead let's use the
> function in gimple-fold that does the same thing.
>
> Bootstrapped and tested on x86_64-linux-gnu.
Ok
Richard
> gcc/ChangeLog:
>
> * gimple-fold.cc (mark_lhs_in_seq_for_dce): Make
> non-static.
> * gimple-fold.h (mark_lhs_in_seq_for_dce): Declare.
> * tree-ssa-phiopt.cc (match_simplify_replacement): Use
> mark_lhs_in_seq_for_dce instead of manually looping.
>
> Signed-off-by: Andrew Pinski <quic_apin...@quicinc.com>
> ---
> gcc/gimple-fold.cc | 2 +-
> gcc/gimple-fold.h | 1 +
> gcc/tree-ssa-phiopt.cc | 13 +++----------
> 3 files changed, 5 insertions(+), 11 deletions(-)
>
> diff --git a/gcc/gimple-fold.cc b/gcc/gimple-fold.cc
> index b74fb8bb50c..0f437616d77 100644
> --- a/gcc/gimple-fold.cc
> +++ b/gcc/gimple-fold.cc
> @@ -6020,7 +6020,7 @@ has_use_on_stmt (tree name, gimple *stmt)
>
> /* Add the lhs of each statement of SEQ to DCE_WORKLIST. */
>
> -static void
> +void
> mark_lhs_in_seq_for_dce (bitmap dce_worklist, gimple_seq seq)
> {
> if (!dce_worklist)
> diff --git a/gcc/gimple-fold.h b/gcc/gimple-fold.h
> index afecbb8ceef..8b1e246b0c0 100644
> --- a/gcc/gimple-fold.h
> +++ b/gcc/gimple-fold.h
> @@ -264,6 +264,7 @@ gimple_build_round_up (gimple_seq *seq, tree type, tree
> old_size,
>
> extern bool gimple_stmt_nonnegative_warnv_p (gimple *, bool *, int = 0);
> extern bool gimple_stmt_integer_valued_real_p (gimple *, int = 0);
> +extern void mark_lhs_in_seq_for_dce (bitmap, gimple_seq);
>
> /* In gimple-match.cc. */
> extern tree gimple_simplify (enum tree_code, tree, tree,
> diff --git a/gcc/tree-ssa-phiopt.cc b/gcc/tree-ssa-phiopt.cc
> index 9724040fc3d..8c5908e5bff 100644
> --- a/gcc/tree-ssa-phiopt.cc
> +++ b/gcc/tree-ssa-phiopt.cc
> @@ -1001,16 +1001,9 @@ match_simplify_replacement (basic_block cond_bb,
> basic_block middle_bb,
> if (seq)
> {
> // Mark the lhs of the new statements maybe for dce
> - gimple_stmt_iterator gsi1 = gsi_start (seq);
> - for (; !gsi_end_p (gsi1); gsi_next (&gsi1))
> - {
> - gimple *stmt = gsi_stmt (gsi1);
> - tree name = gimple_get_lhs (stmt);
> - if (name && TREE_CODE (name) == SSA_NAME)
> - bitmap_set_bit (exprs_maybe_dce, SSA_NAME_VERSION (name));
> - }
> - gsi_insert_seq_before (&gsi, seq, GSI_CONTINUE_LINKING);
> - }
> + mark_lhs_in_seq_for_dce (exprs_maybe_dce, seq);
> + gsi_insert_seq_before (&gsi, seq, GSI_CONTINUE_LINKING);
> + }
>
> /* If there was a statement to move, move it to right before
> the original conditional. */
> --
> 2.43.0
>