https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126175
Bug ID: 126175
Summary: LRA / SH2 and SH4 target result in 1% increase in
binary size
Product: gcc
Version: 16.1.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: middle-end
Assignee: unassigned at gcc dot gnu.org
Reporter: cedric.bail at pm dot me
Target Milestone: ---
Created attachment 64973
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=64973&action=edit
Reproduction case
Switching to default LRA for SH target reveal that SH2 and SH4 binary size
increase by about 1% due likely to the small displacement available for those
architecture. SH2A is mostly immune as it does have access to imm20. This is
visible on CSiBE, CoreMark and Busybox. The worst offender I found is busybox's
mkfs_ext2_main (
https://github.com/brgl/busybox/blob/master/util-linux/mkfs_ext2.c#L239 ).
Forcing the use of frame pointer, mostly solve the problem for that busybox
function, but doesn't at scale and it doesn't for the attached reproduction
case. The reproduction case is pathological and show a lot worse than what
normal use would. I have tried both -Os and -O2 and those have no effect on
solving the problem. The problem shows identically on SH2 and SH4 for the
reproduction case. This likely has performance impact too.
It seems to me that LRA does recalculates stack address instead of reusing them
while the old code was cleverly reusing a base pointer with small displacement.
This is visible when doing a diff between without and with LRA of the
reproduction case as a good portion of the small displacement are replaced by
reload and adding an immediate:
mov r14,r1
add #28,r1
mov.l @(48,r1),r5
- mov r14,r3
- mov.l .L5,r1
+ mov r14,r1
+ add #64,r1
mov r5,r6
+ mov.l r5,@r1
shll2 r6
+ mov r14,r1
add r6,r6
- add #64,r3
- mov.l r5,@(0,r3)
- mov r6,r4
+ add #68,r1
+ mov.l r6,@r1
+ mov.l .L5,r1
jsr @r1
- mov.l r6,@(4,r3)
- mov r14,r3
- add #64,r3
- mov.l @(4,r3),r6
- mov #0,r4
+ mov r6,r4
+ mov r14,r1
+ add #68,r1
+ mov.l @r1,r6
+ mov r14,r1
+ add #64,r1
+ mov.l @r1,r5
jsr @r8
- mov.l @r3,r5
+ mov #0,r4
add #92,r14
mov r14,r15
lds.l @r15+,pr