On Tue, Jul 15, 2025 at 12:18 PM Andrew Pinski <quic_apin...@quicinc.com> wrote:
>
> The switch conversion code asks initializer_constant_valid_p
> if the expression is a valid initializer constant and for
> vector types which have a non-constant elements initializer_constant_valid_p
> would return it is valid.  But it should be rejected as not being
> valid for an initializer.
>
> Build and tested for aarch64-linux-gnu.

Whoops I didn't see a regression until now. This actually regresses PR
116595. So I have to hold back on this for now.
I will debug and figure out how to solve both at the same time.
initializer_constant_valid_p should be rejecting it but at the same
time something else needs to change in the front-end I think.

Thanks,
Andrew Pinski

>
>         PR tree-optimization/121091
>
> gcc/ChangeLog:
>
>         * varasm.cc (initializer_constant_valid_p_1): Reject vector types 
> which
>         have a non-constant number of elements.
>
> gcc/testsuite/ChangeLog:
>
>         * gcc.target/aarch64/sve/pr121091-1.c: New test.
>
> Signed-off-by: Andrew Pinski <quic_apin...@quicinc.com>
> ---
>  .../gcc.target/aarch64/sve/pr121091-1.c       | 25 +++++++++++++++++++
>  gcc/varasm.cc                                 |  5 ++++
>  2 files changed, 30 insertions(+)
>  create mode 100644 gcc/testsuite/gcc.target/aarch64/sve/pr121091-1.c
>
> diff --git a/gcc/testsuite/gcc.target/aarch64/sve/pr121091-1.c 
> b/gcc/testsuite/gcc.target/aarch64/sve/pr121091-1.c
> new file mode 100644
> index 00000000000..ea2e5ce6b6a
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/aarch64/sve/pr121091-1.c
> @@ -0,0 +1,25 @@
> +/* { dg-do compile } */
> +/* { dg-options "-O2" } */
> +
> +/* PR tree-optimization/121091 */
> +/* Switch conversion would convert this
> +   into static constant array but since
> +   svbool_t is a VLA type, it can't be
> +   stored in a constant pool. */
> +
> +#include "arm_sve.h"
> +
> +svbool_t e(int mode, svbool_t pg) {
> +    switch (mode) {
> +        case 0:
> +            pg = svptrue_pat_b16(SV_VL6);
> +            break;
> +        case 1:
> +            pg = svpfalse_b();
> +            break;
> +        case 2:
> +            pg = svptrue_pat_b16(SV_VL2);
> +            break;
> +    }
> +  return pg;
> +}
> diff --git a/gcc/varasm.cc b/gcc/varasm.cc
> index 10c1d2e3137..36b7cd8812d 100644
> --- a/gcc/varasm.cc
> +++ b/gcc/varasm.cc
> @@ -5001,6 +5001,11 @@ initializer_constant_valid_p_1 (tree value, tree 
> endtype, tree *cache)
>  {
>    tree ret;
>
> +  /* Variable sized vectors are never valid for initializers.  */
> +  if (VECTOR_TYPE_P (endtype)
> +      && !TYPE_VECTOR_SUBPARTS (endtype).is_constant ())
> +    return NULL_TREE;
> +
>    switch (TREE_CODE (value))
>      {
>      case CONSTRUCTOR:
> --
> 2.43.0
>

Reply via email to