public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Make GCC move instructions between a multi-cycle instruction and the next instruction that depends on its result.
@ 2022-02-22 19:00 William Tambe
  2022-02-22 21:15 ` William Tambe
  0 siblings, 1 reply; 6+ messages in thread
From: William Tambe @ 2022-02-22 19:00 UTC (permalink / raw)
  To: gcc-help

In this CPU,

A multi-cycle instruction, once decoded, runs in parallel as other
decoded single/multi-cycle instructions.

A single/multi-cycle instruction takes two operands, where the first
operand receives the result
of computing both operands.

An example of multi-cycle instruction is "div".
An example of single-cycle instruction is "add".

GCC should be able to transform following:
````
add %0 %5
add %1 %6
div %4 %5 #<-- Multi-cycle instruction.
add %4 %7 #<-- Next instruction that depends on its result.
add %3 %7
add %2 %7
```
To:
```
div %4 %5 #<-- Multi-cycle instruction.
add %0 %5
add %1 %6
add %3 %7
add %2 %7
add %4 %7 #<-- Next instruction that depends on its result.
```
Without above transformation, `add %4 %7` would cause the cpu to wait
on `div %4 %5` when it could have executed instructions that do not
depend on the result of "div".

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

* Re: Make GCC move instructions between a multi-cycle instruction and the next instruction that depends on its result.
  2022-02-22 19:00 Make GCC move instructions between a multi-cycle instruction and the next instruction that depends on its result William Tambe
@ 2022-02-22 21:15 ` William Tambe
  2022-02-23  0:22   ` Segher Boessenkool
  0 siblings, 1 reply; 6+ messages in thread
From: William Tambe @ 2022-02-22 21:15 UTC (permalink / raw)
  To: gcc-help

On Tue, Feb 22, 2022 at 1:00 PM William Tambe <tambewilliam@gmail.com> wrote:
>
> In this CPU,
>
> A multi-cycle instruction, once decoded, runs in parallel as other
> decoded single/multi-cycle instructions.
>
> A single/multi-cycle instruction takes two operands, where the first
> operand receives the result
> of computing both operands.
>
> An example of multi-cycle instruction is "div".
> An example of single-cycle instruction is "add".
>
> GCC should be able to transform following:
> ````
> add %0 %5
> add %1 %6
> div %4 %5 #<-- Multi-cycle instruction.
> add %4 %7 #<-- Next instruction that depends on its result.
> add %3 %7
> add %2 %7
> ```
> To:
> ```
> div %4 %5 #<-- Multi-cycle instruction.
> add %0 %5
> add %1 %6
> add %3 %7
> add %2 %7
> add %4 %7 #<-- Next instruction that depends on its result.
> ```
> Without above transformation, `add %4 %7` would cause the cpu to wait
> on `div %4 %5` when it could have executed instructions that do not
> depend on the result of "div".

How to implement above transformation such that GCC moves instructions
between a multi-cycle instruction and the next instruction that
depends on its result ?

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

* Re: Make GCC move instructions between a multi-cycle instruction and the next instruction that depends on its result.
  2022-02-22 21:15 ` William Tambe
@ 2022-02-23  0:22   ` Segher Boessenkool
  2022-02-23  0:51     ` William Tambe
  2022-02-23  7:25     ` AW: " stefan
  0 siblings, 2 replies; 6+ messages in thread
From: Segher Boessenkool @ 2022-02-23  0:22 UTC (permalink / raw)
  To: William Tambe; +Cc: gcc-help

On Tue, Feb 22, 2022 at 03:15:55PM -0600, William Tambe via Gcc-help wrote:
[snip]
> > Without above transformation, `add %4 %7` would cause the cpu to wait
> > on `div %4 %5` when it could have executed instructions that do not
> > depend on the result of "div".
> 
> How to implement above transformation such that GCC moves instructions
> between a multi-cycle instruction and the next instruction that
> depends on its result ?

GCC has a pretty advanced instruction scheduler.  You can start looking
at <https://gcc.gnu.org/onlinedocs/gccint/Scheduling.html> for example?


Segher

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

* Re: Make GCC move instructions between a multi-cycle instruction and the next instruction that depends on its result.
  2022-02-23  0:22   ` Segher Boessenkool
@ 2022-02-23  0:51     ` William Tambe
  2022-02-23  7:25     ` AW: " stefan
  1 sibling, 0 replies; 6+ messages in thread
From: William Tambe @ 2022-02-23  0:51 UTC (permalink / raw)
  To: Segher Boessenkool; +Cc: gcc-help

On Tue, Feb 22, 2022 at 6:24 PM Segher Boessenkool
<segher@kernel.crashing.org> wrote:
>
> On Tue, Feb 22, 2022 at 03:15:55PM -0600, William Tambe via Gcc-help wrote:
> [snip]
> > > Without above transformation, `add %4 %7` would cause the cpu to wait
> > > on `div %4 %5` when it could have executed instructions that do not
> > > depend on the result of "div".
> >
> > How to implement above transformation such that GCC moves instructions
> > between a multi-cycle instruction and the next instruction that
> > depends on its result ?
>
> GCC has a pretty advanced instruction scheduler.  You can start looking
> at <https://gcc.gnu.org/onlinedocs/gccint/Scheduling.html> for example?
>

Thank you for the pointer; could you suggest an existing example close
to what I am looking to implement that uses above TARGET_SCHED_* hooks
?

>
> Segher

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

* AW: Make GCC move instructions between a multi-cycle instruction and the next instruction that depends on its result.
  2022-02-23  0:22   ` Segher Boessenkool
  2022-02-23  0:51     ` William Tambe
@ 2022-02-23  7:25     ` stefan
  2022-02-23 15:07       ` William Tambe
  1 sibling, 1 reply; 6+ messages in thread
From: stefan @ 2022-02-23  7:25 UTC (permalink / raw)
  To: 'gcc-help'

> -----Ursprüngliche Nachricht-----
> Von: Gcc-help <gcc-help-bounces+bebbo=bejy.net@gcc.gnu.org> Im
> Auftrag von Segher Boessenkool
> Gesendet: Mittwoch, 23. Februar 2022 01:23
> An: William Tambe <tambewilliam@gmail.com>
> Cc: gcc-help <gcc-help@gcc.gnu.org>
> Betreff: Re: Make GCC move instructions between a multi-cycle instruction
> and the next instruction that depends on its result.
> 
> On Tue, Feb 22, 2022 at 03:15:55PM -0600, William Tambe via Gcc-help
> wrote:
> [snip]
> > > Without above transformation, `add %4 %7` would cause the cpu to
> > > wait on `div %4 %5` when it could have executed instructions that do
> > > not depend on the result of "div".
> >
> > How to implement above transformation such that GCC moves instructions
> > between a multi-cycle instruction and the next instruction that
> > depends on its result ?
> 
> GCC has a pretty advanced instruction scheduler.  You can start looking at
> <https://gcc.gnu.org/onlinedocs/gccint/Scheduling.html> for example?
> 

You should also look at the md files defining an automaton -->
"define_automaton". 

There you model the pipelines, latency etc.p.p. for the cpu. 
Then annotate the insns in the cpu md file with the types from the
automaton.
That information can be used by the scheduler and you may still need to
implement some of the scheduler hooks.

Start looking at a simple cpu.

Stefan


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

* Re: Make GCC move instructions between a multi-cycle instruction and the next instruction that depends on its result.
  2022-02-23  7:25     ` AW: " stefan
@ 2022-02-23 15:07       ` William Tambe
  0 siblings, 0 replies; 6+ messages in thread
From: William Tambe @ 2022-02-23 15:07 UTC (permalink / raw)
  To: Stefan Franke; +Cc: gcc-help

On Wed, Feb 23, 2022 at 1:26 AM <stefan@franke.ms> wrote:
>
> > -----Ursprüngliche Nachricht-----
> > Von: Gcc-help <gcc-help-bounces+bebbo=bejy.net@gcc.gnu.org> Im
> > Auftrag von Segher Boessenkool
> > Gesendet: Mittwoch, 23. Februar 2022 01:23
> > An: William Tambe <tambewilliam@gmail.com>
> > Cc: gcc-help <gcc-help@gcc.gnu.org>
> > Betreff: Re: Make GCC move instructions between a multi-cycle instruction
> > and the next instruction that depends on its result.
> >
> > On Tue, Feb 22, 2022 at 03:15:55PM -0600, William Tambe via Gcc-help
> > wrote:
> > [snip]
> > > > Without above transformation, `add %4 %7` would cause the cpu to
> > > > wait on `div %4 %5` when it could have executed instructions that do
> > > > not depend on the result of "div".
> > >
> > > How to implement above transformation such that GCC moves instructions
> > > between a multi-cycle instruction and the next instruction that
> > > depends on its result ?
> >
> > GCC has a pretty advanced instruction scheduler.  You can start looking at
> > <https://gcc.gnu.org/onlinedocs/gccint/Scheduling.html> for example?
> >
>
> You should also look at the md files defining an automaton -->
> "define_automaton".
>
> There you model the pipelines, latency etc.p.p. for the cpu.
> Then annotate the insns in the cpu md file with the types from the
> automaton.
> That information can be used by the scheduler and you may still need to
> implement some of the scheduler hooks.
>
> Start looking at a simple cpu.
>

Would it be possible and safe to accomplish above transformation using
TARGET_MACHINE_DEPENDENT_REORG ? If yes, what functions can be used to
move an instruction ?

> Stefan
>

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

end of thread, other threads:[~2022-02-23 15:07 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-22 19:00 Make GCC move instructions between a multi-cycle instruction and the next instruction that depends on its result William Tambe
2022-02-22 21:15 ` William Tambe
2022-02-23  0:22   ` Segher Boessenkool
2022-02-23  0:51     ` William Tambe
2022-02-23  7:25     ` AW: " stefan
2022-02-23 15:07       ` William Tambe

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