https://gcc.gnu.org/g:d4c5d27a7b67759899c90793f47ac25519ce1b8b
commit r16-6671-gd4c5d27a7b67759899c90793f47ac25519ce1b8b Author: Robin Dapp <[email protected]> Date: Thu Jan 8 14:22:18 2026 +0100 forwprop: Use ssizetype for mask [PR123414]. RVV's vectors can get very large with LMUL8. In the PR we have 256-element char vectors which get permuted. For permuting them we use a mask vectype that is deduced from the element type without checking if the permute indices fit this type. That leads to an invalid permute mask which gets optimized away. This patch uses ssizetype as masktype instead. PR tree-optimization/123414 gcc/ChangeLog: * tree-ssa-forwprop.cc (simplify_vector_constructor): Use ssizetype as mask type. gcc/testsuite/ChangeLog: * gcc.target/riscv/rvv/autovec/pr123414.c: New test. Diff: --- .../gcc.target/riscv/rvv/autovec/pr123414.c | 29 ++++++++++++++++++++++ gcc/tree-ssa-forwprop.cc | 22 +++------------- 2 files changed, 33 insertions(+), 18 deletions(-) diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/pr123414.c b/gcc/testsuite/gcc.target/riscv/rvv/autovec/pr123414.c new file mode 100644 index 000000000000..9e3bf6bca816 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/pr123414.c @@ -0,0 +1,29 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv64gcv_zvl256b -mabi=lp64d -mrvv-max-lmul=m8 -O3 -fsigned-char -fno-strict-aliasing -fwrapv -fdump-tree-optimized -std=gnu99" } */ + +signed char a=2; +long long b; +long c = 93; +int e[1][9]; + +void +g (long cc, int ee[][9]) +{ + for (int i = 0; i < 4; i++) + for (int j = 0; j < 5; j++) + for (unsigned k = 0; k < 9; k++) + { + a *= cc; + for (int l = 0; l < 6; l += (ee[k] <= 0) + 2) + ; + } +} + +int main() { + g( c, e); + b = (int)a; + if (b != 34) + __builtin_abort (); +} + +/* { dg-final { scan-tree-dump-times "\[a-zA-Z_\]\[a-zA-Z0-9_\]+.=.VEC_PERM_EXPR <_\[0-9\]+, \\\{ 1(?:, 1){255} \\\}, \\\{ 0, 257, 258" 3 "optimized" } } */ diff --git a/gcc/tree-ssa-forwprop.cc b/gcc/tree-ssa-forwprop.cc index c5bad3ddf381..b70fe8169adc 100644 --- a/gcc/tree-ssa-forwprop.cc +++ b/gcc/tree-ssa-forwprop.cc @@ -3829,8 +3829,8 @@ static bool simplify_vector_constructor (gimple_stmt_iterator *gsi) { gimple *stmt = gsi_stmt (*gsi); - tree op, orig[2], type, elem_type; - unsigned elem_size, i; + tree op, orig[2], type; + unsigned i; unsigned HOST_WIDE_INT nelts; unsigned HOST_WIDE_INT refnelts; enum tree_code conv_code; @@ -3843,8 +3843,6 @@ simplify_vector_constructor (gimple_stmt_iterator *gsi) if (!TYPE_VECTOR_SUBPARTS (type).is_constant (&nelts)) return false; - elem_type = TREE_TYPE (type); - elem_size = TREE_INT_CST_LOW (TYPE_SIZE (elem_type)); orig[0] = NULL; orig[1] = NULL; @@ -4177,13 +4175,7 @@ simplify_vector_constructor (gimple_stmt_iterator *gsi) machine_mode vmode = TYPE_MODE (perm_type); if (!can_vec_perm_const_p (vmode, vmode, indices)) return false; - mask_type - = build_vector_type (build_nonstandard_integer_type (elem_size, 1), - refnelts); - if (GET_MODE_CLASS (TYPE_MODE (mask_type)) != MODE_VECTOR_INT - || maybe_ne (GET_MODE_SIZE (TYPE_MODE (mask_type)), - GET_MODE_SIZE (TYPE_MODE (perm_type)))) - return false; + mask_type = build_vector_type (ssizetype, refnelts); tree op2 = vec_perm_indices_to_tree (mask_type, indices); bool converted_orig1 = false; gimple_seq stmts = NULL; @@ -4248,13 +4240,7 @@ simplify_vector_constructor (gimple_stmt_iterator *gsi) machine_mode vmode = TYPE_MODE (type); if (!can_vec_perm_const_p (vmode, vmode, indices)) return false; - mask_type - = build_vector_type (build_nonstandard_integer_type (elem_size, 1), - nelts); - if (GET_MODE_CLASS (TYPE_MODE (mask_type)) != MODE_VECTOR_INT - || maybe_ne (GET_MODE_SIZE (TYPE_MODE (mask_type)), - GET_MODE_SIZE (TYPE_MODE (type)))) - return false; + mask_type = build_vector_type (ssizetype, nelts); blend_op2 = vec_perm_indices_to_tree (mask_type, indices); }
