POLY_INT_CSTs can wrap for large enough vector lengths: 33 - svcntb ()
in uint64_t has a negative coefficient, (uint8_t) svcntb () and
(int8_t) svcntb () are narrowed coefficient-wise, and
(int64_t) svcntd () << 58 overflows. can_min_p and get_tree_range
assume they do not wrap. Both patches compute the range of the
constant over TARGET_POLY_INT_INDETERMINATE_BOUND in widest_int and
give up when it does not fit the type.
1/2 is v1 with the helper Andrea asked for and covers unsigned
constants in can_min_p. 2/2 covers signed ones, in get_tree_range and
can_min_p; its can_min_p part alone would let evrp's saturated range
fold MIN ((int64_t) (svcntb () * (1ULL << 59)), 5) to INT64_MIN, wrong
at VL 256. On RISC-V, which lacks the hook, an asm comparison of the
gcc.target/riscv/rvv tests at -O2 and -O3 shows no change.
OK for trunk?
Dominic P (2):
fold-const: Do not fold MIN of possibly wrapping unsigned
POLY_INT_CSTs
middle-end: Do not assume signed POLY_INT_CSTs cannot wrap
gcc/fold-const.cc | 41 ++++++++
gcc/fold-const.h | 1 +
.../aarch64/sve/acle/general/cntb_ptr_1.c | 11 +++
.../aarch64/sve/acle/general/min_poly_1.c | 55 +++++++++++
.../aarch64/sve/acle/general/min_poly_2.c | 88 +++++++++++++++++
.../aarch64/sve/acle/general/min_poly_2_run.c | 24 +++++
.../aarch64/sve/acle/general/min_poly_3.c | 50 ++++++++++
.../aarch64/sve/acle/general/min_poly_3_run.c | 20 ++++
.../aarch64/sve/acle/general/min_poly_4.c | 51 ++++++++++
gcc/value-query.cc | 96 +++----------------
10 files changed, 353 insertions(+), 84 deletions(-)
create mode 100644
gcc/testsuite/gcc.target/aarch64/sve/acle/general/cntb_ptr_1.c
create mode 100644
gcc/testsuite/gcc.target/aarch64/sve/acle/general/min_poly_1.c
create mode 100644
gcc/testsuite/gcc.target/aarch64/sve/acle/general/min_poly_2.c
create mode 100644
gcc/testsuite/gcc.target/aarch64/sve/acle/general/min_poly_2_run.c
create mode 100644
gcc/testsuite/gcc.target/aarch64/sve/acle/general/min_poly_3.c
create mode 100644
gcc/testsuite/gcc.target/aarch64/sve/acle/general/min_poly_3_run.c
create mode 100644
gcc/testsuite/gcc.target/aarch64/sve/acle/general/min_poly_4.c
--
2.56.0