https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126640
--- Comment #4 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Kito Cheng <[email protected]>: https://gcc.gnu.org/g:a0b9eb2dc14273e0dae3f79d01ba01d13b586c47 commit r17-7155-ga0b9eb2dc14273e0dae3f79d01ba01d13b586c47 Author: Kito Cheng <[email protected]> Date: Fri Oct 23 20:28:49 2026 +0800 RISC-V: Do not let -mtune allow misaligned accesses [PR126640] We take whether misaligned accesses work from the -mtune table, but this depends on the hardware. So -mtune=generic-ooo emits misaligned vle32.v/vse32.v for any -march, and these can trap. Before this patch, this happens even with an explicit -mvector-strict-align. Now -mcpu says if misaligned accesses are allowed, and -mtune only says if they are slow. An explicit -m[no-]strict-align or -m[no-]vector-strict-align always wins: - Scalar: if -m[no-]strict-align is not given, use -mstrict-align when -mtune says they are slow or -mcpu does not support them. - Vector: if -m[no-]vector-strict-align is not given, -mcpu decides. The option now defaults to -1, so we can tell if it was given. Without -mcpu, misaligned accesses are not allowed unless an explicit option allows them. PR target/126640 gcc/ChangeLog: * config/riscv/riscv.cc (riscv_scalar_unaligned_access_allowed_p): New function. (riscv_vector_unaligned_access_allowed_p): New function. (riscv_can_inline_p): Compare whether misaligned vector accesses are allowed instead of the raw -mvector-strict-align setting. (riscv_override_options_internal): Take whether misaligned accesses are allowed from -mcpu, not -mtune, and let an explicit -m[no-]vector-strict-align win. * config/riscv/riscv.opt (mvector-strict-align): Init to -1. * doc/invoke.texi (RISC-V Options): Update -mstrict-align, -mscalar-strict-align and -mvector-strict-align. gcc/testsuite/ChangeLog: * gcc.target/riscv/cpymem-32-ooo.c: Add -mno-strict-align. * gcc.target/riscv/cpymem-64-ooo.c: Likewise. * gcc.target/riscv/movmem-scalar-32.c: Likewise. * gcc.target/riscv/movmem-scalar-64.c: Likewise. * gcc.target/riscv/setmem-scalar-32.c: Likewise. * gcc.target/riscv/setmem-scalar-64.c: Likewise. * gcc.target/riscv/load-no-shift.c: Likewise. * gcc.target/riscv/rvv/autovec/pr122445.c: Add -mno-vector-strict-align. * gcc.target/riscv/predef-align-1.c: Use -mcpu=thead-c906. * gcc.target/riscv/predef-align-7.c: New test. * gcc.target/riscv/pr126640-1.c: New test. * gcc.target/riscv/pr126640-2.c: New test. * gcc.target/riscv/rvv/autovec/pr126640-1.c: New test. * gcc.target/riscv/rvv/autovec/pr126640-2.c: New test. * gcc.target/riscv/rvv/autovec/pr126640-3.c: New test.
