public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Backend port: Minimizing register usage in favor of memory accesses
@ 2004-03-30 17:48 xyzzy
  2004-03-31  1:43 ` Joern Rennecke
  2004-03-31  1:48 ` Jim Wilson
  0 siblings, 2 replies; 8+ messages in thread
From: xyzzy @ 2004-03-30 17:48 UTC (permalink / raw)
  To: GCC list

I understand that one of the goals of any optimizing compiler is to maximize 
use of registers since this is the fastest and least space consuming type of 
instruction on most processors.

Thus, C code like:

extern void bar();
int a,b;
foo()
{
	a = 5;
	if ( b > a )
		bar();
}

... produces pseudo-code like:
.word a,b
	move 5,tmp1reg
	move tmp1reg,a

	move b,tmp2reg
	cmp tmp2reg,tmp1reg
	bgt label1
	call bar
label1:
	ret

What I want to do is reverse this and minimize register usage as much as 
possible, massively favoring memory accesses unless a register absolutely 
MUST be used.  Thus, I want my backend to produce code like this:

.word a,b
	move 5,a
	cmp b,a
	bgt label1
	call bar
label1:
	ret

Is there any way to force the GCC backend to do this, if at all?  Will 
defining SMALL_REGISTER_CLASSES to 1 do the trick or is there any other magic 
that can be invoked?  Doing it in the optimizer stage is OK, too... if O2 or 
less.

Many thanks for any help on this.

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

* Re: Backend port: Minimizing register usage in favor of memory accesses
  2004-03-30 17:48 Backend port: Minimizing register usage in favor of memory accesses xyzzy
@ 2004-03-31  1:43 ` Joern Rennecke
  2004-03-31  1:48 ` Jim Wilson
  1 sibling, 0 replies; 8+ messages in thread
From: Joern Rennecke @ 2004-03-31  1:43 UTC (permalink / raw)
  To: xyzzy; +Cc: GCC list

> What I want to do is reverse this and minimize register usage as much as 
> possible, massively favoring memory accesses unless a register absolutely 
> MUST be used.  Thus, I want my backend to produce code like this:

Try lowering MEMORY_MOVE_COST.

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

* Re: Backend port: Minimizing register usage in favor of memory accesses
  2004-03-30 17:48 Backend port: Minimizing register usage in favor of memory accesses xyzzy
  2004-03-31  1:43 ` Joern Rennecke
@ 2004-03-31  1:48 ` Jim Wilson
  2004-03-31 12:23   ` xyzzy
  2004-03-31 12:53   ` Richard Earnshaw
  1 sibling, 2 replies; 8+ messages in thread
From: Jim Wilson @ 2004-03-31  1:48 UTC (permalink / raw)
  To: xyzzy; +Cc: gcc

xyzzy@hotpop.com wrote:
> I understand that one of the goals of any optimizing compiler is to maximize 
> use of registers since this is the fastest and least space consuming type of 
> instruction on most processors.

The goal of an optimizing compiler is to produce the fastest code for 
the target.  If the target wants registers to be used, then we use 
registers.  If the target doesn't want registers to be used, then we 
don't use registers.

> Is there any way to force the GCC backend to do this, if at all?

We have been doing this since the beginning for an i386 target.
-- 
Jim Wilson, GNU Tools Support, http://www.SpecifixInc.com

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

* Re: Backend port: Minimizing register usage in favor of memory accesses
  2004-03-31  1:48 ` Jim Wilson
@ 2004-03-31 12:23   ` xyzzy
  2004-04-01 19:48     ` Jim Wilson
  2004-03-31 12:53   ` Richard Earnshaw
  1 sibling, 1 reply; 8+ messages in thread
From: xyzzy @ 2004-03-31 12:23 UTC (permalink / raw)
  To: gcc; +Cc: Jim Wilson

On Tuesday 30 March 2004 22:31, Jim Wilson wrote:
> xyzzy@hotpop.com wrote:
> > I understand that one of the goals of any optimizing compiler is to
> > maximize use of registers since this is the fastest and least space
> > consuming type of instruction on most processors.
>
> The goal of an optimizing compiler is to produce the fastest code for
> the target.  If the target wants registers to be used, then we use
> registers.  If the target doesn't want registers to be used, then we
> don't use registers.
>
> > Is there any way to force the GCC backend to do this, if at all?
>
> We have been doing this since the beginning for an i386 target.

Jim, thanks for the reply... Also, thanks to Joem.

Can you point me in the right place to look in the i386 target so I don't mess 
this up?  Is what Joem said about "lowering MEMORY_MOVE_COST" the only thing 
to do? Is there other black magic involved?

Thanks again.

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

* Re: Backend port: Minimizing register usage in favor of memory  accesses
  2004-03-31  1:48 ` Jim Wilson
  2004-03-31 12:23   ` xyzzy
@ 2004-03-31 12:53   ` Richard Earnshaw
  2004-03-31 13:05     ` xyzzy
  2004-03-31 13:49     ` Robert Dewar
  1 sibling, 2 replies; 8+ messages in thread
From: Richard Earnshaw @ 2004-03-31 12:53 UTC (permalink / raw)
  To: Jim Wilson; +Cc: xyzzy, gcc, Richard Earnshaw


> The goal of an optimizing compiler is to produce the fastest code for 
> the target.

Not necessarily.  The goal of an optimizing compiler is to minimize some 
cost metric.  Sometimes that cost metric is the same as 'target execution 
time' at other times it is something else, such as 'code size'.  Many of 
the specific optimizations performed will be same regardless of the 
overall cost metric being worked on; but not always.

R.

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

* Re: Backend port: Minimizing register usage in favor of memory accesses
  2004-03-31 12:53   ` Richard Earnshaw
@ 2004-03-31 13:05     ` xyzzy
  2004-03-31 13:49     ` Robert Dewar
  1 sibling, 0 replies; 8+ messages in thread
From: xyzzy @ 2004-03-31 13:05 UTC (permalink / raw)
  To: GCC list, Richard Earnshaw

On Wednesday 31 March 2004 11:43, Richard Earnshaw wrote:
> > The goal of an optimizing compiler is to produce the fastest code for
> > the target.
>
> Not necessarily.  The goal of an optimizing compiler is to minimize some
> cost metric.  Sometimes that cost metric is the same as 'target execution
> time' at other times it is something else, such as 'code size'.  Many of
> the specific optimizations performed will be same regardless of the
> overall cost metric being worked on; but not always.
>
> R.
Yes, my mistake... I meant to say "the BEST code for the target", which is 
horribly subjective.

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

* Re: Backend port: Minimizing register usage in favor of memory  accesses
  2004-03-31 12:53   ` Richard Earnshaw
  2004-03-31 13:05     ` xyzzy
@ 2004-03-31 13:49     ` Robert Dewar
  1 sibling, 0 replies; 8+ messages in thread
From: Robert Dewar @ 2004-03-31 13:49 UTC (permalink / raw)
  To: Richard Earnshaw; +Cc: Jim Wilson, xyzzy, gcc

Richard Earnshaw wrote:

> Not necessarily.  The goal of an optimizing compiler is to minimize some 
> cost metric.  Sometimes that cost metric is the same as 'target execution 
> time' at other times it is something else, such as 'code size'

Or data size. In some embedded environments, data size and code size
are radically different metrics. The latter may be in ROM and quite
large, the former may be very limited RAM.

While minimizing code space is often closely related to minimizing
execution time of code, minimizing data space is actually sometimes 
quite at odds with minimizing time.

For interesting details on some optimizations
for reducing space, see Janet Fabri's thesis on Automatic
Storage Optimization, NYU, R. Dewar advisor, 1982 (also published as
Fabri, Janet. Automatic Storage Optimization. UMI Research Press, 1982.)
Unfortunately this thesis does not seem to be online anywhere that
I can find. One day it would be nice if all University Microfilms
material made it onto the web!


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

* Re: Backend port: Minimizing register usage in favor of memory accesses
  2004-03-31 12:23   ` xyzzy
@ 2004-04-01 19:48     ` Jim Wilson
  0 siblings, 0 replies; 8+ messages in thread
From: Jim Wilson @ 2004-04-01 19:48 UTC (permalink / raw)
  To: xyzzy; +Cc: gcc

xyzzy@hotpop.com wrote:
> Can you point me in the right place to look in the i386 target so I don't mess 
> this up?  Is what Joem said about "lowering MEMORY_MOVE_COST" the only thing 
> to do? Is there other black magic involved?

If your target has patterns that allow MEMs, then gcc will use them. 
Since some gcc optimizations (like combine) try to reduce the total 
number of instructions, you will naturally get code that uses MEM in 
preference to REG.

You shouldn't really need to do anything else to get started.  There are 
other things that you can do to fine tune the result and address 
specific problems, such as setting MEMORY_MOVE_COST.  However, since you 
haven't reported any specific problems, I can't offer any specific 
suggestions.
-- 
Jim Wilson, GNU Tools Support, http://www.SpecifixInc.com

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

end of thread, other threads:[~2004-04-01 19:48 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-03-30 17:48 Backend port: Minimizing register usage in favor of memory accesses xyzzy
2004-03-31  1:43 ` Joern Rennecke
2004-03-31  1:48 ` Jim Wilson
2004-03-31 12:23   ` xyzzy
2004-04-01 19:48     ` Jim Wilson
2004-03-31 12:53   ` Richard Earnshaw
2004-03-31 13:05     ` xyzzy
2004-03-31 13:49     ` Robert Dewar

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