https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128998
--- Comment #3 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Kyrylo Tkachov <[email protected]>: https://gcc.gnu.org/g:a03bb1a1500f0ac7cd6e67b1bbd2ac6e510a5e7c commit r17-6681-ga03bb1a1500f0ac7cd6e67b1bbd2ac6e510a5e7c Author: Kyrylo Tkachov <[email protected]> Date: Tue Nov 17 06:58:29 2026 -0800 aarch64: Cost vec_deconstruct as per-lane vec_to_scalar [PR128998] The vectorizer now costs the lane extraction needed by emulated gathers, strided accesses and reductions as one vec_deconstruct per vector instead of one vec_to_scalar per lane. The AArch64 hook handles vec_deconstruct like vec_construct, which charges elements / 2 + 1 for the whole vector. This is much cheaper than the previous elements * vec_to_scalar cost. The AArch64 costing code that looks for vec_to_scalar, such as the adjustment for index loads of emulated Advanced SIMD gathers, no longer matches either. As a result, for double f (double *restrict x, double *restrict y, int *restrict z) { double res = 0.0; for (int i = 0; i < 100; ++i) res += x[i] * y[z[i]]; return res; } at -Ofast -mtune=neoverse-v1 -march=armv8.2-a+sve, the Advanced SIMD loop that emulates the gather is now estimated as cheaper than the SVE loop that uses a real gather. The vectorizer picks V16QI instead of VNx2DF, which regresses gcc.target/aarch64/sve/cost_model_15.c. The same happens with -mcpu=neoverse-v2. PR128998 reports a calculix slowdown on neoverse-n1 that bisects to the vectorizer change that introduced vec_deconstruct. Convert vec_deconstruct to vec_to_scalar, scaled by the number of lanes in the vector, at the start of add_stmt_cost. This restores the per-lane costs and lets the existing vec_to_scalar handling apply. The strided SLP store path now costs every lane of the vector, which can slightly exceed the previous count when the stores use multi-lane pieces. Bootstrapped and tested on aarch64-linux-gnu. gcc/ChangeLog: PR target/128998 * config/aarch64/aarch64.cc (aarch64_vector_costs::add_stmt_cost): Treat vec_deconstruct as one vec_to_scalar per vector lane. (aarch64_vector_costs::count_ops): Make the vec_deconstruct case unreachable. Signed-off-by: Kyrylo Tkachov <[email protected]>
