[PATCH v3 11/16] aarch64: Add read_ffr_cost item to cost model
Tamar Christina
Tamar.Christina@arm.com
Wed Oct 7 06:57:26 GMT 2026
> -----Original Message-----
> From: Alfie Richards <alfie.richards@arm.com>
> Sent: 17 September 2026 15:40
> To: gcc-patches@gcc.gnu.org
> Cc: Alex Coplan <Alex.Coplan@arm.com>; Alice Carlotti
> <Alice.Carlotti@arm.com>; Andrea Pinski
> <andrew.pinski@oss.qualcomm.com>; Richard Biener <rguenther@suse.de>;
> Tamar Christina <Tamar.Christina@arm.com>; Zdenek Dvorak <ook@ucw.cz>;
> Robin Dapp <rdapp.gcc@gmail.com>; Richard Sandiford
> <rdsandiford@googlemail.com>; Kyrylo Tkachov <ktkachov@nvidia.com>;
> Alfie Richards <Alfie.Richards@arm.com>
> Subject: [PATCH v3 11/16] aarch64: Add read_ffr_cost item to cost model
>
> Represents the cost of a rdffr.
>
> gcc/ChangeLog:
>
> * config/aarch64/aarch64-protos.h (struct sve_vec_cost): Add
> read_ffr_cost member.
> * config/aarch64/aarch64.cc (aarch64_builtin_vectorization_cost):
> Add handling for hssr_read using read_ffr_cost.
> (aarch64_vector_costs::count_ops):
> Add handling for hssr_read.
> * config/aarch64/tuning_models/a64fx.h: Add entry for
> read_ffr_cost.
> * config/aarch64/tuning_models/cortexa320.h: Likewise.
> * config/aarch64/tuning_models/cortexx925.h: Likewise.
> * config/aarch64/tuning_models/generic.h: Likewise.
> * config/aarch64/tuning_models/generic_armv8_a.h: Likewise.
> * config/aarch64/tuning_models/generic_armv9_a.h: Likewise.
> * config/aarch64/tuning_models/hip12.h: Likewise.
> * config/aarch64/tuning_models/neoverse512tvb.h: Likewise.
> * config/aarch64/tuning_models/neoversen2.h: Likewise.
> * config/aarch64/tuning_models/neoversen3.h: Likewise.
> * config/aarch64/tuning_models/neoversev1.h: Likewise.
> * config/aarch64/tuning_models/neoversev2.h: Likewise.
> * config/aarch64/tuning_models/neoversev3.h: Likewise.
> * config/aarch64/tuning_models/neoversev3ae.h: Likewise.
> * config/aarch64/tuning_models/olympus.h: Likewise.
> ---
> gcc/config/aarch64/aarch64-protos.h | 10 ++++++++--
> gcc/config/aarch64/aarch64.cc | 12 ++++++++++++
> gcc/config/aarch64/tuning_models/a64fx.h | 3 ++-
> gcc/config/aarch64/tuning_models/cortexa320.h | 3 ++-
> gcc/config/aarch64/tuning_models/cortexx925.h | 3 ++-
> gcc/config/aarch64/tuning_models/generic.h | 3 ++-
> gcc/config/aarch64/tuning_models/generic_armv8_a.h | 3 ++-
> gcc/config/aarch64/tuning_models/generic_armv9_a.h | 3 ++-
> gcc/config/aarch64/tuning_models/hip12.h | 3 ++-
> gcc/config/aarch64/tuning_models/neoverse512tvb.h | 3 ++-
> gcc/config/aarch64/tuning_models/neoversen2.h | 3 ++-
> gcc/config/aarch64/tuning_models/neoversen3.h | 3 ++-
> gcc/config/aarch64/tuning_models/neoversev1.h | 3 ++-
> gcc/config/aarch64/tuning_models/neoversev2.h | 3 ++-
> gcc/config/aarch64/tuning_models/neoversev3.h | 3 ++-
> gcc/config/aarch64/tuning_models/neoversev3ae.h | 3 ++-
> gcc/config/aarch64/tuning_models/olympus.h | 3 ++-
> 17 files changed, 50 insertions(+), 17 deletions(-)
>
> diff --git a/gcc/config/aarch64/aarch64-protos.h
> b/gcc/config/aarch64/aarch64-protos.h
> index 22fd1c68b05..c21611f97f7 100644
> --- a/gcc/config/aarch64/aarch64-protos.h
> +++ b/gcc/config/aarch64/aarch64-protos.h
> @@ -266,7 +266,9 @@ struct sve_vec_cost : simd_vec_cost
> unsigned int gather_load_x64_cost,
> unsigned int gather_load_x32_init_cost,
> unsigned int gather_load_x64_init_cost,
> - unsigned int scatter_store_elt_cost)
> + unsigned int scatter_store_elt_cost,
> + unsigned int read_ffr_cost
> + )
> : simd_vec_cost (base),
> clast_cost (clast_cost),
> fadda_f16_cost (fadda_f16_cost),
> @@ -276,7 +278,8 @@ struct sve_vec_cost : simd_vec_cost
> gather_load_x64_cost (gather_load_x64_cost),
> gather_load_x32_init_cost (gather_load_x32_init_cost),
> gather_load_x64_init_cost (gather_load_x64_init_cost),
> - scatter_store_elt_cost (scatter_store_elt_cost)
> + scatter_store_elt_cost (scatter_store_elt_cost),
> + read_ffr_cost (read_ffr_cost)
> {}
>
> /* The cost of a vector-to-scalar CLASTA or CLASTB instruction,
> @@ -303,6 +306,9 @@ struct sve_vec_cost : simd_vec_cost
>
> /* The per-element cost of a scatter store. */
> int scatter_store_elt_cost;
> +
> + /* Cost of an rdffrs. */
> + int read_ffr_cost;
> };
>
> /* Base information about how the CPU issues code, containing
> diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc
> index d8bd0cc74f1..00df040c8dc 100644
> --- a/gcc/config/aarch64/aarch64.cc
> +++ b/gcc/config/aarch64/aarch64.cc
> @@ -18007,6 +18007,17 @@ aarch64_builtin_vectorization_cost (enum
> vect_cost_for_stmt type_of_cost,
> elements = estimated_poly_value (TYPE_VECTOR_SUBPARTS
> (vectype));
> return elements / 2 + 1;
>
> + case hssr_read:
> + {
> + const sve_vec_cost *sve_costs = aarch64_tune_params.vec_costs-
> >sve;
> + /* We need SVE to have HSSR so we surely will have sve costs defined
> + too. */
But that's already simd_costs then :) aarch64_simd_vec_costs picks the cost
model based on the vectype and I assume you're costing hssr_read with a vectype?
You also didn't update the serializer and de-serializer. The json costing code will
Likely crash here. See aarch64-json-schema.h. edit that and call make which should
regenerate the .inc files.
Thanks,
Tamar
> + gcc_assert (sve_costs);
> +
> + /* This will be a rdffr + b.nlast. */
> + return sve_costs->read_ffr_cost + costs-
> >cond_not_taken_branch_cost;
> + }
> +
> default:
> gcc_unreachable ();
> }
> @@ -18636,6 +18647,7 @@ aarch64_vector_costs::count_ops (unsigned int
> count, vect_cost_for_stmt kind,
> case scalar_to_vec:
> case vector_stmt:
> case scalar_stmt:
> + case hssr_read:
> ops->general_ops += count;
> break;
>
> diff --git a/gcc/config/aarch64/tuning_models/a64fx.h
> b/gcc/config/aarch64/tuning_models/a64fx.h
> index c3222960f17..d457e8e29a8 100644
> --- a/gcc/config/aarch64/tuning_models/a64fx.h
> +++ b/gcc/config/aarch64/tuning_models/a64fx.h
> @@ -106,7 +106,8 @@ static const sve_vec_cost a64fx_sve_vector_cost =
> 32, /* gather_load_x64_cost */
> 0, /* gather_load_x32_init_cost */
> 0, /* gather_load_x64_init_cost */
> - 1 /* scatter_store_elt_cost */
> + 1, /* scatter_store_elt_cost */
> + 5 /* read_ffr_cost */
> };
>
> static const struct cpu_vector_cost a64fx_vector_cost =
> diff --git a/gcc/config/aarch64/tuning_models/cortexa320.h
> b/gcc/config/aarch64/tuning_models/cortexa320.h
> index d5e1f2b2993..749d2afd879 100644
> --- a/gcc/config/aarch64/tuning_models/cortexa320.h
> +++ b/gcc/config/aarch64/tuning_models/cortexa320.h
> @@ -137,7 +137,8 @@ static const sve_vec_cost
> cortexa320_sve_vector_cost =
> 19, /* gather_load_x64_cost */
> 48, /* gather_load_x32_init_cost */
> 38, /* gather_load_x64_init_cost */
> - 0 /* scatter_store_elt_cost */
> + 0, /* scatter_store_elt_cost */
> + 5 /* read_ffr_cost */
> };
>
> /* Cortexa320 costs for vector insn classes. */
> diff --git a/gcc/config/aarch64/tuning_models/cortexx925.h
> b/gcc/config/aarch64/tuning_models/cortexx925.h
> index 2a73b369706..46e2f653812 100644
> --- a/gcc/config/aarch64/tuning_models/cortexx925.h
> +++ b/gcc/config/aarch64/tuning_models/cortexx925.h
> @@ -119,7 +119,8 @@ static const sve_vec_cost
> cortexx925_sve_vector_cost =
> 12, /* gather_load_x64_cost */
> 42, /* gather_load_x32_init_cost */
> 24, /* gather_load_x64_init_cost */
> - 1 /* scatter_store_elt_cost */
> + 1, /* scatter_store_elt_cost */
> + 5 /* read_ffr_cost */
> };
>
> static const aarch64_scalar_vec_issue_info cortexx925_scalar_issue_info =
> diff --git a/gcc/config/aarch64/tuning_models/generic.h
> b/gcc/config/aarch64/tuning_models/generic.h
> index af013e478d4..e163b60f405 100644
> --- a/gcc/config/aarch64/tuning_models/generic.h
> +++ b/gcc/config/aarch64/tuning_models/generic.h
> @@ -107,7 +107,8 @@ static const sve_vec_cost generic_sve_vector_cost =
> 2, /* gather_load_x64_cost */
> 0, /* gather_load_x32_init_cost */
> 0, /* gather_load_x64_init_cost */
> - 1 /* scatter_store_elt_cost */
> + 1, /* scatter_store_elt_cost */
> + 5 /* read_ffr_cost */
> };
>
> /* Generic costs for vector insn classes. */
> diff --git a/gcc/config/aarch64/tuning_models/generic_armv8_a.h
> b/gcc/config/aarch64/tuning_models/generic_armv8_a.h
> index 29cf3a5a7c7..4de03a3770e 100644
> --- a/gcc/config/aarch64/tuning_models/generic_armv8_a.h
> +++ b/gcc/config/aarch64/tuning_models/generic_armv8_a.h
> @@ -108,7 +108,8 @@ static const sve_vec_cost
> generic_armv8_a_sve_vector_cost =
> 2, /* gather_load_x64_cost */
> 12, /* gather_load_x32_init_cost */
> 4, /* gather_load_x64_init_cost */
> - 1 /* scatter_store_elt_cost */
> + 1, /* scatter_store_elt_cost */
> + 5 /* read_ffr_cost */
> };
>
> /* Generic costs for vector insn classes. */
> diff --git a/gcc/config/aarch64/tuning_models/generic_armv9_a.h
> b/gcc/config/aarch64/tuning_models/generic_armv9_a.h
> index 05e777d20ef..d0131c168d9 100644
> --- a/gcc/config/aarch64/tuning_models/generic_armv9_a.h
> +++ b/gcc/config/aarch64/tuning_models/generic_armv9_a.h
> @@ -138,7 +138,8 @@ static const sve_vec_cost
> generic_armv9_a_sve_vector_cost =
> 12, /* gather_load_x64_cost */
> 42, /* gather_load_x32_init_cost */
> 24, /* gather_load_x64_init_cost */
> - 3 /* scatter_store_elt_cost */
> + 3, /* scatter_store_elt_cost */
> + 5 /* read_ffr_cost */
> };
>
> static const aarch64_scalar_vec_issue_info
> generic_armv9_a_scalar_issue_info =
> diff --git a/gcc/config/aarch64/tuning_models/hip12.h
> b/gcc/config/aarch64/tuning_models/hip12.h
> index cfb204b2e53..64e08de3da0 100644
> --- a/gcc/config/aarch64/tuning_models/hip12.h
> +++ b/gcc/config/aarch64/tuning_models/hip12.h
> @@ -117,7 +117,8 @@ static const sve_vec_cost hip12_sve_vector_cost =
> 16, /* gather_load_x64_cost */
> 96, /* gather_load_x32_init_cost */
> 32, /* gather_load_x64_init_cost */
> - 3 /* scatter_store_elt_cost */
> + 3, /* scatter_store_elt_cost */
> + 5 /* read_ffr_cost */
> };
>
> static const aarch64_scalar_vec_issue_info hip12_scalar_issue_info =
> diff --git a/gcc/config/aarch64/tuning_models/neoverse512tvb.h
> b/gcc/config/aarch64/tuning_models/neoverse512tvb.h
> index d6e2c2e8120..910eb0d52cf 100644
> --- a/gcc/config/aarch64/tuning_models/neoverse512tvb.h
> +++ b/gcc/config/aarch64/tuning_models/neoverse512tvb.h
> @@ -81,7 +81,8 @@ static const sve_vec_cost
> neoverse512tvb_sve_vector_cost =
> 12, /* gather_load_x64_cost */
> 42, /* gather_load_x32_init_cost */
> 24, /* gather_load_x64_init_cost */
> - 3 /* scatter_store_elt_cost */
> + 3, /* scatter_store_elt_cost */
> + 5 /* read_ffr_cost */
> };
>
> static const aarch64_sve_vec_issue_info neoverse512tvb_sve_issue_info =
> diff --git a/gcc/config/aarch64/tuning_models/neoversen2.h
> b/gcc/config/aarch64/tuning_models/neoversen2.h
> index 21597e6b50f..abbdc98e068 100644
> --- a/gcc/config/aarch64/tuning_models/neoversen2.h
> +++ b/gcc/config/aarch64/tuning_models/neoversen2.h
> @@ -119,7 +119,8 @@ static const sve_vec_cost
> neoversen2_sve_vector_cost =
> 12, /* gather_load_x64_cost */
> 42, /* gather_load_x32_init_cost */
> 24, /* gather_load_x64_init_cost */
> - 3 /* scatter_store_elt_cost */
> + 3, /* scatter_store_elt_cost */
> + 5 /* read_ffr_cost */
> };
>
> static const aarch64_scalar_vec_issue_info neoversen2_scalar_issue_info =
> diff --git a/gcc/config/aarch64/tuning_models/neoversen3.h
> b/gcc/config/aarch64/tuning_models/neoversen3.h
> index 37f9819148f..e17af8c259e 100644
> --- a/gcc/config/aarch64/tuning_models/neoversen3.h
> +++ b/gcc/config/aarch64/tuning_models/neoversen3.h
> @@ -119,7 +119,8 @@ static const sve_vec_cost
> neoversen3_sve_vector_cost =
> 12, /* gather_load_x64_cost */
> 42, /* gather_load_x32_init_cost */
> 24, /* gather_load_x64_init_cost */
> - 1 /* scatter_store_elt_cost */
> + 1, /* scatter_store_elt_cost */
> + 5 /* read_ffr_cost */
> };
>
> static const aarch64_scalar_vec_issue_info neoversen3_scalar_issue_info =
> diff --git a/gcc/config/aarch64/tuning_models/neoversev1.h
> b/gcc/config/aarch64/tuning_models/neoversev1.h
> index 004676a8dba..68a82e42dc2 100644
> --- a/gcc/config/aarch64/tuning_models/neoversev1.h
> +++ b/gcc/config/aarch64/tuning_models/neoversev1.h
> @@ -128,7 +128,8 @@ static const sve_vec_cost
> neoversev1_sve_vector_cost =
> 16, /* gather_load_x64_cost */
> 96, /* gather_load_x32_init_cost */
> 32, /* gather_load_x64_init_cost */
> - 3 /* scatter_store_elt_cost */
> + 3, /* scatter_store_elt_cost */
> + 5 /* read_ffr_cost */
> };
>
> static const aarch64_scalar_vec_issue_info neoversev1_scalar_issue_info =
> diff --git a/gcc/config/aarch64/tuning_models/neoversev2.h
> b/gcc/config/aarch64/tuning_models/neoversev2.h
> index 73408977251..da20d3724cf 100644
> --- a/gcc/config/aarch64/tuning_models/neoversev2.h
> +++ b/gcc/config/aarch64/tuning_models/neoversev2.h
> @@ -121,7 +121,8 @@ static const sve_vec_cost
> neoversev2_sve_vector_cost =
> 12, /* gather_load_x64_cost */
> 42, /* gather_load_x32_init_cost */
> 24, /* gather_load_x64_init_cost */
> - 3 /* scatter_store_elt_cost */
> + 3, /* scatter_store_elt_cost */
> + 5 /* read_ffr_cost */
> };
>
> static const aarch64_scalar_vec_issue_info neoversev2_scalar_issue_info =
> diff --git a/gcc/config/aarch64/tuning_models/neoversev3.h
> b/gcc/config/aarch64/tuning_models/neoversev3.h
> index 7e0144032dc..a6a25a3425a 100644
> --- a/gcc/config/aarch64/tuning_models/neoversev3.h
> +++ b/gcc/config/aarch64/tuning_models/neoversev3.h
> @@ -119,7 +119,8 @@ static const sve_vec_cost
> neoversev3_sve_vector_cost =
> 12, /* gather_load_x64_cost */
> 42, /* gather_load_x32_init_cost */
> 24, /* gather_load_x64_init_cost */
> - 1 /* scatter_store_elt_cost */
> + 1, /* scatter_store_elt_cost */
> + 5 /* read_ffr_cost */
> };
>
> static const aarch64_scalar_vec_issue_info neoversev3_scalar_issue_info =
> diff --git a/gcc/config/aarch64/tuning_models/neoversev3ae.h
> b/gcc/config/aarch64/tuning_models/neoversev3ae.h
> index bbe4dc54701..86484268985 100644
> --- a/gcc/config/aarch64/tuning_models/neoversev3ae.h
> +++ b/gcc/config/aarch64/tuning_models/neoversev3ae.h
> @@ -119,7 +119,8 @@ static const sve_vec_cost
> neoversev3ae_sve_vector_cost =
> 12, /* gather_load_x64_cost */
> 42, /* gather_load_x32_init_cost */
> 24, /* gather_load_x64_init_cost */
> - 1 /* scatter_store_elt_cost */
> + 1, /* scatter_store_elt_cost */
> + 5 /* read_ffr_cost */
> };
>
> static const aarch64_scalar_vec_issue_info neoversev3ae_scalar_issue_info =
> diff --git a/gcc/config/aarch64/tuning_models/olympus.h
> b/gcc/config/aarch64/tuning_models/olympus.h
> index 1e701722e22..41bd70f0147 100644
> --- a/gcc/config/aarch64/tuning_models/olympus.h
> +++ b/gcc/config/aarch64/tuning_models/olympus.h
> @@ -90,7 +90,8 @@ static sve_vec_cost olympus_sve_vector_cost =
> 12, /* gather_load_x64_cost */
> 42, /* gather_load_x32_init_cost */
> 24, /* gather_load_x64_init_cost */
> - 1 /* scatter_store_elt_cost */
> + 1, /* scatter_store_elt_cost */
> + 5 /* read_ffr_cost */
> };
>
> static aarch64_scalar_vec_issue_info olympus_scalar_issue_info =
> --
> 2.43.0
More information about the Gcc-patches
mailing list