From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7292 invoked by alias); 29 Sep 2014 10:24:47 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 7223 invoked by uid 48); 29 Sep 2014 10:24:43 -0000 From: "vries at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug rtl-optimization/61605] Potential optimization: Keep unclobbered argument registers live across function calls Date: Mon, 29 Sep 2014 10:24:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: rtl-optimization X-Bugzilla-Version: 5.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: vries at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_status cf_reconfirmed_on cc everconfirmed Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2014-09/txt/msg02664.txt.bz2 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.