https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70048
Bug ID: 70048
Summary: [AArch64] Inefficient local array addressing
Product: gcc
Version: 6.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: wdijkstr at arm dot com
Target Milestone: ---
The following example generates very inefficient code on AArch64:
int f1(int i) { int p[1000]; p[i] = 1; return p[i + 10] + p[i + 20]; }
f1:
sub sp, sp, #4000
add w2, w0, 10
add x4, sp, 4000
add w1, w0, 20
mov w3, 1
add x0, x4, x0, sxtw 2
add x2, x4, x2, sxtw 2
sub x0, x0, #4096
add x1, x4, x1, sxtw 2
sub x1, x1, #4096
sub x2, x2, #4096
str w3, [x0, 96]
ldr w0, [x1, 96]
ldr w2, [x2, 96]
add sp, sp, 4000
add w0, w2, w0
ret
Previous compilers, eg GCC4.9 generate:
f1:
sub sp, sp, #4000
add w1, w0, 10
add w2, w0, 20
mov w3, 1
str w3, [sp,w0,sxtw 2]
ldr w1, [sp,w1,sxtw 2]
ldr w0, [sp,w2,sxtw 2]
add sp, sp, 4000
add w0, w1, w0
ret