-mtune=generic-ooo emits misaligned vector accesses for any -march, and
these can trap.  Scalar accesses have the same problem.  The cause is
that we read this from the -mtune table, but it depends on the hardware.

Patch 1 fixes an old bug: if -m[no-]strict-align is not given,
MASK_STRICT_ALIGN can be set but is never cleared.  So a target
attribute or pragma cannot allow misaligned accesses, and
#pragma GCC target defines __riscv_misaligned_avoid.

Patch 2 fixes the PR.  -mcpu now 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.
I made few structural changes on purpose, so it is easy to backport to
GCC 16.

Patch 3 is for trunk only.  It moves this data from riscv_tune_param to a
new FEATURES field in RISCV_CORE, so -mtune has no effect at all.  The
code for each -mcpu does not change.

Users who need misaligned accesses without -mcpu must now use
-mno-strict-align or -mno-vector-strict-align.

Changes since v1:

- Rebase.
- New patch 1, for the MASK_STRICT_ALIGN issue that Sashiko found.
- Reword the commit message of patch 2.  The old one said "It also
  overrides an explicit -mvector-strict-align", which was about the
  behavior before the patch, but read like the new behavior.
- Patch 3: remove the fields from the new mips-i8500 tune table too.
- -mcpu=native now gets the misaligned access support of the detected
  core, since the driver also passes -mcpu=<core> after r17-6379
  ("RISC-V: Pass the detected core with -mcpu=native").

Kito Cheng (3):
  RISC-V: Clear MASK_STRICT_ALIGN when it is not given
  RISC-V: Do not let -mtune allow misaligned accesses [PR126640]
  RISC-V: Move unaligned access support from tune to CPU features

 gcc/common/config/riscv/riscv-common.cc       |   7 +-
 gcc/config/riscv/driver-riscv.cc              |   3 +-
 gcc/config/riscv/gen-riscv-mcpu-texi.cc       |   3 +-
 gcc/config/riscv/riscv-cores.def              |  64 ++++++++-
 gcc/config/riscv/riscv-protos.h               |  12 ++
 gcc/config/riscv/riscv.cc                     | 131 +++++++++---------
 gcc/config/riscv/riscv.opt                    |   2 +-
 gcc/doc/invoke.texi                           |  19 +--
 .../gcc.target/riscv/cpymem-32-ooo.c          |   2 +-
 .../gcc.target/riscv/cpymem-64-ooo.c          |   2 +-
 .../gcc.target/riscv/mcpu-unaligned-1.c       |  15 ++
 .../gcc.target/riscv/movmem-scalar-32.c       |   2 +-
 .../gcc.target/riscv/movmem-scalar-64.c       |   2 +-
 gcc/testsuite/gcc.target/riscv/pr126640-1.c   |  15 ++
 gcc/testsuite/gcc.target/riscv/pr126640-2.c   |  15 ++
 .../gcc.target/riscv/predef-align-1.c         |   2 +-
 .../gcc.target/riscv/predef-align-3.c         |   4 +-
 .../gcc.target/riscv/predef-align-7.c         |  16 +++
 .../gcc.target/riscv/predef-align-8.c         |  16 +++
 .../gcc.target/riscv/rvv/autovec/pr122445.c   |   2 +-
 .../gcc.target/riscv/rvv/autovec/pr126640-1.c |  16 +++
 .../gcc.target/riscv/rvv/autovec/pr126640-2.c |  16 +++
 .../gcc.target/riscv/rvv/autovec/pr126640-3.c |  16 +++
 .../gcc.target/riscv/setmem-scalar-32.c       |   2 +-
 .../gcc.target/riscv/setmem-scalar-64.c       |   2 +-
 .../gcc.target/riscv/strict-align-attr-1.c    |  14 ++
 .../gcc.target/riscv/strict-align-attr-2.c    |  13 ++
 .../gcc.target/riscv/strict-align-pragma-1.c  |  17 +++
 .../gcc.target/riscv/strict-align-pragma-2.c  |  13 ++
 29 files changed, 348 insertions(+), 95 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/riscv/mcpu-unaligned-1.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/pr126640-1.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/pr126640-2.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/predef-align-7.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/predef-align-8.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/autovec/pr126640-1.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/autovec/pr126640-2.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/autovec/pr126640-3.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/strict-align-attr-1.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/strict-align-attr-2.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/strict-align-pragma-1.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/strict-align-pragma-2.c


base-commit: 535e0759e5b7153470d4d2bf91c8d1a04747948f
-- 
2.54.0

Reply via email to