On 11/4/26 9:21 PM, Kito Cheng wrote:
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.  It also overrides an
explicit -mvector-strict-align.

Now -mcpu says if misaligned accesses are allowed, and -mtune only says if
they are slow:

- Scalar: unless -m[no-]strict-align is given, use -mstrict-align if -mtune
   says they are slow or -mcpu does not support them.
- Vector: -m[no-]vector-strict-align wins if given, otherwise -mcpu decides.
   The option now defaults to -1, so we can tell if it was given.

Without -mcpu, misaligned accesses are not allowed.

        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/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.
It looks like Sashiko has findings that are worth addressing:

https://gcc.sashiko.dev/#/patchset/20261105042154.1546368-1-kito.cheng%40sifive.com

More importantly there was some concern about inconsistency in behavior vs the patch description.  Just to be clear I think everyone expects the explicit -m option to override any implicit/default behavior.

Jeff

Reply via email to