Re: Predict register usage

Chris F Clark <>
Fri, 25 Apr 2008 23:36:26 -0400

          From comp.compilers

Related articles
Predict register usage (Tim Frink) (2008-04-25)
Re: Predict register usage (Chris F Clark) (2008-04-25)
Predict register usage (Inderaj Bains) (2008-04-26)
Re: Predict register usage (Sid Touati) (2008-04-28)
Re: Predict register usage (2008-05-02)
Re: Predict register usage (2008-05-02)
Re: Predict register usage (=?ISO-8859-1?Q?Bj=F6rn_Franke?=) (2008-05-09)
| List of all articles for this month |

From: Chris F Clark <>
Newsgroups: comp.compilers
Date: Fri, 25 Apr 2008 23:36:26 -0400
Organization: The World Public Access UNIX, Brookline, MA
References: 08-04-093
Keywords: registers, optimize
Posted-Date: 25 Apr 2008 23:57:00 EDT

Tim Frink <> writes:

> When the optimization inline extension is performed on a high-level
> intermediate representation or on a low-level IR before register
> allocation, the final result for the inlined code after the register
> allocation is not known. Thus, it might happen that due to the
> increased register pressure after inlining, spill code must be added
> heavily leading to a worse performance than before the
> optimization. Do you know of any approaches which try to predict the
> resulting spill code added by a register allocation when inlining is
> done for a particular function?

> My idea was that lifetime analyses might be used for that
> purpose. One could find out how many variables (in high-level) or
> register are life across a call. This is an indication for spill
> code candidates. Based on this one could develop some heuristics
> that omit inlining for functions that are supposed to add too much
> spilling. What do you think about this idea?

While this seems like it would be useful, to understand the tradeoff
you have to consider what happens if you don't inline the function and
in fact call the function.

If the variable is held in a caller-save register, then the caller
must spill the register before the call, thus you haven't saved
executing any spill code. Similarly, if the variable is held in a
callee-save register and the possibly-to-be-inlined function uses the
register, the function needs to save the register even if called and
no spill code has been saved.

The one calling (register based) convention that I'm aware of where
you might not need spill code by doing a call, is if the architecture
supports a rotating register window. In that case, the hardware
itself will take care of the spills.

Now, it wouldn't surprise me to learn of other calling conventions
where a call doesn't require spills, but caller and callee-save
registers are the most popular, and in both of those cases you won't
save spills by not inlining the call. In fact, when I was doing code
generator and optimizer work, it was often worth inlining the call
even if the only improvement was the elimination of superfluous spills
that the calling convention required.

Hope this helps,

Chris Clark Internet:
Compiler Resources, Inc. or:
23 Bailey Rd Web Site:
Berlin, MA 01503 voice: (508) 435-5016
USA fax: (978) 838-0263 (24 hours)

Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.