public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/61605] New: Potential optimization: Keep unclobbered argument registers live across function calls
@ 2014-06-25 11:39 patrick at parcs dot ath.cx
2014-09-28 7:15 ` [Bug rtl-optimization/61605] " andi-gcc at firstfloor dot org
` (8 more replies)
0 siblings, 9 replies; 10+ messages in thread
From: patrick at parcs dot ath.cx @ 2014-06-25 11:39 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61605
Bug ID: 61605
Summary: Potential optimization: Keep unclobbered argument
registers live across function calls
Product: gcc
Version: 4.10.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: rtl-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: patrick at parcs dot ath.cx
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. Example:
The C code:
static int __attribute__ ((noinline))
bar (int x)
{
return x + 3;
}
int
foo (int y)
{
return y + bar (y);
}
generates:
bar:
.LFB0:
.cfi_startproc
leal 3(%rdi), %eax
ret
.cfi_endproc
foo:
.LFB1:
.cfi_startproc
movl %edi, %edx
call bar
addl %edx, %eax
ret
.cfi_endproc
Here, %edi is saved to %edx even though the call to bar doesn't clobber %edi.
The assembly for the function foo could potentially be:
call bar
addl %edi, %eax
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug rtl-optimization/61605] Potential optimization: Keep unclobbered argument registers live across function calls
2014-06-25 11:39 [Bug rtl-optimization/61605] New: Potential optimization: Keep unclobbered argument registers live across function calls patrick at parcs dot ath.cx
@ 2014-09-28 7:15 ` andi-gcc at firstfloor dot org
2014-09-28 7:22 ` pinskia at gcc dot gnu.org
` (7 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: andi-gcc at firstfloor dot org @ 2014-09-28 7:15 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61605
Andi Kleen <andi-gcc at firstfloor dot org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |andi-gcc at firstfloor dot org,
| |tom at codesourcery dot com
--- Comment #1 from Andi Kleen <andi-gcc at firstfloor dot org> ---
This is in theory implemented in mainline with -fuse-caller-save
It doesn't seem to work for me though. I also didn't see the option doing
anything on a larger program.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug rtl-optimization/61605] Potential optimization: Keep unclobbered argument registers live across function calls
2014-06-25 11:39 [Bug rtl-optimization/61605] New: Potential optimization: Keep unclobbered argument registers live across function calls patrick at parcs dot ath.cx
2014-09-28 7:15 ` [Bug rtl-optimization/61605] " andi-gcc at firstfloor dot org
@ 2014-09-28 7:22 ` pinskia at gcc dot gnu.org
2014-09-28 7:36 ` andi-gcc at firstfloor dot org
` (6 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2014-09-28 7:22 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61605
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target| |x86_64-*-*
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Andi Kleen from comment #1)
> This is in theory implemented in mainline with -fuse-caller-save
> It doesn't seem to work for me though. I also didn't see the option doing
> anything on a larger program.
Most likely because it is not fully implemented for x86 :).
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug rtl-optimization/61605] Potential optimization: Keep unclobbered argument registers live across function calls
2014-06-25 11:39 [Bug rtl-optimization/61605] New: Potential optimization: Keep unclobbered argument registers live across function calls patrick at parcs dot ath.cx
2014-09-28 7:15 ` [Bug rtl-optimization/61605] " andi-gcc at firstfloor dot org
2014-09-28 7:22 ` pinskia at gcc dot gnu.org
@ 2014-09-28 7:36 ` andi-gcc at firstfloor dot org
2014-09-29 10:24 ` vries at gcc dot gnu.org
` (5 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: andi-gcc at firstfloor dot org @ 2014-09-28 7:36 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61605
--- Comment #3 from Andi Kleen <andi-gcc at firstfloor dot org> ---
It was supposed to be enabled with
Date: Fri May 30 11:39:49 2014 +0000
-fuse-caller-save - Enable for i386
2014-05-30 Tom de Vries <tom@codesourcery.com>
* config/i386/i386.c (TARGET_CALL_FUSAGE_CONTAINS_NON_CALLEE_CLOBBERS):
Redefine as true.
* gcc.target/i386/fuse-caller-save.c: New test.
* gcc.dg/ira-shrinkwrap-prep-1.c: Run with -fno-use-caller-save.
* gcc.dg/ira-shrinkwrap-prep-2.c: Same.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@211078
138bc75d-0d04-0410-961f-82ee72b054a4
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug rtl-optimization/61605] Potential optimization: Keep unclobbered argument registers live across function calls
2014-06-25 11:39 [Bug rtl-optimization/61605] New: Potential optimization: Keep unclobbered argument registers live across function calls patrick at parcs dot ath.cx
` (2 preceding siblings ...)
2014-09-28 7:36 ` andi-gcc at firstfloor dot org
@ 2014-09-29 10:24 ` vries at gcc dot gnu.org
2014-09-30 10:25 ` vries at gcc dot gnu.org
` (4 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: vries at gcc dot gnu.org @ 2014-09-29 10:24 UTC (permalink / raw)
To: gcc-bugs
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.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug rtl-optimization/61605] Potential optimization: Keep unclobbered argument registers live across function calls
2014-06-25 11:39 [Bug rtl-optimization/61605] New: Potential optimization: Keep unclobbered argument registers live across function calls patrick at parcs dot ath.cx
` (3 preceding siblings ...)
2014-09-29 10:24 ` vries at gcc dot gnu.org
@ 2014-09-30 10:25 ` vries at gcc dot gnu.org
2014-09-30 10:29 ` vries at gcc dot gnu.org
` (3 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: vries at gcc dot gnu.org @ 2014-09-30 10:25 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61605
--- Comment #6 from vries at gcc dot gnu.org ---
Created attachment 33618
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=33618&action=edit
[1/2] Use fuse-caller-save-info in cprop-hardreg
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug rtl-optimization/61605] Potential optimization: Keep unclobbered argument registers live across function calls
2014-06-25 11:39 [Bug rtl-optimization/61605] New: Potential optimization: Keep unclobbered argument registers live across function calls patrick at parcs dot ath.cx
` (4 preceding siblings ...)
2014-09-30 10:25 ` vries at gcc dot gnu.org
@ 2014-09-30 10:29 ` vries at gcc dot gnu.org
2014-10-16 9:16 ` vries at gcc dot gnu.org
` (2 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: vries at gcc dot gnu.org @ 2014-09-30 10:29 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61605
--- Comment #7 from vries at gcc dot gnu.org ---
Created attachment 33619
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=33619&action=edit
[2/2] Don't regard a copy with identical src and dest as killing dest
This patch adds handling of copies with identical source and destination
register in copyprop_hardreg_forward_1.
Using this patch series we get the desired code.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug rtl-optimization/61605] Potential optimization: Keep unclobbered argument registers live across function calls
2014-06-25 11:39 [Bug rtl-optimization/61605] New: Potential optimization: Keep unclobbered argument registers live across function calls patrick at parcs dot ath.cx
` (5 preceding siblings ...)
2014-09-30 10:29 ` vries at gcc dot gnu.org
@ 2014-10-16 9:16 ` vries at gcc dot gnu.org
2014-10-17 6:37 ` vries at gcc dot gnu.org
2014-10-17 6:37 ` vries at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: vries at gcc dot gnu.org @ 2014-10-16 9:16 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61605
vries at gcc dot gnu.org changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |patch
--- Comment #8 from vries at gcc dot gnu.org ---
Patches submitted at:
https://gcc.gnu.org/ml/gcc-patches/2014-10/msg01513.html
https://gcc.gnu.org/ml/gcc-patches/2014-10/msg01514.html
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug rtl-optimization/61605] Potential optimization: Keep unclobbered argument registers live across function calls
2014-06-25 11:39 [Bug rtl-optimization/61605] New: Potential optimization: Keep unclobbered argument registers live across function calls patrick at parcs dot ath.cx
` (7 preceding siblings ...)
2014-10-17 6:37 ` vries at gcc dot gnu.org
@ 2014-10-17 6:37 ` vries at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: vries at gcc dot gnu.org @ 2014-10-17 6:37 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61605
--- Comment #10 from vries at gcc dot gnu.org ---
Author: vries
Date: Fri Oct 17 06:36:45 2014
New Revision: 216365
URL: https://gcc.gnu.org/viewcvs?rev=216365&root=gcc&view=rev
Log:
Use fuse-caller-save info in cprop-hardreg
2014-10-17 Tom de Vries <tom@codesourcery.com>
PR rtl-optimization/61605
* regcprop.c (copyprop_hardreg_forward_1): Use
regs_invalidated_by_this_call instead of regs_invalidated_by_call.
* gcc.target/i386/fuse-caller-save.c: Update addition check. Add movl
absence check.
Modified:
trunk/gcc/ChangeLog
trunk/gcc/regcprop.c
trunk/gcc/testsuite/ChangeLog
trunk/gcc/testsuite/gcc.target/i386/fuse-caller-save.c
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug rtl-optimization/61605] Potential optimization: Keep unclobbered argument registers live across function calls
2014-06-25 11:39 [Bug rtl-optimization/61605] New: Potential optimization: Keep unclobbered argument registers live across function calls patrick at parcs dot ath.cx
` (6 preceding siblings ...)
2014-10-16 9:16 ` vries at gcc dot gnu.org
@ 2014-10-17 6:37 ` vries at gcc dot gnu.org
2014-10-17 6:37 ` vries at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: vries at gcc dot gnu.org @ 2014-10-17 6:37 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61605
--- Comment #9 from vries at gcc dot gnu.org ---
Author: vries
Date: Fri Oct 17 06:36:35 2014
New Revision: 216364
URL: https://gcc.gnu.org/viewcvs?rev=216364&root=gcc&view=rev
Log:
Handle copy cycles in pass_cprop_hardreg
2014-10-17 Tom de Vries <tom@codesourcery.com>
PR rtl-optimization/61605
* regcprop.c (copyprop_hardreg_forward_1): Add copy_p and noop_p. Don't
notice stores for noops. Don't regard noops as copies.
Modified:
trunk/gcc/ChangeLog
trunk/gcc/regcprop.c
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2014-10-17 6:37 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-25 11:39 [Bug rtl-optimization/61605] New: Potential optimization: Keep unclobbered argument registers live across function calls patrick at parcs dot ath.cx
2014-09-28 7:15 ` [Bug rtl-optimization/61605] " andi-gcc at firstfloor dot org
2014-09-28 7:22 ` pinskia at gcc dot gnu.org
2014-09-28 7:36 ` andi-gcc at firstfloor dot org
2014-09-29 10:24 ` vries at gcc dot gnu.org
2014-09-30 10:25 ` vries at gcc dot gnu.org
2014-09-30 10:29 ` vries at gcc dot gnu.org
2014-10-16 9:16 ` vries at gcc dot gnu.org
2014-10-17 6:37 ` vries at gcc dot gnu.org
2014-10-17 6:37 ` vries at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).