https://gcc.gnu.org/g:fada0de3559a530fa643a5de5fcee4f328699c0a
commit r17-6174-gfada0de3559a530fa643a5de5fcee4f328699c0a Author: Kyrylo Tkachov <[email protected]> Date: Tue Nov 3 02:52:05 2026 -0800 tree: Avoid building a zero tree for poly_int coefficients 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. 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]> Diff: --- gcc/tree.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/gcc/tree.h b/gcc/tree.h index c90b1bfe445a..4bdf87637949 100644 --- a/gcc/tree.h +++ b/gcc/tree.h @@ -7106,20 +7106,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>
