On Tue, Nov 10, 2026 at 8:14 PM Andrea Pinski <[email protected]> wrote: > > On Tue, Nov 10, 2026 at 6:44 PM Andrea Pinski > <[email protected]> wrote: > > > > On Tue, Nov 10, 2026 at 6:45 AM <[email protected]> wrote: > > > > > > From: Kyrylo Tkachov <[email protected]> > > > > > > TARGET_FNTYPE_ABI is called very often from RTL passes (fndecl_abi and > > > insn_callee_abi, via reg_set_p, IRA, df, rtl-ssa, cselib and others), > > > but there are few distinct function types. aarch64_fntype_abi re-runs > > > aarch64_returns_value_in_sve_regs_p and > > > aarch64_takes_arguments_in_sve_regs_p on every call. These analyse the > > > return type and every argument type with pure_scalable_type_info. In a > > > perf profile of compiling fmt at -O3, aarch64_fntype_abi accounts for > > > about 2.5% of cc1plus instructions. > > > > > > Add aarch64_fntype_uses_sve_regs_p, which caches the combined result per > > > function type in a GC cache map. The cache is only used once the current > > > function has been expanded to RTL, when all types are complete and the > > > answer for a given type cannot change. Earlier callers (for example the > > > front ends and gimple passes) still recompute. With checking enabled a > > > cache hit is verified against a recomputation. > > > > > > 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). > > > > > > user-space instructions drop -2.2% in total, with printf-test.cc -2.7% and > > > format-test.cc -2.2%. > > > The new test checks that calls to an SVE ABI function are compiled the > > > same > > > way from functions with different target options. > > > > I suspect the real issue is how aarch64_takes_arguments_in_sve_regs_p is > > done. > > There must be a better way than what it is currently doing of > > aarch64_init_cumulative_args/apply_pass_by_reference_rules. > > Especially since aarch64_pass_by_reference calls pst_info.analyze > > which is done again in aarch64_takes_arguments_in_sve_regs_p too. > > Can you speed up aarch64_takes_arguments_in_sve_regs_p first? Because > > I suspect once you do that, it should be ok. > > Also if I am reading the code, it should return false if !TARGET_SVE > > so at least for non sve targets there is a simple speed up right > > there. > > The other thing; is there a way to your cache as part of the function > type rather than a side map?
A few spare bits for function type: needs_constructing_flag string_flag Seems like those 2 bits could be used to cache things here. say string_flag is if the value is cached and needs_constructing_flag is the value of the cache. Thanks, Andrea > > Thanks, > Andrea > > > > > > > > > > Bootstrapped and tested on aarch64-none-linux-gnu. > > > Ok for trunk? > > > Thanks, > > > Kyrill > > > > > > gcc/ChangeLog: > > > > > > * config/aarch64/aarch64.cc > > > (aarch64_fntype_uses_sve_regs_uncached_p): > > > New function. > > > (aarch64_sve_regs_cache): New variable. > > > (aarch64_fntype_uses_sve_regs_p): New function. > > > (aarch64_fntype_abi): Use it. > > > > > > gcc/testsuite/ChangeLog: > > > > > > * gcc.target/aarch64/sve/pcs/fntype_abi_target_1.c: New test. > > > > > > Signed-off-by: Kyrylo Tkachov <[email protected]> > > > --- > > > gcc/config/aarch64/aarch64.cc | 48 +++++++++++++- > > > .../aarch64/sve/pcs/fntype_abi_target_1.c | 63 +++++++++++++++++++ > > > 2 files changed, 109 insertions(+), 2 deletions(-) > > > create mode 100644 > > > gcc/testsuite/gcc.target/aarch64/sve/pcs/fntype_abi_target_1.c > > > > > > diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc > > > index 730a1fee835..4aae97a8c3c 100644 > > > --- a/gcc/config/aarch64/aarch64.cc > > > +++ b/gcc/config/aarch64/aarch64.cc > > > @@ -2657,6 +2657,51 @@ aarch64_ms_variadic_abi (void) > > > return ms_variadic_abi; > > > } > > > > > > +/* Return true if a function with type FNTYPE passes or returns a value > > > + in SVE vector or predicate registers. */ > > > + > > > +static bool > > > +aarch64_fntype_uses_sve_regs_uncached_p (const_tree fntype) > > > +{ > > > + return (aarch64_returns_value_in_sve_regs_p (fntype) > > > + || aarch64_takes_arguments_in_sve_regs_p (fntype)); > > > +} > > > + > > > +/* Cache for aarch64_fntype_uses_sve_regs_p, mapping function types to > > > + boolean_true_node or boolean_false_node. */ > > > +static GTY((cache)) type_tree_cache_map *aarch64_sve_regs_cache; > > > + > > > +/* Return true if a function with type FNTYPE passes or returns a value > > > + in SVE vector or predicate registers. Cache the answer per function > > > + type, but only once the current function has been expanded to RTL. > > > + Before that, types can still be incomplete or be modified in place, > > > + for example when a C++ deduced return type is resolved. Outside of > > > + any function (!cfun) the answer is also not cached. */ > > > + > > > +static bool > > > +aarch64_fntype_uses_sve_regs_p (const_tree fntype) > > > +{ > > > + if (!cfun || !(cfun->curr_properties & PROP_rtl)) > > > + return aarch64_fntype_uses_sve_regs_uncached_p (fntype); > > > + > > > + if (!aarch64_sve_regs_cache) > > > + aarch64_sve_regs_cache = type_tree_cache_map::create_ggc (64); > > > + > > > + tree type = const_cast<tree> (fntype); > > > + if (tree *entry = aarch64_sve_regs_cache->get (type)) > > > + { > > > + bool res = *entry == boolean_true_node; > > > + gcc_checking_assert (res > > > + == aarch64_fntype_uses_sve_regs_uncached_p > > > (fntype)); > > > + return res; > > > + } > > > + > > > + bool res = aarch64_fntype_uses_sve_regs_uncached_p (fntype); > > > + aarch64_sve_regs_cache->put (type, res ? boolean_true_node > > > + : boolean_false_node); > > > + return res; > > > +} > > > + > > > /* Implement TARGET_FNTYPE_ABI. */ > > > > > > static const predefined_function_abi & > > > @@ -2673,8 +2718,7 @@ aarch64_fntype_abi (const_tree fntype) > > > && !stdarg_p (fntype)) > > > return aarch64_preserve_none_abi (); > > > > > > - if (aarch64_returns_value_in_sve_regs_p (fntype) > > > - || aarch64_takes_arguments_in_sve_regs_p (fntype)) > > > + if (aarch64_fntype_uses_sve_regs_p (fntype)) > > > return aarch64_sve_abi (); > > > > > > return default_function_abi; > > > diff --git > > > a/gcc/testsuite/gcc.target/aarch64/sve/pcs/fntype_abi_target_1.c > > > b/gcc/testsuite/gcc.target/aarch64/sve/pcs/fntype_abi_target_1.c > > > new file mode 100644 > > > index 00000000000..adf1faba3e0 > > > --- /dev/null > > > +++ b/gcc/testsuite/gcc.target/aarch64/sve/pcs/fntype_abi_target_1.c > > > @@ -0,0 +1,63 @@ > > > +/* { dg-do compile } */ > > > +/* { dg-options "-O2 -march=armv8.2-a" } */ > > > + > > > +/* Check that calls to a function with an SVE register ABI are compiled > > > + in the same way, whether SVE is enabled by a pragma or by an attribute > > > + and whatever other extensions are enabled with it. The ABI of a > > > + function type does not depend on the target options. > > > + Under the SVE ABI, p4-p15 are preserved by calls, so the predicates > > > + that live across the calls below are held in them and are never > > > + spilled. */ > > > + > > > +#include <arm_sve.h> > > > + > > > +svbool_t sve_callee (svbool_t); > > > +svbool_t (*sve_fn) (svbool_t); > > > + > > > +#pragma GCC push_options > > > +#pragma GCC target "+sve" > > > +svbool_t > > > +pragma_sve (svbool_t p) > > > +{ > > > + svbool_t q = sve_callee (p); > > > + return svand_z (p, q, sve_callee (q)); > > > +} > > > +#pragma GCC pop_options > > > + > > > +#pragma GCC push_options > > > +#pragma GCC target "+sve2" > > > +svbool_t > > > +pragma_sve2 (svbool_t p) > > > +{ > > > + svbool_t q = sve_callee (p); > > > + return svand_z (p, q, sve_callee (q)); > > > +} > > > +#pragma GCC pop_options > > > + > > > +__attribute__((target ("+sve"))) > > > +svbool_t > > > +attribute_sve (svbool_t p) > > > +{ > > > + svbool_t q = sve_callee (p); > > > + return svand_z (p, q, sve_callee (q)); > > > +} > > > + > > > +__attribute__((target ("+sve2"))) > > > +svbool_t > > > +attribute_sve2 (svbool_t p) > > > +{ > > > + svbool_t q = sve_callee (p); > > > + return svand_z (p, q, sve_callee (q)); > > > +} > > > + > > > +__attribute__((target ("+sve2"))) > > > +svbool_t > > > +indirect_sve2 (svbool_t p) > > > +{ > > > + svbool_t q = sve_fn (p); > > > + return svand_z (p, q, sve_fn (q)); > > > +} > > > + > > > +/* { dg-final { scan-assembler {\t\.variant_pcs\tsve_callee\n} } } */ > > > +/* { dg-final { scan-assembler-times {\tmov\tp(?:[4-9]|1[0-5])\.b, > > > p0\.b\n} 10 } } */ > > > +/* { dg-final { scan-assembler-not {\tstr\tp[0-3],} } } */ > > > -- > > > 2.54.0 (Apple Git-157) > > >
