On Wed, Sep 9, 2026 at 1:57 PM Aldy Hernandez <[email protected]> wrote:
>
> hoist_adjacent_loads moves the two loads from under the condition of
> the diamond into its head, but keeps the range info computed for them
> under the condition.  Clear it.
>
> A follow-up patch to range_from_readonly_load takes the range of a
> load from a constant aggregate from its index:
>
>   struct S { int a, b; };
>   static const struct S sa[4] = { { 1, 2 }, { 3, 4 }, { 5, 6 }, { 7, 8 } };
>
>   if (i < 2)
>     r = sa[i].a;      /* [1, 3] here, [1, 7] before the if */
>   else
>     r = sa[i].b;
>   if (sa[i].a > 3)    /* folds to false */
>     ...
>
> Nothing on trunk gives a load a range that depends on where it sits, so
> the wrong code cannot be exercised on its own.  The testcase comes with
> the follow-on patch that provides this functionality, which generates
> wrong code without this patch: chicken and egg :).
>
> Tested on ppc64le Linux.
>
> OK?

OK.

Thanks,
Richard.

> gcc/ChangeLog:
>
>         * tree-ssa-phiopt.cc (hoist_adjacent_loads): Clear the range
>         info of the hoisted loads.
> ---
>  gcc/tree-ssa-phiopt.cc | 4 ++++
>  1 file changed, 4 insertions(+)
>
> diff --git a/gcc/tree-ssa-phiopt.cc b/gcc/tree-ssa-phiopt.cc
> index 6e17d21b58c..7203f4d29c8 100644
> --- a/gcc/tree-ssa-phiopt.cc
> +++ b/gcc/tree-ssa-phiopt.cc
> @@ -4569,6 +4569,10 @@ hoist_adjacent_loads (basic_block bb0, basic_block bb1,
>        gsi_move_to_bb_end (&gsi2, bb0);
>        gsi2 = gsi_for_stmt (def2);
>        gsi_move_to_bb_end (&gsi2, bb0);
> +      /* Clear range info from the defs we've moved from under the
> +        condition.  */
> +      reset_flow_sensitive_info (gimple_assign_lhs (def1));
> +      reset_flow_sensitive_info (gimple_assign_lhs (def2));
>        statistics_counter_event (cfun, "hoisted loads", 1);
>
>        if (dump_file && (dump_flags & TDF_DETAILS))
> --
> 2.53.0
>

Reply via email to