On Tue, Nov 10, 2026 at 3:52 PM <[email protected]> wrote:
>
> From: Kyrylo Tkachov <[email protected]>
>
> On targets with NUM_POLY_INT_COEFFS > 1 (AArch64, RISC-V), converting an
> INTEGER_CST to a poly_offset_int or poly_widest_int, as wi::to_poly_offset
> and wi::to_poly_widest do, fills the trailing coefficients using
> wi::ints_for<...>::zero.  For the tree-backed extended_tree types this
> called build_zero_cst, which looks up the INTEGER_CST cache on every
> conversion.
>
> These conversions are frequent.  For example get_ref_base_and_extent
> does them for every COMPONENT_REF, ARRAY_REF and MEM_REF it decomposes,
> so the alias oracle pays for it on each statement visited by the alias
> walkers.  In an AArch64 -O3 profile of a C++ file, wide_int_to_tree was
> about 1% of the compiler's instructions as self cost, mostly reached
> from get_ref_base_and_extent via refs_may_alias_p_2.
>
> extended_tree has a fixed precision independent of the type of the tree,
> so any zero INTEGER_CST represents the coefficient.  Return
> integer_zero_node instead.  The unextended_tree variant takes its
> precision from the type and is unchanged.
>
> The test input is the C++ test suite of fmtlib/fmt
> (https://github.com/fmtlib/fmt),
> built with CMake in Release mode (-O3 -DNDEBUG -std=gnu++11).
>
> instructions drop printf-test.cc -2.8%, format-test.cc
> -1.5%, all 8 translation units combined -1.9%.
>
> Bootstrapped and tested on aarch64-none-linux-gnu.
> Ok for trunk?

LGTM.

> Thanks,
> Kyrill
>
> gcc/ChangeLog:
>
>         * tree.h (wi::ints_for<generic_wide_int<extended_tree<N>>,
>         INL_CONST_PRECISION>::zero): Return integer_zero_node.
>         (wi::ints_for<generic_wide_int<extended_tree<N>>,
>         CONST_PRECISION>::zero): Likewise.
>
> Signed-off-by: Kyrylo Tkachov <[email protected]>
> ---
>  gcc/tree.h | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/gcc/tree.h b/gcc/tree.h
> index 73c7d25a22c..98574fffa32 100644
> --- a/gcc/tree.h
> +++ b/gcc/tree.h
> @@ -6875,20 +6875,22 @@ wi::to_poly_wide (const_tree t)
>    return t;
>  }
>
> +/* The precision of extended_tree does not depend on the type of the tree,
> +   so any zero INTEGER_CST is a valid zero.  */
>  template <int N>
>  inline generic_wide_int <wi::extended_tree <N> >
>  wi::ints_for <generic_wide_int <wi::extended_tree <N> >,
> -             wi::INL_CONST_PRECISION>::zero (const extended &x)
> +             wi::INL_CONST_PRECISION>::zero (const extended &)
>  {
> -  return build_zero_cst (TREE_TYPE (x.get_tree ()));
> +  return integer_zero_node;
>  }
>
>  template <int N>
>  inline generic_wide_int <wi::extended_tree <N> >
>  wi::ints_for <generic_wide_int <wi::extended_tree <N> >,
> -             wi::CONST_PRECISION>::zero (const extended &x)
> +             wi::CONST_PRECISION>::zero (const extended &)
>  {
> -  return build_zero_cst (TREE_TYPE (x.get_tree ()));
> +  return integer_zero_node;
>  }
>
>  inline generic_wide_int <wi::unextended_tree>
> --
> 2.54.0 (Apple Git-157)
>

Reply via email to