public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: Question about patch for PR bootstrap/65150 (identical functions)
@ 2015-05-08 19:07 David Edelsohn
  2015-05-08 19:10 ` Jeff Law
  0 siblings, 1 reply; 6+ messages in thread
From: David Edelsohn @ 2015-05-08 19:07 UTC (permalink / raw)
  To: Steve Ellcey
  Cc: Martin Liška, Jan Hubicka, GCC Patches,
	Ramana Radhakrishnan, Richard Earnshaw

>>> Steve Ellcey wrote:
>
> After your change GCC sees that the code for f1 and f2 are identical
> so it replaced the body of f2 with a call to f1.  This optimization will
> save space but it is not going to be faster because any call to f2 will
> now include an extra call/return.  Do other platforms have this same issue
> or is there a way to make f2 an alias for f1 on other targets so no extra
> call is needed?  I looked around to see if there was a target function or
> macro that is used to make one function an alias of another but I didn't
> see anything.

This probably is not good for POWER, and probably not for ARM, in fact
probably not good for most RISC architectures.

- David

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Question about patch for PR bootstrap/65150 (identical functions)
  2015-05-08 19:07 Question about patch for PR bootstrap/65150 (identical functions) David Edelsohn
@ 2015-05-08 19:10 ` Jeff Law
  2015-05-08 19:35   ` Jakub Jelinek
  0 siblings, 1 reply; 6+ messages in thread
From: Jeff Law @ 2015-05-08 19:10 UTC (permalink / raw)
  To: David Edelsohn, Steve Ellcey
  Cc: Martin Liška, Jan Hubicka, GCC Patches,
	Ramana Radhakrishnan, Richard Earnshaw

On 05/08/2015 01:07 PM, David Edelsohn wrote:
>>>> Steve Ellcey wrote:
>>
>> After your change GCC sees that the code for f1 and f2 are identical
>> so it replaced the body of f2 with a call to f1.  This optimization will
>> save space but it is not going to be faster because any call to f2 will
>> now include an extra call/return.  Do other platforms have this same issue
>> or is there a way to make f2 an alias for f1 on other targets so no extra
>> call is needed?  I looked around to see if there was a target function or
>> macro that is used to make one function an alias of another but I didn't
>> see anything.
>
> This probably is not good for POWER, and probably not for ARM, in fact
> probably not good for most RISC architectures.
But isn't this code going to be creating aliases when the output format 
supports them -- which avoids the call/return overheads?

Which might argue that if we don't have aliases, then ICF might need to 
be a -Os thing.

jeff

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Question about patch for PR bootstrap/65150 (identical functions)
  2015-05-08 19:10 ` Jeff Law
@ 2015-05-08 19:35   ` Jakub Jelinek
  2015-05-08 21:58     ` Jan Hubicka
  0 siblings, 1 reply; 6+ messages in thread
From: Jakub Jelinek @ 2015-05-08 19:35 UTC (permalink / raw)
  To: Jeff Law
  Cc: David Edelsohn, Steve Ellcey, Martin Liška, Jan Hubicka,
	GCC Patches, Ramana Radhakrishnan, Richard Earnshaw

On Fri, May 08, 2015 at 01:09:52PM -0600, Jeff Law wrote:
> On 05/08/2015 01:07 PM, David Edelsohn wrote:
> >>>>Steve Ellcey wrote:
> >>
> >>After your change GCC sees that the code for f1 and f2 are identical
> >>so it replaced the body of f2 with a call to f1.  This optimization will
> >>save space but it is not going to be faster because any call to f2 will
> >>now include an extra call/return.  Do other platforms have this same issue
> >>or is there a way to make f2 an alias for f1 on other targets so no extra
> >>call is needed?  I looked around to see if there was a target function or
> >>macro that is used to make one function an alias of another but I didn't
> >>see anything.
> >
> >This probably is not good for POWER, and probably not for ARM, in fact
> >probably not good for most RISC architectures.
> But isn't this code going to be creating aliases when the output format
> supports them -- which avoids the call/return overheads?
> 
> Which might argue that if we don't have aliases, then ICF might need to be a
> -Os thing.

ICF uses aliases only when possible (when it can prove that the callers
don't care about function address equality/non-equality.  In other cases
ICF uses caller redirection (if it is possible to redirect all callers and
remove unused other call), or thunks (otherwise).

Thunks indeed can slow things down somewhat, especially if they can't tail
call the function.

	Jakub

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Question about patch for PR bootstrap/65150 (identical functions)
  2015-05-08 19:35   ` Jakub Jelinek
@ 2015-05-08 21:58     ` Jan Hubicka
  2015-05-08 22:56       ` Bernhard Reutner-Fischer
  0 siblings, 1 reply; 6+ messages in thread
From: Jan Hubicka @ 2015-05-08 21:58 UTC (permalink / raw)
  To: Jakub Jelinek
  Cc: Jeff Law, David Edelsohn, Steve Ellcey, Martin Liška,
	Jan Hubicka, GCC Patches, Ramana Radhakrishnan, Richard Earnshaw

> On Fri, May 08, 2015 at 01:09:52PM -0600, Jeff Law wrote:
> > On 05/08/2015 01:07 PM, David Edelsohn wrote:
> > >>>>Steve Ellcey wrote:
> > >>
> > >>After your change GCC sees that the code for f1 and f2 are identical
> > >>so it replaced the body of f2 with a call to f1.  This optimization will
> > >>save space but it is not going to be faster because any call to f2 will
> > >>now include an extra call/return.  Do other platforms have this same issue
> > >>or is there a way to make f2 an alias for f1 on other targets so no extra
> > >>call is needed?  I looked around to see if there was a target function or
> > >>macro that is used to make one function an alias of another but I didn't
> > >>see anything.
> > >
> > >This probably is not good for POWER, and probably not for ARM, in fact
> > >probably not good for most RISC architectures.
> > But isn't this code going to be creating aliases when the output format
> > supports them -- which avoids the call/return overheads?
> > 
> > Which might argue that if we don't have aliases, then ICF might need to be a
> > -Os thing.
> 
> ICF uses aliases only when possible (when it can prove that the callers
> don't care about function address equality/non-equality.  In other cases
> ICF uses caller redirection (if it is possible to redirect all callers and
> remove unused other call), or thunks (otherwise).
> 
> Thunks indeed can slow things down somewhat, especially if they can't tail
> call the function.

Yep, the idea here is that inliner should undo the splitting in most cases
where the hot path performance matters.
For GCC 6 we plan to work bit on this and try to chose thunks to point in right
direction.  It also may be possible to arrange backend to output those thunks
as simple nops just ahead of the target functions (and also to output thunks
there without the redundant jump instructions)

Honza
> 
> 	Jakub

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Question about patch for PR bootstrap/65150 (identical functions)
  2015-05-08 21:58     ` Jan Hubicka
@ 2015-05-08 22:56       ` Bernhard Reutner-Fischer
  0 siblings, 0 replies; 6+ messages in thread
From: Bernhard Reutner-Fischer @ 2015-05-08 22:56 UTC (permalink / raw)
  To: Jan Hubicka, Jakub Jelinek
  Cc: Jeff Law, David Edelsohn, Steve Ellcey, Martin Liška,
	GCC Patches, Ramana Radhakrishnan, Richard Earnshaw

On May 8, 2015 11:58:18 PM GMT+02:00, Jan Hubicka <hubicka@ucw.cz> wrote:
>> On Fri, May 08, 2015 at 01:09:52PM -0600, Jeff Law wrote:
>> > On 05/08/2015 01:07 PM, David Edelsohn wrote:
>> > >>>>Steve Ellcey wrote:
>> > >>
>> > >>After your change GCC sees that the code for f1 and f2 are
>identical
>> > >>so it replaced the body of f2 with a call to f1.  This
>optimization will
>> > >>save space but it is not going to be faster because any call to
>f2 will
>> > >>now include an extra call/return.  Do other platforms have this
>same issue
>> > >>or is there a way to make f2 an alias for f1 on other targets so
>no extra
>> > >>call is needed?  I looked around to see if there was a target
>function or
>> > >>macro that is used to make one function an alias of another but I
>didn't
>> > >>see anything.
>> > >
>> > >This probably is not good for POWER, and probably not for ARM, in
>fact
>> > >probably not good for most RISC architectures.
>> > But isn't this code going to be creating aliases when the output
>format
>> > supports them -- which avoids the call/return overheads?
>> > 
>> > Which might argue that if we don't have aliases, then ICF might
>need to be a
>> > -Os thing.
>> 
>> ICF uses aliases only when possible (when it can prove that the
>callers
>> don't care about function address equality/non-equality.  In other
>cases
>> ICF uses caller redirection (if it is possible to redirect all
>callers and
>> remove unused other call), or thunks (otherwise).
>> 
>> Thunks indeed can slow things down somewhat, especially if they can't
>tail
>> call the function.
>
>Yep, the idea here is that inliner should undo the splitting in most
>cases
>where the hot path performance matters.
>For GCC 6 we plan to work bit on this and try to chose thunks to point
>in right
>direction.  It also may be possible to arrange backend to output those
>thunks
>as simple nops just ahead of the target functions (and also to output
>thunks
>there without the redundant jump instructions)

... which will hopefully address https://gcc.gnu.org/PR65534

thanks,

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Question about patch for PR bootstrap/65150 (identical functions)
@ 2015-05-08 17:50 Steve Ellcey 
  0 siblings, 0 replies; 6+ messages in thread
From: Steve Ellcey  @ 2015-05-08 17:50 UTC (permalink / raw)
  To: mliska, hubicka, gcc-patches

Jan and Martin,

I just noticed that your patch for PR bootstrap/65150 broke one of the
MIPS tests (gcc.target/mips/branch-1.c).  I can fix the test with no
problem but I am wondering if the change I am seeing with your patch 
is intended or not.

A cutdown version of the test is:

void bar (void);
void f1 (int x) { if (x & 4) bar (); }
void f2 (int x) { if ((x >> 2) & 1) bar (); }

After your change GCC sees that the code for f1 and f2 are identical
so it replaced the body of f2 with a call to f1.  This optimization will
save space but it is not going to be faster because any call to f2 will
now include an extra call/return.  Do other platforms have this same issue
or is there a way to make f2 an alias for f1 on other targets so no extra
call is needed?  I looked around to see if there was a target function or
macro that is used to make one function an alias of another but I didn't
see anything.

Steve Ellcey
sellcey@imgtec.com

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2015-05-08 22:56 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-08 19:07 Question about patch for PR bootstrap/65150 (identical functions) David Edelsohn
2015-05-08 19:10 ` Jeff Law
2015-05-08 19:35   ` Jakub Jelinek
2015-05-08 21:58     ` Jan Hubicka
2015-05-08 22:56       ` Bernhard Reutner-Fischer
  -- strict thread matches above, loose matches on Subject: below --
2015-05-08 17:50 Steve Ellcey 

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).