]> git.ipfire.org Git - thirdparty/gcc.git/commit
RISC-V: Fix overflow check in interleave pattern [PR122970].
authorRobin Dapp <rdapp@qti.qualcomm.com>
Thu, 18 Dec 2025 10:19:57 +0000 (11:19 +0100)
committerRobin Dapp <rdapp@oss.qualcomm.com>
Fri, 19 Dec 2025 18:41:54 +0000 (19:41 +0100)
commitd4e6fc510f90b0e6895841febfa9da8858653cfe
tree52dbcf662de92ed1eee167f6812570cd7f144957
parent23a2cab0e68e8452014986fbdbb93df4eca3e0a2
RISC-V: Fix overflow check in interleave pattern [PR122970].

In the pattern where we interpret and code-gen two interleaving series as if
they were represented in a larger type we check for overflow.
The overflow check is basically
 if (base + (nelems - 1) * step >> inner_bits != 0)
     overflow = true;

In the PR, base is negative and we interpret it as negative uint64
value.  Thus, e.g. base + (nelems - 1) * step  = -32 + 7 * 8 = 24.
24 fits uint8 and we wrongly assume that no overflow happens.

This patch reinterprets base as type of inner bit size which makes the
overflow check work.

PR target/122970

gcc/ChangeLog:

* config/riscv/riscv-v.cc (expand_const_vector_interleaved_stepped_npatterns):
Reinterpret base as smaller type.

gcc/testsuite/ChangeLog:

* lib/target-supports.exp: Add rvv_zvl128b_ok.
* gcc.target/riscv/rvv/autovec/pr122970.c: New test.
gcc/config/riscv/riscv-v.cc
gcc/testsuite/gcc.target/riscv/rvv/autovec/pr122970.c [new file with mode: 0644]
gcc/testsuite/lib/target-supports.exp