https://gcc.gnu.org/g:9ff3f5b4d849512fd3529a15d28f4e7dfa1351d4
commit 9ff3f5b4d849512fd3529a15d28f4e7dfa1351d4 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. (cherry picked from commit d4c5d27a7b67759899c90793f47ac25519ce1b8b) 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 fafc4d6b77ab..4ae702e35876 100644 --- a/gcc/tree-ssa-forwprop.cc +++ b/gcc/tree-ssa-forwprop.cc @@ -2800,8 +2800,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; @@ -2814,8 +2814,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; @@ -3105,13 +3103,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; @@ -3155,13 +3147,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); } tree orig1_for_perm
