public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* peephole optimizations
@ 2010-05-03 12:46 roy rosen
  2010-05-03 20:06 ` Ian Lance Taylor
  0 siblings, 1 reply; 5+ messages in thread
From: roy rosen @ 2010-05-03 12:46 UTC (permalink / raw)
  To: gcc

Hi All,

I have tried to write some peephole patterns and I now have some
questions regarding the way it is working.

1. Is that true that if I try to match in the pattern two insns and in
my code between these insns there is another insn which does not have
any dependency connection to the other two, Is that true that the
peephole would not match in this case? (i.e. the insns to match must
come in the code in sequential order with no other insns between
them)?

2. I saw that the peephole2 pass is done after IRA. Many peepholes are
practically useless after register allocating.
Is it possible to run it before IRA? Is it possible to run it several times?

Thanks, Roy.

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

* Re: peephole optimizations
  2010-05-03 12:46 peephole optimizations roy rosen
@ 2010-05-03 20:06 ` Ian Lance Taylor
  2010-05-04  7:18   ` roy rosen
  0 siblings, 1 reply; 5+ messages in thread
From: Ian Lance Taylor @ 2010-05-03 20:06 UTC (permalink / raw)
  To: roy rosen; +Cc: gcc

roy rosen <roy.1rosen@gmail.com> writes:

> 1. Is that true that if I try to match in the pattern two insns and in
> my code between these insns there is another insn which does not have
> any dependency connection to the other two, Is that true that the
> peephole would not match in this case? (i.e. the insns to match must
> come in the code in sequential order with no other insns between
> them)?

Yes.


> 2. I saw that the peephole2 pass is done after IRA. Many peepholes are
> practically useless after register allocating.
> Is it possible to run it before IRA? Is it possible to run it several times?

There are also many peepholes can not be run before register
allocation, because they depend on relationships between the
registers.

Before register allocation, you should normally write an insn pattern
which can be recognized by the combine pass, rather than writing a
peephole.  To do this, write a define_insn as usual, and use
appropriate operand and insn predicates to recognize the pattern you
are looking for.

That has the advantage that it works even if random insns appear in
between the insns you care about, the case you ask about in your first
question.  (However, it does not work across block boundaries.)

Ian

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

* Re: peephole optimizations
  2010-05-03 20:06 ` Ian Lance Taylor
@ 2010-05-04  7:18   ` roy rosen
  2010-05-04  7:37     ` Ian Lance Taylor
  2010-05-04 15:49     ` Jeff Law
  0 siblings, 2 replies; 5+ messages in thread
From: roy rosen @ 2010-05-04  7:18 UTC (permalink / raw)
  To: Ian Lance Taylor; +Cc: gcc

Hi,

2010/5/3, Ian Lance Taylor <iant@google.com>:
> roy rosen <roy.1rosen@gmail.com> writes:
>
> > 1. Is that true that if I try to match in the pattern two insns and in
> > my code between these insns there is another insn which does not have
> > any dependency connection to the other two, Is that true that the
> > peephole would not match in this case? (i.e. the insns to match must
> > come in the code in sequential order with no other insns between
> > them)?
>
> Yes.
>

Was there any special problem implementing such peephole mechanism or
simply nobody tried to work on this yet?

I think it may be very beneficial since I guess that for most
patterns, there are other insns between the pattern's insns which
cause the peephole not to match...

>
> > 2. I saw that the peephole2 pass is done after IRA. Many peepholes are
> > practically useless after register allocating.
> > Is it possible to run it before IRA? Is it possible to run it several times?
>
> There are also many peepholes can not be run before register
> allocation, because they depend on relationships between the
> registers.
>
> Before register allocation, you should normally write an insn pattern
> which can be recognized by the combine pass, rather than writing a
> peephole.  To do this, write a define_insn as usual, and use
> appropriate operand and insn predicates to recognize the pattern you
> are looking for.
>
> That has the advantage that it works even if random insns appear in
> between the insns you care about, the case you ask about in your first
> question.  (However, it does not work across block boundaries.)
>
> Ian
>

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

* Re: peephole optimizations
  2010-05-04  7:18   ` roy rosen
@ 2010-05-04  7:37     ` Ian Lance Taylor
  2010-05-04 15:49     ` Jeff Law
  1 sibling, 0 replies; 5+ messages in thread
From: Ian Lance Taylor @ 2010-05-04  7:37 UTC (permalink / raw)
  To: roy rosen; +Cc: gcc

roy rosen <roy.1rosen@gmail.com> writes:

> 2010/5/3, Ian Lance Taylor <iant@google.com>:
>> roy rosen <roy.1rosen@gmail.com> writes:
>>
>> > 1. Is that true that if I try to match in the pattern two insns and in
>> > my code between these insns there is another insn which does not have
>> > any dependency connection to the other two, Is that true that the
>> > peephole would not match in this case? (i.e. the insns to match must
>> > come in the code in sequential order with no other insns between
>> > them)?
>>
>> Yes.
>>
>
> Was there any special problem implementing such peephole mechanism or
> simply nobody tried to work on this yet?

It would have to be very conservative about whether the intervening
instructions affected the instructions being optimized.  I don't think
there is any special problem other than that.

The compiler doesn't rely on peepholes that much, since most of that
sort of thing is done in the combine pass.  The peepholes are mostly
used to optimize the output of the register allocator.  As such, the
instructions tend to be sequential anyhow.  Before starting a project
to permit skipping instructions in the middle of peepholes, I think it
would be useful to analyze some .s files and see how often the
peephole could be applied.

Ian

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

* Re: peephole optimizations
  2010-05-04  7:18   ` roy rosen
  2010-05-04  7:37     ` Ian Lance Taylor
@ 2010-05-04 15:49     ` Jeff Law
  1 sibling, 0 replies; 5+ messages in thread
From: Jeff Law @ 2010-05-04 15:49 UTC (permalink / raw)
  To: roy rosen; +Cc: Ian Lance Taylor, gcc

On 05/04/10 01:18, roy rosen wrote:
> Hi,
>
> 2010/5/3, Ian Lance Taylor<iant@google.com>:
>    
>> roy rosen<roy.1rosen@gmail.com>  writes:
>>
>>      
>>> 1. Is that true that if I try to match in the pattern two insns and in
>>> my code between these insns there is another insn which does not have
>>> any dependency connection to the other two, Is that true that the
>>> peephole would not match in this case? (i.e. the insns to match must
>>> come in the code in sequential order with no other insns between
>>> them)?
>>>        
>> Yes.
>>
>>      
> Was there any special problem implementing such peephole mechanism or
> simply nobody tried to work on this yet?
>
> I think it may be very beneficial since I guess that for most
> patterns, there are other insns between the pattern's insns which
> cause the peephole not to match...
>    
In general, peepholes (in the GCC world) are typically only used when 
there is no obvious data dependency between insns and thus the combiner 
phase of GCC doesn't know to try and optimize the two (or three) 
insns.    It has been our experience that peepholes are only 
occasionally useful and thus we haven't spent considerable time 
improving the infrastructure for the peephole optimizer.

Jeff

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

end of thread, other threads:[~2010-05-04 15:49 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-05-03 12:46 peephole optimizations roy rosen
2010-05-03 20:06 ` Ian Lance Taylor
2010-05-04  7:18   ` roy rosen
2010-05-04  7:37     ` Ian Lance Taylor
2010-05-04 15:49     ` Jeff Law

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