On Tue, Aug 18, 2026 at 12:30 PM Aldy Hernandez <[email protected]> wrote:
>
> Since r17-3298 the path ranger can become the current query while
> fold_using_range folds a statement, so match.pd simplifications can
> query with a context statement that can be from an arbitrary block on
> the path.  The solver's positional machinery is only meaningful at the
> block the walk is currently at.
>
> Only compute ranges at the current path position otherwise fall back
> to the global range.  Assert the positional invariant in
> range_defined_in_block, which I verified holds by testing the assert
> on a tree before r17-3298.
>
> Tested on ppc64le Linux.
>
> Pushed.
>
>         PR tree-optimization/126876
>
> gcc/ChangeLog:
>
>         * gimple-range-path.cc
>         (path_range_query::internal_range_of_expr): Only call
>         range_defined_in_block at the current path position.
>         (path_range_query::range_defined_in_block): Assert the current
>         path position.
> ---
>  gcc/gimple-range-path.cc | 10 ++++++++++
>  1 file changed, 10 insertions(+)
>
> diff --git a/gcc/gimple-range-path.cc b/gcc/gimple-range-path.cc
> index 467e321b8de..54c8a04b486 100644
> --- a/gcc/gimple-range-path.cc
> +++ b/gcc/gimple-range-path.cc
> @@ -156,7 +156,12 @@ path_range_query::internal_range_of_expr (vrange &r, 
> tree name, gimple *stmt)
>        return true;
>      }
>
> +  // We can be called from match.pd or elsewhere, with a context statement
> +  // that can be anywhere on the path.  Since we can only compute ranges
> +  // mid flight at the current path position, check that's the case,
> +  // otherwise fall through to the global range.
>    if (stmt
> +      && gimple_bb (stmt) == curr_bb ()

Are there not in-BB side-effects to ranges that might or might not be reflected?

I'm not sure it's sensible to use path ranger as current query.

>        && range_defined_in_block (r, name, gimple_bb (stmt)))
>      {
>        if (TREE_CODE (name) == SSA_NAME)
> @@ -290,6 +295,11 @@ path_range_query::ssa_range_in_phi (vrange &r, gphi *phi)
>  bool
>  path_range_query::range_defined_in_block (vrange &r, tree name, basic_block 
> bb)
>  {
> +  // Ranges can only be calculated at the current path position, both
> +  // while pre-computing the cache and when answering questions at the
> +  // path exit afterwards.
> +  gcc_assert (bb == curr_bb ());
> +
>    gimple *def_stmt = SSA_NAME_DEF_STMT (name);
>    basic_block def_bb = gimple_bb (def_stmt);
>
> --
> 2.47.3
>

Reply via email to