https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117477
Bug ID: 117477
Summary: aarch64: Unnecessary stack spill generated around
function call
Product: gcc
Version: 15.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: rtl-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: dhruvc at nvidia dot com
Target Milestone: ---
Given the following input:
int test (int x), test2 (int x);
int foo (int x, int y) {
test (x);
int lhs = test2 (y);
return x + lhs;
}
GCC 15.0 generates the following assembly at -O2:
foo:
stp x29, x30, [sp, -48]!
mov x29, sp
str x19, [sp, 16]
mov w19, w0
str w1, [sp, 44]
bl test
ldr w0, [sp, 44]
bl test2
add w0, w19, w0
ldr x19, [sp, 16]
ldp x29, x30, [sp], 48
ret
The stack spill around the call to `test` is unnecessary, and LLVM does not
generate it:
foo:
stp x29, x30, [sp, #-32]!
stp x20, x19, [sp, #16]
mov x29, sp
mov w19, w1
mov w20, w0
bl test
mov w0, w19
bl test2
add w0, w0, w20
ldp x20, x19, [sp, #16]
ldp x29, x30, [sp], #32
ret
clang commit: bbc3af0577a05bf5c06f5c39d51b7d48bd63d65f
This issue seems to intermittently occur in older versions, and is not present
in 14.2.0 or 13.3.0.
CE: https://godbolt.org/z/rK7P4jffh