https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66179
Bug ID: 66179 Summary: Sub-optimal code generation with __attribute__((leaf)) Product: gcc Version: 5.1.0 Status: UNCONFIRMED Severity: minor Priority: P3 Component: other Assignee: unassigned at gcc dot gnu.org Reporter: mednafen at sent dot com Target Milestone: --- Created attachment 35556 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=35556&action=edit C code which demonstrates the issue. The attached code, when compiled like(for example): gcc -fno-asynchronous-unwind-tables -O2 -S -o leaf.s -c leaf.c (with 4.9.2 or 5.1.0, Linux x86_64) produces bloated, sub-optimal assembly like: test_call_leaf: pushq %r12 pushq %rbp pushq %rbx movl a(%rip), %r12d movl c(%rip), %ebx call function_leaf movl b(%rip), %ebp addl $2, %r12d addl $2, %ebx movl %r12d, a(%rip) call function_leaf addl $2, %ebp movl %ebx, c(%rip) movl %ebp, b(%rip) popq %rbx popq %rbp popq %r12 ret compared to a more optimal possibility: test_call_normal: subq $8, %rsp addl $2, a(%rip) call function_normal addl $2, b(%rip) call function_normal addl $2, c(%rip) addq $8, %rsp ret