On Tue, Nov 3, 2026 at 7:36 PM Andrew MacLeod <[email protected]> wrote:
>
> There is code in ipa-prop which checks for a pointer range, and then looks to 
> see if there is points to info, eiother invariant to or away,.  If ti si 
> there, it clears it in one case and proceeds, and bails in the other.    This 
> provides a helper class which simply clears the fields if it is present and 
> fails the is_gimple_ip_invariant test.   This simplifies the client code, and 
> in the latter case still allows the range itself to be propagated rather than 
> bailing.
>
> Bootstraps on x86_64-pc-linux-gnu with no regressions.  OK?
>
> Andrew
>
>
> Rather than looking for and clearing points to information that is
> gimple_ip_invariant, introduce a routine and call it.
>
>         * ipa-prop.cc (ipa_set_jfunc_vr): Call enw routine.
>         (ipa_record_return_value_range_1): Likewise.
>         * tree-ssanames.cc (clear_function_local_points_to): New.
>         * tree-ssanames.h (clear_function_local_points_to)): New prototype.
> ---
>  gcc/ipa-prop.cc      | 30 ++++++++++--------------------
>  gcc/tree-ssanames.cc | 22 ++++++++++++++++++++++
>  gcc/tree-ssanames.h  |  1 +
>  3 files changed, 33 insertions(+), 20 deletions(-)
>
> diff --git a/gcc/ipa-prop.cc b/gcc/ipa-prop.cc
> index eb220b92eab..4df4cdfbcec 100644
> --- a/gcc/ipa-prop.cc
> +++ b/gcc/ipa-prop.cc
> @@ -2402,11 +2402,8 @@ ipa_set_jfunc_vr (ipa_jump_func *jf, const vrange &tmp)
>       the bitmask remain valid.  */
>    if (is_a <prange> (tmp))
>      {
> -      const prange &pr = as_a <prange> (tmp);
> -      tree t = pr.pt_invariant ();
> -      if (!t)
> -       t = pr.pt_invariant_away ();
> -      if (t && !is_gimple_ip_invariant (t))
> +      prange p = as_a <prange> (tmp);
> +      if (clear_function_local_points_to (p))
>         {
>           if (dump_file && (dump_flags & TDF_DETAILS))
>             {
> @@ -2414,13 +2411,11 @@ ipa_set_jfunc_vr (ipa_jump_func *jf, const vrange 
> &tmp)
>               tmp.dump (dump_file);
>               fprintf (dump_file, "\n");
>             }
> -         prange stripped = pr;
> -         stripped.set_pt_unknown ();
> -         jf->m_vr = ipa_get_value_range (stripped);
> -         return;
>         }
> +      jf->m_vr = ipa_get_value_range (p);
>      }
> -  jf->m_vr = ipa_get_value_range (tmp);
> +  else
> +    jf->m_vr = ipa_get_value_range (tmp);
>  }
>
>  static void
> @@ -6037,21 +6032,16 @@ ipa_record_return_value_range_1 (cgraph_node *n, 
> value_range val)
>    // Remove local invariant from return values.
>    if (is_a<prange> (val))
>      {
> -      const prange &pr = as_a <prange> (val);
> -      tree t = pr.pt_invariant ();
> -      if (!t)
> -       t = pr.pt_invariant_away ();
> -      if (t && !is_gimple_ip_invariant (t))
> -        {
> +      if (clear_function_local_points_to (val))
> +       {
>           if (dump_file && (dump_flags & TDF_DETAILS))
>             {
> -             fprintf (dump_file, "Could not record return range of %s:", 
> n->dump_name ());
> +             fprintf (dump_file, "Dropping non ipa invariant points-to 
> from");
> +             fprintf (dump_file, " return range of %s:", n->dump_name ());
>               val.dump (dump_file);
>               fprintf (dump_file, "\n");
> -             fprintf (dump_file, "Because uses non ipa invariant\n");
>             }
> -         return;
> -        }
> +       }
>      }
>    if (!ipa_return_value_sum)
>      {
> diff --git a/gcc/tree-ssanames.cc b/gcc/tree-ssanames.cc
> index 18678e41fca..b24cdc878ca 100644
> --- a/gcc/tree-ssanames.cc
> +++ b/gcc/tree-ssanames.cc
> @@ -956,6 +956,28 @@ duplicate_ssa_name_ptr_info (tree dest, tree src)
>      duplicate_ssa_name_ptr_info (dest, pt);
>  }
>
> +
> +/* Remove any function-local points-to references from R, preserving its
> +   bounds and bitmask and any invariant target.  Return TRUE if any points to
> +   info was removed.  */

So this doesn't do anything to pt_solution?  IMO the function is misnamed
then?  Why is it not a member function of prange or somewhere in value-range.cc?

> +bool
> +clear_function_local_points_to (vrange &r)
> +{
> +  if (!is_a <prange> (r))
> +    return false;
> +  prange &pr = as_a <prange> (r);
> +  tree t = pr.pt_invariant ();
> +  if (!t)
> +    t = pr.pt_invariant_away ();
> +  if (t && !is_gimple_ip_invariant (t))
> +    {
> +      pr.set_pt_unknown ();
> +      return true;
> +    }
> +  return false;
> +}
> +
>  /* Copy any global range information from SRC to NAME.  */
>
>  void
> diff --git a/gcc/tree-ssanames.h b/gcc/tree-ssanames.h
> index 78136871027..219e11428a5 100644
> --- a/gcc/tree-ssanames.h
> +++ b/gcc/tree-ssanames.h
> @@ -71,6 +71,7 @@ extern tree duplicate_ssa_name_fn (struct function *, tree, 
> gimple *);
>  extern void duplicate_ssa_name_ptr_info (tree dest, const pt_solution *);
>  extern void duplicate_ssa_name_ptr_info (tree dest, tree src);
>  extern void duplicate_ssa_name_range_info (tree dest, tree src);
> +extern bool clear_function_local_points_to (vrange &);
>  extern void maybe_duplicate_ssa_info_at_copy (tree dest, tree src);
>  extern void reset_flow_sensitive_info (tree);
>  extern void reset_flow_sensitive_info_in_bb (basic_block);
> --
> 2.56.0
>

Reply via email to