]> git.ipfire.org Git - thirdparty/gcc.git/commit
[RISC-V][PR target/118241] Fix data prefetch predicate/constraint for RISC-V
authorJeff Law <jlaw@ventanamicro.com>
Sat, 21 Jun 2025 14:24:58 +0000 (08:24 -0600)
committerJeff Law <jlaw@ventanamicro.com>
Sat, 21 Jun 2025 14:26:33 +0000 (08:26 -0600)
commit49199bb29628365fc6c60bd185808a1bad65086d
tree590658fd00da3861f5fa25aece02a4ff7f732018
parentb76779c7cd6b92f167a80f16f11f599eea4dfc67
[RISC-V][PR target/118241] Fix data prefetch predicate/constraint for RISC-V

The RISC-V prefetch support is broken in a few ways.  This addresses the data
side prefetch problems.  I'd mistakenly thought this BZ was a prefetch.i
related (which has deeper problems).

The basic problem is we were accepting any valid address when in fact there are
restrictions.  This patch more precisely defines the predicate such that we
allow

REG
REG+D

Where D must have the low 5 bits clear.  Note that absolute addresses fall into
the REG+D form using the x0 for the register operand since it always has the
value zero.  The test verifies REG, REG+D, ABS addressing modes that are valid
as well as REG+D and ABS which must be reloaded into a REG because the
displacement has low bits set.

An earlier version of this patch has gone through testing in my tester on rv32
and rv64.  Obviously I'll wait for pre-commit CI to do its thing before moving
forward.

This is a good backport candidate after simmering on the trunk for a bit.

PR target/118241
gcc/
* config/riscv/predicates.md (prefetch_operand): New predicate.
* config/riscv/constraints.md (Q): New constraint.
* config/riscv/riscv.md (prefetch): Use new predicate and constraint.
(riscv_prefetchi_<mode>): Similarly.

gcc/testsuite/
* gcc.target/riscv/pr118241.c: New test.
gcc/config/riscv/constraints.md
gcc/config/riscv/predicates.md
gcc/config/riscv/riscv.md
gcc/testsuite/gcc.target/riscv/pr118241.c [new file with mode: 0644]