]> git.ipfire.org Git - thirdparty/gcc.git/commit
[RISC-V][PR target/120811] Improving address reloads in LRA
authorShreya Munnangi <smunnangi1@ventanamicro.com>
Mon, 13 Oct 2025 22:13:44 +0000 (16:13 -0600)
committerJeff Law <jlaw@ventanamicro.com>
Mon, 13 Oct 2025 22:15:02 +0000 (16:15 -0600)
commit304d7359a67b8f7b979bf5941c7a5cbabf1aebcf
treee0e05d577d9a44afb5c8c6e4aa91b1bb7065431f
parenta92369a6be95c8df1525b02635b9e7c16fc3640e
[RISC-V][PR target/120811] Improving address reloads in LRA

In pr120811, we have cases where GCC is emitting an extra addi instruction
instead of using the 12-bit signed-immediate of ld.

addi t1, t1, 1
ld   t1, 0(t1)

This problem occurs when fp -> sp+offset elimination results in an
out-of-range constant and we generate an address reload in LRA using
addsi/adddi expanders.

We've already adjusted the expanders to widen the set of valid operands to
allow more constants for the 2nd input operand. These expanders, rather than
constructing the constant into a register and using an add instruction, will
generate two addi instructions (or shNadd) during initial RTL generation.

We define a new pattern for cases where we need to access the current frame
and the offsets are too large. This gets reasonable code out of LRA in a form
fold-mem-offsets can handle, rather than having to wait for sched2 to do
the height reduction transformation and leaving in the unnecessary add
instruction in the RTL stream.

To avoid the two addi instructions being squashed back together in the
post-reload combine, we remove the adddi3_const_sum_of_two_s12 pattern.

We are seeing about 100 billion dynamic instructions saved which is about 5%
on cactuBSSN and a 2% improvement in performance on the BPI.

PR target/120811

gcc/

* config/riscv/riscv.cc (synthesize_add): Exchange constant terms when
generating addi pairs.
(synthesize_addsi): Similarly.
* config/riscv/riscv.md (addptr<mode>3): New define_expand.
(*add<mode>3_const_sum_of_two_s12): Remove pattern.

gcc/testsuite/

* gcc.target/riscv/add-synthesis-1.c: Adjust const to fit in range.
* gcc.target/riscv/pr120811.c: Add new test case.
* gcc.target/riscv/sum-of-two-s12-const-1.c: Adjust const to fit in range.
gcc/config/riscv/riscv.cc
gcc/config/riscv/riscv.md
gcc/testsuite/gcc.target/riscv/add-synthesis-1.c
gcc/testsuite/gcc.target/riscv/pr120811.c
gcc/testsuite/gcc.target/riscv/sum-of-two-s12-const-1.c