https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61605
vries at gcc dot gnu.org changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |NEW Last reconfirmed| |2014-09-29 CC| |vries at gcc dot gnu.org Ever confirmed|0 |1 --- Comment #4 from vries at gcc dot gnu.org --- > If a function is known to not clobber an argument register then the caller > shouldn't have to save/reload that register across the function call. If a function is known to not clobber an call_used_reg then the caller can use it as a non-call_used_reg across the function call. This diff shows the example with -fno-use-caller-save vs -fuse-caller-save: ... foo: .LFB1: .cfi_startproc - pushq %rbx - .cfi_def_cfa_offset 16 - .cfi_offset 3, -16 - movl %edi, %ebx + movl %edi, %edx call bar - addl %ebx, %eax - popq %rbx - .cfi_def_cfa_offset 8 + addl %edx, %eax ret .cfi_endproc .LFE1: ... -fuse-caller-save removes the entry/exit save/restore pair 'pushq %rbx'/'popq %rbx'. The 'movl %edi, %edx' is indeed non-optimal, but it's not a 'save' in the sense of save/restore pair generated at function entry/exit or around function calls. It's a copy at function entry of a hard reg argumument to a pseudo reg, generated at expand, which is followed by a copy of the pseudo reg to the same register to set the argument for the function call: ... (insn 2 4 3 2 (set (reg/v:SI 86 [ yD.1755 ]) (reg:SI 5 di [ yD.1755 ])) test.c:9 -1 (nil)) (note 3 2 6 2 NOTE_INSN_FUNCTION_BEG) (insn 6 3 7 2 (set (reg:SI 5 di) (reg/v:SI 86 [ yD.1755 ])) test.c:10 -1 (nil)) ... The second insn is removed in pass_fast_rtl_dce. The reg-alloc choiche for pseudo 86 in the first insn is dx, and the insn remains. I think there could be two ways to address this: 1. Teach a pass after ira, like pass_cprop_hardreg or pass_gcse2 to use the information collected by fuse-calller-save. 2. Teach ira to prefer the dx to di in this case. My guess would be pass_cprop_hardreg.