https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70432
Bug ID: 70432 Summary: Move operation across function call to reduce save / restore Product: gcc Version: 6.0 Status: UNCONFIRMED Keywords: missed-optimization Severity: enhancement Priority: P3 Component: rtl-optimization Assignee: unassigned at gcc dot gnu.org Reporter: glisse at gcc dot gnu.org Target Milestone: --- I have no idea how one would do such a transformation, and there is likely a dup of this somewhere... The compiler generates much smaller code for f2 than f1. void g(void); int f1(int a,int b,int c){ g(); return a+b+c; } int f2(int a,int b,int c){ int r=a+b+c; g(); return r; } f1: .LFB0: .cfi_startproc pushq %r12 .cfi_def_cfa_offset 16 .cfi_offset 12, -16 pushq %rbp .cfi_def_cfa_offset 24 .cfi_offset 6, -24 movl %esi, %r12d pushq %rbx .cfi_def_cfa_offset 32 .cfi_offset 3, -32 movl %edi, %ebx movl %edx, %ebp call g leal (%rbx,%r12), %eax popq %rbx .cfi_def_cfa_offset 24 addl %ebp, %eax popq %rbp .cfi_def_cfa_offset 16 popq %r12 .cfi_def_cfa_offset 8 ret .cfi_endproc .LFE0: .size f1, .-f1 .p2align 4,,15 .globl f2 .type f2, @function f2: .LFB1: .cfi_startproc addl %esi, %edi pushq %rbx .cfi_def_cfa_offset 16 .cfi_offset 3, -16 leal (%rdi,%rdx), %ebx call g movl %ebx, %eax popq %rbx .cfi_def_cfa_offset 8 ret .cfi_endproc