https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126873
--- Comment #6 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The releases/gcc-15 branch has been updated by Jeff Law <[email protected]>: https://gcc.gnu.org/g:0bcf1dc2e7010c968e2b21a34e1042ec088fcc25 commit r15-11504-g0bcf1dc2e7010c968e2b21a34e1042ec088fcc25 Author: Jin Ma <[email protected]> Date: Tue Aug 18 23:31:24 2026 +0800 RISC-V: Fix sub-Pmode index in vec_set/vec_extract [PR126873] When gimple-isel lowers a variable-index element access on a fixed-length vector into .VEC_SET or .VEC_EXTRACT, the index may be narrower than Pmode. The vec_set and vec_extract expanders used gen_lowpart to convert it to Pmode, which only reinterprets the register and drops the source-level truncation. The full 64-bit value is then used as the slide amount of vslideup/vslidedown and wrong code is generated. Fix this by zero-extending a sub-Pmode index with convert_to_mode instead. PR target/126873 gcc/ChangeLog: * config/riscv/autovec.md (vec_set<mode>): Zero-extend a sub-Pmode index to Pmode. (vec_extract<mode><vel>): Likewise. gcc/testsuite/ChangeLog: * gcc.target/riscv/pr126873.c: New test. Reported-by: XChy <[email protected]> Signed-off-by: Jin Ma <[email protected]> (cherry picked from commit 1a29fdbdcb6775cd93bfc23426bf4e8b6b0475d2)
