From: Robin Dapp Date: Mon, 15 Dec 2025 10:20:54 +0000 (+0100) Subject: vect: Fix scale-only pass in vect_gather_scatter_fn_p [PR123118]. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3c2b6906fb49401e0fe41b810e4396b72b969267;p=thirdparty%2Fgcc.git vect: Fix scale-only pass in vect_gather_scatter_fn_p [PR123118]. In the process of refactoring the gather/scatter rework this likely got lost. In the "third pass" we look for a configuration with a smaller scale and a larger offset type with the same signedness. We want to be able to multiply the offset by the new scale but not change the offset sign. What we actually checked is whether a converted offset type was supported without setting *supported_offset_vectype. This patch removes the check for the offset type change and replaces it with a TYPE_SIGN match. PR tree-optimization/123118 gcc/ChangeLog: * tree-vect-data-refs.cc (vect_gather_scatter_fn_p): Check that the type sign is equal. gcc/testsuite/ChangeLog: * g++.target/riscv/rvv/autovec/pr123118.C: New test. --- diff --git a/gcc/testsuite/g++.target/riscv/rvv/autovec/pr123118.C b/gcc/testsuite/g++.target/riscv/rvv/autovec/pr123118.C new file mode 100644 index 00000000000..8cef5a7fe91 --- /dev/null +++ b/gcc/testsuite/g++.target/riscv/rvv/autovec/pr123118.C @@ -0,0 +1,19 @@ +/* { dg-do compile } */ +/* { dg-options "-O3 -march=rv64gcv -mabi=lp64d" } */ + +long long a; +short c, d; +extern int e[][1][1][1]; +extern bool f[][1][4][2]; +#include + +void +g () +{ + for (bool b;;) + for (signed char h (c); h < 4; h += -4487 - 119) + { + e[b][b][b][b] = std::max (std::min ((long long) 3, a), (long long) d); + f[0][0][h][1] = h; + } +} diff --git a/gcc/tree-vect-data-refs.cc b/gcc/tree-vect-data-refs.cc index b86e17d1a95..89a9077af0d 100644 --- a/gcc/tree-vect-data-refs.cc +++ b/gcc/tree-vect-data-refs.cc @@ -4716,13 +4716,9 @@ vect_gather_scatter_fn_p (vec_info *vinfo, bool read_p, bool masked_p, unsigned int precision = TYPE_PRECISION (TREE_TYPE (configs[i].offset_vectype)); if (configs[i].scale < scale - && precision >= needed_precision - && (supportable_convert_operation (CONVERT_EXPR, - configs[i].offset_vectype, - offset_vectype, &tmp) - || (needed_precision == offset_precision - && tree_nop_conversion_p (configs[i].offset_vectype, - offset_vectype)))) + && TYPE_SIGN (configs[i].offset_vectype) + == TYPE_SIGN (offset_vectype) + && precision >= needed_precision) { *ifn_out = configs[i].ifn; *offset_vectype_out = configs[i].offset_vectype;