From 55f898008ec8235897cf56c89f5599c3ec1bc963 Mon Sep 17 00:00:00 2001 From: Tamar Christina Date: Fri, 18 Oct 2024 10:36:19 +0100 Subject: [PATCH] middle-end: Fix VEC_PERM_EXPR lowering since relaxation of vector sizes In GCC 14 VEC_PERM_EXPR was relaxed to be able to permute to a 2x larger vector than the size of the input vectors. However various passes and transformations were not updated to account for this. I have patches in these area that I will be upstreaming with individual patches that expose them. This one is that vectlower tries to lower based on the size of the input vectors rather than the size of the output. As a consequence it creates an invalid vector of half the size. Luckily we ICE because the resulting nunits doesn't match the vector size. gcc/ChangeLog: * tree-vect-generic.cc (lower_vec_perm): Use output vector size instead of input vector when determining output nunits. gcc/testsuite/ChangeLog: * gcc.dg/vec-perm-lower.c: New test. --- gcc/testsuite/gcc.dg/vec-perm-lower.c | 16 ++++++++++++++++ gcc/tree-vect-generic.cc | 7 ++++--- 2 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/vec-perm-lower.c diff --git a/gcc/testsuite/gcc.dg/vec-perm-lower.c b/gcc/testsuite/gcc.dg/vec-perm-lower.c new file mode 100644 index 00000000000..da738fbeed8 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vec-perm-lower.c @@ -0,0 +1,16 @@ +/* { dg-do compile } */ +/* { dg-options "-fgimple -O2" } */ + +typedef char v8qi __attribute__ ((vector_size (8))); +typedef char v16qi __attribute__ ((vector_size (16))); + +v16qi __GIMPLE (ssa) +foo (v8qi a, v8qi b) +{ + v16qi _5; + + __BB(2): + _5 = __VEC_PERM (a, b, _Literal (unsigned char [[gnu::vector_size(16)]]) { _Literal (unsigned char) 0, _Literal (unsigned char) 16, _Literal (unsigned char) 1, _Literal (unsigned char) 17, _Literal (unsigned char) 2, _Literal (unsigned char) 18, _Literal (unsigned char) 3, _Literal (unsigned char) 19, _Literal (unsigned char) 4, _Literal (unsigned char) 20, _Literal (unsigned char) 5, _Literal (unsigned char) 21, _Literal (unsigned char) 6, _Literal (unsigned char) 22, _Literal (unsigned char) 7, _Literal (unsigned char) 23 }); + return _5; + +} diff --git a/gcc/tree-vect-generic.cc b/gcc/tree-vect-generic.cc index 3041fb8fcf2..f86f7eabb25 100644 --- a/gcc/tree-vect-generic.cc +++ b/gcc/tree-vect-generic.cc @@ -1500,6 +1500,7 @@ lower_vec_perm (gimple_stmt_iterator *gsi) tree mask = gimple_assign_rhs3 (stmt); tree vec0 = gimple_assign_rhs1 (stmt); tree vec1 = gimple_assign_rhs2 (stmt); + tree res_vect_type = TREE_TYPE (gimple_assign_lhs (stmt)); tree vect_type = TREE_TYPE (vec0); tree mask_type = TREE_TYPE (mask); tree vect_elt_type = TREE_TYPE (vect_type); @@ -1512,7 +1513,7 @@ lower_vec_perm (gimple_stmt_iterator *gsi) location_t loc = gimple_location (gsi_stmt (*gsi)); unsigned i; - if (!TYPE_VECTOR_SUBPARTS (vect_type).is_constant (&elements)) + if (!TYPE_VECTOR_SUBPARTS (res_vect_type).is_constant (&elements)) return; if (TREE_CODE (mask) == SSA_NAME) @@ -1672,9 +1673,9 @@ lower_vec_perm (gimple_stmt_iterator *gsi) } if (constant_p) - constr = build_vector_from_ctor (vect_type, v); + constr = build_vector_from_ctor (res_vect_type, v); else - constr = build_constructor (vect_type, v); + constr = build_constructor (res_vect_type, v); gimple_assign_set_rhs_from_tree (gsi, constr); update_stmt (gsi_stmt (*gsi)); }