https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128443
Bug ID: 128443
Summary: Reassociate shift-add-add chain with an out of range
constant for RISC-V
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Keywords: missed-optimization
Severity: normal
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: law at gcc dot gnu.org
Blocks: 26163
Target Milestone: ---
Target: riscv
This is a hacked testcase from x264.
typedef unsigned char pixel;
typedef struct
{
signed char ref[2][40];
char pad[22992 - 80];
pixel *p_fref[2][32][6];
} x264_t;
pixel *
f (x264_t *h, int i8)
{
int i_ref0 = h->ref[0][i8];
return h->p_fref[0][i_ref0][0];
}
li a4,24576 # 17 [c=4 l=4] *movdi_64bit/1
sh1add t0,a5,a5 # 13 [c=4 l=4] *shNadd
slli t1,t0,4 # 14 [c=4 l=4] ashldi3
add a0,a0,t1 # 16 [c=4 l=4] *adddi3/0
add t2,a0,a4 # 18 [c=4 l=4] *adddi3/0
So we could add 1536 to t0 before the shift by 4. That would exchange an
li+add for an addi. Profitable. But very small on x264 AFAICT. And with the
li issuing speculatively with no input dependencies, it's even less profitable
in practice. Very low priority.
Referenced Bugs:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=26163
[Bug 26163] [meta-bug] missed optimization in SPEC (2026, 2k17, 2k and 2k6 and
95)