]> git.ipfire.org Git - thirdparty/gcc.git/commit
RISC-V: Fix bug for expand_const_vector interleave [PR118931]
authorPan Li <pan2.li@intel.com>
Sat, 22 Feb 2025 11:34:52 +0000 (19:34 +0800)
committerPan Li <pan2.li@intel.com>
Thu, 27 Feb 2025 23:33:17 +0000 (07:33 +0800)
commite7287cbbb208b676991096dd9081ff8a61c49781
tree7446fba0fb1307616134f945c4d23e4868c99a81
parent955de3733a9ef301e2d95009cd59a1eb4ee5273c
RISC-V: Fix bug for expand_const_vector interleave [PR118931]

This patch would like to fix one bug when expanding const vector for the
interleave case.  For example, we have:

base1 = 151
step = 121

For vec_series, we will generate vector in format of v[i] = base + i * step.
Then the vec_series will have below result for HImode, and we can find
that the result overflow to the highest 8 bits of HImode.

v1.b = {151, 255, 7,  0, 119,  0, 231,  0, 87,  1, 199,  1, 55,   2, 167,   2}

Aka we expect v1.b should be:

v1.b = {151, 0, 7,  0, 119,  0, 231,  0, 87,  0, 199,  0, 55,   0, 167,   0}

After that it will perform the IOR with v2 for the base2(aka another series).

v2.b =  {0,  17, 0, 33,   0, 49,   0, 65,  0, 81,   0, 97,  0, 113,   0, 129}

Unfortunately, the base1 + i * step1 in HImode may overflow to the high
8 bits, and the high 8 bits will pollute the v2 and result in incorrect
value in const_vector.

This patch would like to perform the overflow to smode check before the
optimized interleave code generation.  If overflow or VLA, it will fall
back to the default merge approach.

The below test suites are passed for this patch.
* The rv64gcv fully regression test.

PR target/118931

gcc/ChangeLog:

* config/riscv/riscv-v.cc (expand_const_vector): Add overflow to
smode check and clean up highest bits if overflow.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/base/pr118931-run-1.c: New test.

Signed-off-by: Pan Li <pan2.li@intel.com>
gcc/config/riscv/riscv-v.cc
gcc/testsuite/gcc.target/riscv/rvv/base/pr118931-run-1.c [new file with mode: 0644]