https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106439
Bug ID: 106439
Summary: RISC-V suboptimal codegen for large constants
Product: gcc
Version: 13.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: vineet.gupta at linux dot dev
CC: cmuellner at linux dot com, kito at gcc dot gnu.org,
wilson at gcc dot gnu.org
Target Milestone: ---
Target: riscv
As part of experiments to create smaller tests for
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106265, ran into a slightly
different issue involving large constants (> S12) and stack access.
RISC-V codegen for stack accesses with offsets > S12 is terrible.
long foo(void)
{
long a[512];
return a[500];
}
output for rv64 -O2 : gcc trunk as of June 14 (commit 6abe341558ab)
foo:
li t0,-4096
li a5,4096
add sp,sp,t0
addi a5,a5,-96
add a5,a5,sp
li t0,4096
ld a0,0(a5)
add sp,sp,t0
jr ra
Compare the same code to aarch64:
foo:
sub sp, sp, #4096
ldr x0, [sp, 4000]
add sp, sp, 4096
Of course part of the problem is limited S12 offset encoding in RV LD, but the
compiler can definitely do much better.