On Thu, 10 Sep 2026, Aldy Hernandez wrote:

> There are two insn counts now.  Rename this one to say what it is, the
> path's insns less the branch we get to remove.  This keeps it distinct
> from path_stats::n_insns, the running total.

But why does m_net_insns have to be a class member rather than
a local variable in 
back_threader_profitability::possibly_profitable_path_p?
It gets overridden each time it is called?

> gcc/ChangeLog:
> 
>       * tree-ssa-threadbackward.cc (back_threader_profitability):
>       Rename m_n_insns to m_net_insns.
>       (back_threader_profitability::possibly_profitable_path_p):
>       Adjust.
>       (back_threader_profitability::profitable_path_p): Adjust.
> ---
>  gcc/tree-ssa-threadbackward.cc | 24 ++++++++++++------------
>  1 file changed, 12 insertions(+), 12 deletions(-)
> 
> diff --git a/gcc/tree-ssa-threadbackward.cc b/gcc/tree-ssa-threadbackward.cc
> index 03a7e1db50c..dd53c99db96 100644
> --- a/gcc/tree-ssa-threadbackward.cc
> +++ b/gcc/tree-ssa-threadbackward.cc
> @@ -86,7 +86,7 @@ private:
>    };
>    path_stats m_stats;
>    // Number of insns on the path, less the branch we get to remove.
> -  int m_n_insns;
> +  int m_net_insns;
>    // One entry per push.  These are the stats as they stood before that push,
>    // and the insns of the block.  Basically the entry pushed for m_path[i]
>    // accounts m_path[i - 1].
> @@ -762,12 +762,12 @@ back_threader_profitability::possibly_profitable_path_p
>    /* We are going to remove the control statement at the end of the
>       last block in the threading path.  So don't count it against our
>       statement count.  */
> -  m_n_insns = m_stats.n_insns - m_exit_jump_benefit;
> +  m_net_insns = m_stats.n_insns - m_exit_jump_benefit;
>  
>    if (dump_file && (dump_flags & TDF_DETAILS))
>      fprintf (dump_file, "\n  Control statement insns: %i\n"
>            "  Overall: %i insns\n",
> -          m_exit_jump_benefit, m_n_insns);
> +          m_exit_jump_benefit, m_net_insns);
>  
>    /* Threading is profitable if the path duplicated is hot but also
>       in a case we separate cold path from hot path and permit optimization
> @@ -775,7 +775,7 @@ back_threader_profitability::possibly_profitable_path_p
>       as in PR 78407 this leads to noticeable improvements.  */
>    if (m_speed_p)
>      {
> -      if (m_n_insns >= param_max_fsm_thread_path_insns)
> +      if (m_net_insns >= param_max_fsm_thread_path_insns)
>       {
>         if (dump_file && (dump_flags & TDF_DETAILS))
>           fprintf (dump_file, "  FAIL: Jump-thread path not considered: "
> @@ -793,12 +793,12 @@ back_threader_profitability::possibly_profitable_path_p
>         return false;
>       }
>      }
> -  else if (m_n_insns > 1)
> +  else if (m_net_insns > 1)
>      {
>        if (dump_file && (dump_flags & TDF_DETAILS))
>       fprintf (dump_file, "  FAIL: Jump-thread path not considered: "
>                "duplication of %i insns is needed and optimizing for size.\n",
> -              m_n_insns);
> +              m_net_insns);
>        return false;
>      }
>  
> @@ -811,7 +811,7 @@ back_threader_profitability::possibly_profitable_path_p
>    if ((!m_threaded_multiway_branch
>         || !loop->latch
>         || loop->latch->index == EXIT_BLOCK)
> -      && (m_n_insns * param_fsm_scale_path_stmts
> +      && (m_net_insns * param_fsm_scale_path_stmts
>         >= param_max_jump_thread_duplication_stmts))
>      {
>        if (dump_file && (dump_flags & TDF_DETAILS))
> @@ -822,7 +822,7 @@ back_threader_profitability::possibly_profitable_path_p
>      }
>    *large_non_fsm = (!(m_stats.threaded_through_latch
>                     && m_threaded_multiway_branch)
> -                 && (m_n_insns * param_fsm_scale_path_stmts
> +                 && (m_net_insns * param_fsm_scale_path_stmts
>                       >= param_max_jump_thread_duplication_stmts));
>  
>    if (dump_file && (dump_flags & TDF_DETAILS))
> @@ -878,12 +878,12 @@ back_threader_profitability::profitable_path_p (const 
> vec<basic_block> &m_path,
>         return false;
>       }
>      }
> -  else if (m_n_insns > 1)
> +  else if (m_net_insns > 1)
>      {
>        if (dump_file && (dump_flags & TDF_DETAILS))
>       fprintf (dump_file, "  FAIL: Jump-thread path not considered: "
>                "duplication of %i insns is needed and optimizing for size.\n",
> -              m_n_insns);
> +              m_net_insns);
>        return false;
>      }
>  
> @@ -896,7 +896,7 @@ back_threader_profitability::profitable_path_p (const 
> vec<basic_block> &m_path,
>    if (!m_threaded_multiway_branch
>        && *creates_irreducible_loop
>        && (!(cfun->curr_properties & PROP_loop_opts_done)
> -       || (m_n_insns * param_fsm_scale_path_stmts
> +       || (m_net_insns * param_fsm_scale_path_stmts
>             >= param_max_jump_thread_duplication_stmts)))
>      {
>        if (dump_file && (dump_flags & TDF_DETAILS))
> @@ -912,7 +912,7 @@ back_threader_profitability::profitable_path_p (const 
> vec<basic_block> &m_path,
>       case, drastically reduce the number of statements we are allowed
>       to copy.  */
>    if (!(m_stats.threaded_through_latch && m_threaded_multiway_branch)
> -      && (m_n_insns * param_fsm_scale_path_stmts
> +      && (m_net_insns * param_fsm_scale_path_stmts
>         >= param_max_jump_thread_duplication_stmts))
>      {
>        if (dump_file && (dump_flags & TDF_DETAILS))
> 

-- 
Richard Biener <[email protected]>
SUSE Software Solutions Germany GmbH,
Frankenstrasse 146, 90461 Nuernberg, Germany;
GF: Jochen Jaser, Andrew McDonald, Abhinav Puri; (HRB 36809, AG Nuernberg)

Reply via email to