On Mon, Oct 14, 2024 at 4:26 AM Andrew Pinski <quic_apin...@quicinc.com> wrote:
>
> This is the updated patch with the suggestion from:
> https://gcc.gnu.org/pipermail/gcc-patches/2024-October/665217.html
> Where we use a second arg/param to set which passes we want to have
> the remove_unused_locals on the dce.
>
> Bootstrapped and tested on x86_64-linux-gnu.

OK.

Thanks,
Richard.

> gcc/ChangeLog:
>
>         PR tree-optimize/117096
>         * passes.def: Update some of the dce/cd-cde passes setting
>         the 2nd arg to true.
>         Also remove comment about stdarg since dce does it.
>         * tree-ssa-dce.cc (pass_dce): Add remove_unused_locals_p field.
>         Update set_pass_param to allow for 2nd param.
>         Use remove_unused_locals_p in execute to return 
> TODO_remove_unused_locals.
>         (pass_cd_dce): Likewise.
>         * tree-stdarg.cc (pass_data_stdarg): Remove TODO_remove_unused_locals.
>
> Signed-off-by: Andrew Pinski <quic_apin...@quicinc.com>
> ---
>  gcc/passes.def      | 11 ++++-------
>  gcc/tree-ssa-dce.cc | 18 ++++++++++++++----
>  gcc/tree-stdarg.cc  |  2 +-
>  3 files changed, 19 insertions(+), 12 deletions(-)
>
> diff --git a/gcc/passes.def b/gcc/passes.def
> index 40162ac20a0..7d01227eed1 100644
> --- a/gcc/passes.def
> +++ b/gcc/passes.def
> @@ -92,7 +92,7 @@ along with GCC; see the file COPYING3.  If not see
>           NEXT_PASS (pass_early_vrp);
>           NEXT_PASS (pass_merge_phi);
>            NEXT_PASS (pass_dse);
> -         NEXT_PASS (pass_cd_dce, false /* update_address_taken_p */);
> +         NEXT_PASS (pass_cd_dce, false /* update_address_taken_p */, true /* 
> remove_unused_locals */);
>           NEXT_PASS (pass_phiopt, true /* early_p */);
>           NEXT_PASS (pass_tail_recursion);
>           NEXT_PASS (pass_if_to_switch);
> @@ -225,10 +225,7 @@ along with GCC; see the file COPYING3.  If not see
>        NEXT_PASS (pass_vrp, false /* final_p*/);
>        NEXT_PASS (pass_array_bounds);
>        NEXT_PASS (pass_dse);
> -      NEXT_PASS (pass_dce);
> -      /* pass_stdarg is always run and at this point we execute
> -         TODO_remove_unused_locals to prune CLOBBERs of dead
> -        variables which are otherwise a churn on alias walkings.  */
> +      NEXT_PASS (pass_dce, false /* update_address_taken_p */, true /* 
> remove_unused_locals */);
>        NEXT_PASS (pass_stdarg);
>        NEXT_PASS (pass_call_cdce);
>        NEXT_PASS (pass_cselim);
> @@ -273,7 +270,7 @@ along with GCC; see the file COPYING3.  If not see
>        NEXT_PASS (pass_asan);
>        NEXT_PASS (pass_tsan);
>        NEXT_PASS (pass_dse, true /* use DR analysis */);
> -      NEXT_PASS (pass_dce);
> +      NEXT_PASS (pass_dce, false /* update_address_taken_p */, false /* 
> remove_unused_locals */);
>        /* Pass group that runs when 1) enabled, 2) there are loops
>          in the function.  Make sure to run pass_fix_loops before
>          to discover/remove loops before running the gate function
> @@ -355,7 +352,7 @@ along with GCC; see the file COPYING3.  If not see
>        NEXT_PASS (pass_ccp, true /* nonzero_p */);
>        NEXT_PASS (pass_warn_restrict);
>        NEXT_PASS (pass_dse);
> -      NEXT_PASS (pass_dce, true /* update_address_taken_p */);
> +      NEXT_PASS (pass_dce, true /* update_address_taken_p */, true /* 
> remove_unused_locals */);
>        /* After late DCE we rewrite no longer addressed locals into SSA
>          form if possible.  */
>        NEXT_PASS (pass_forwprop);
> diff --git a/gcc/tree-ssa-dce.cc b/gcc/tree-ssa-dce.cc
> index 69249c73013..66612b5d575 100644
> --- a/gcc/tree-ssa-dce.cc
> +++ b/gcc/tree-ssa-dce.cc
> @@ -2096,18 +2096,23 @@ public:
>    opt_pass * clone () final override { return new pass_dce (m_ctxt); }
>    void set_pass_param (unsigned n, bool param) final override
>      {
> -      gcc_assert (n == 0);
> -      update_address_taken_p = param;
> +      gcc_assert (n == 0 || n == 1);
> +      if (n == 0)
> +       update_address_taken_p = param;
> +      else if (n == 1)
> +       remove_unused_locals_p = param;
>      }
>    bool gate (function *) final override { return flag_tree_dce != 0; }
>    unsigned int execute (function *) final override
>      {
>        return (tree_ssa_dce ()
> +             | (remove_unused_locals_p ? TODO_remove_unused_locals : 0)
>               | (update_address_taken_p ? TODO_update_address_taken : 0));
>      }
>
>  private:
>    bool update_address_taken_p;
> +  bool remove_unused_locals_p = false;
>  }; // class pass_dce
>
>  } // anon namespace
> @@ -2144,18 +2149,23 @@ public:
>    opt_pass * clone () final override { return new pass_cd_dce (m_ctxt); }
>    void set_pass_param (unsigned n, bool param) final override
>      {
> -      gcc_assert (n == 0);
> -      update_address_taken_p = param;
> +      gcc_assert (n == 0 || n == 1);
> +      if (n == 0)
> +       update_address_taken_p = param;
> +      else if (n == 1)
> +       remove_unused_locals_p = param;
>      }
>    bool gate (function *) final override { return flag_tree_dce != 0; }
>    unsigned int execute (function *) final override
>      {
>        return (tree_ssa_cd_dce ()
> +             | (remove_unused_locals_p ? TODO_remove_unused_locals : 0)
>               | (update_address_taken_p ? TODO_update_address_taken : 0));
>      }
>
>  private:
>    bool update_address_taken_p;
> +  bool remove_unused_locals_p = false;
>  }; // class pass_cd_dce
>
>  } // anon namespace
> diff --git a/gcc/tree-stdarg.cc b/gcc/tree-stdarg.cc
> index 1167fd9f224..33763cd3d11 100644
> --- a/gcc/tree-stdarg.cc
> +++ b/gcc/tree-stdarg.cc
> @@ -1114,7 +1114,7 @@ const pass_data pass_data_stdarg =
>    ( PROP_cfg | PROP_ssa ), /* properties_required */
>    PROP_gimple_lva, /* properties_provided */
>    0, /* properties_destroyed */
> -  TODO_remove_unused_locals, /* todo_flags_start */
> +  0, /* todo_flags_start */
>    0, /* todo_flags_finish */
>  };
>
> --
> 2.43.0
>

Reply via email to