> -----Original Message-----
> From: Christopher Bazley <[email protected]>
> Sent: 19 December 2025 15:09
> To: [email protected]
> Cc: [email protected]; Tamar Christina
> <[email protected]>
> Subject: [PATCH v8 06/10] Handle variable-length vector types in
> store_constructor
>
> When given a constructor of variable-length vector type, the
> store_constructor function now builds a vector with the number of
> elements specified by the constructor and uses it to emit the body
> of the kind of insn chosen by the convert_optab_handler function.
> Previously, this function used a fallback path of calling
> store_constructor_field upon discovering that the number of subparts
> in the vector type was not a constant multiple of the number of
> subparts in the element type.
>
> For example, this allows GCC to generate the following AArch64 assembly
> language output for the tail of a reduction in the slp_6 test:
>
> uaddv d31, p6, z31.b
> uaddv d27, p6, z27.b
> uaddv d26, p6, z26.b
> movi d30, #0
> insr z30.b, b26
> insr z30.b, b27
> insr z30.b, b31
> add z25.b, z25.b, z30.b
>
> instead of the following output (with predicated tails for basic block
> SLP vectorization but without this change):
>
> addvl x0, sp, #2
> movi d0, #0
> st1b z0.b, p6, [sp, #2, mul vl]
> uaddv d27, p6, z27.b
> uaddv d26, p6, z26.b
> uaddv d25, p6, z25.b
> str b27, [x0]
> addvl x0, sp, #1
> add x0, x0, 1
> ptrue p7.b, vl3
> ld1b z0.b, p6/z, [sp, #2, mul vl]
> st1b z0.b, p6, [sp, #1, mul vl]
> str b26, [x0]
> ld1b z0.b, p6/z, [sp, #1, mul vl]
> st1b z0.b, p6, [sp]
> str b25, [sp, 2]
> ld1b z0.b, p6/z, [sp]
> add z28.b, z28.b, z0.b
> st1b z28.b, p7, [x1]
> addvl sp, sp, #3
>
> or the original assembly language output (with neither predicated tails
> for basic block SLP vectorization nor this change):
>
> uaddv d31, p6, z31.b
> fmov x0, d31
> uaddv d31, p6, z26.b
> add w6, w6, w0
> fmov x0, d31
> uaddv d31, p6, z27.b
> add w5, w5, w0
> fmov x0, d31
> add w4, w4, w0
>
> gcc/ChangeLog:
>
> * expr.cc (store_constructor): Add an else block to handle
> cases of TREE_CODE (TREE_TYPE (exp)) == VECTOR_TYPE in which
> exact_div (n_elts, GET_MODE_NUNITS (eltmode)).is_constant
> (&const_n_elts) is false similar to the existing "element type
> is not a vector type" case except that const_n_elts is taken
> from the constructor instead of the subparts of the vector
> type.
>
This is a good change to have in general. It helps the C++ VLA support code.
Can't approve it but LGTM.
Thanks,
Tamar
> ---
> gcc/expr.cc | 7 ++++++-
> 1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/gcc/expr.cc b/gcc/expr.cc
> index 7d84ad9e6fc..622c5be1d59 100644
> --- a/gcc/expr.cc
> +++ b/gcc/expr.cc
> @@ -8058,7 +8058,12 @@ store_constructor (tree exp, rtx target, int
> cleared, poly_int64 size,
> similarly non-const type vectors. */
> icode = convert_optab_handler (vec_init_optab, mode,
> eltmode);
> }
> -
> + else
> + {
> + /* Handle variable-length vector types. */
> + icode = convert_optab_handler (vec_init_optab, mode,
> eltmode);
> + const_n_elts = CONSTRUCTOR_NELTS (exp);
> + }
> if (const_n_elts && icode != CODE_FOR_nothing)
> {
> vector = rtvec_alloc (const_n_elts);
> --
> 2.43.0