Re: Is global optimization worth it? (Nick Maclaren)
30 Jan 2002 20:42:43 -0500

          From comp.compilers

Related articles
[3 earlier articles]
Re: Is global optimization worth it? (Gary Oblock) (2001-12-20)
Re: Is global optimization worth it? (Lex Spoon) (2001-12-20)
Re: Is global optimization worth it? (2002-01-24)
Re: Is global optimization worth it? (2002-01-24)
Re: Is global optimization worth it? (2002-01-24)
Re: Is global optimization worth it? (Rinie Kervel) (2002-01-28)
Re: Is global optimization worth it? (2002-01-30)
Re: Is global optimization worth it? (Rinie Kervel) (2002-02-06)
| List of all articles for this month |

From: (Nick Maclaren)
Newsgroups: comp.compilers
Date: 30 Jan 2002 20:42:43 -0500
Organization: University of Cambridge, England
References: 01-12-069 01-12-116 02-01-097 02-01-146
Keywords: optimize
Posted-Date: 30 Jan 2002 20:42:43 EST

Rinie Kervel <> wrote:
>Lance wrote:
>> Actually, thats why I'm here. I have a compiler working, and the
>>code it generates makes me cringe. But it works. So I did some
>>research, and it turns out my compiler is a "naive" compiler. I need
>>to recode the code generator so that it generates machine code the
>>way I do: select instructions leading towards what I want, allocate
>>registers (OK - I know, thats obvious - in hindsight) For now my goal
>>is "simple" - the compiler should generate code that doesn't make me
>>cringe. I am an experienced C/assembly (embedded systems) coder, so
>>that will take some doing :( At this point, I've done enough research
>>to know what I'm letting myself in for.
>I see the other posters jumping directly to alias analysis, which
>poses some theoretical restrictions on C optimisations. I donīt know
>if this is actually a severe restriction in real life programs: many C
>programs don't use floating point at all. So I think you can start
>with some real gains as using as many registers as you can, avoiding
>frame pointers, passing parameters in registers, strcpy inlining etc,
>accessing globals by offset of a previous global etc.

It has nothing to do with floating-point - precisely the same things
apply to codes without any. It has to do with the nature of C.

You can get away without using global optimisation in a language where
encapsulation is automatic and tight. In such a case, you can do a
lot of the optimisations that you are talking about (and more) quite
safely. In C, you cannot, because of the aliasing problems - hence
the need for global optimisation to detect such aliasing.

Even larger gains on modern systems come from things like operand
preloading, but let's consider just register use. It isn't unusual
for a C code not to be able to make use of more than a few registers
because everything has to be in memory over every function call.
Global optimisation can remove most of that constraint, and allow the
use of (say) 20 registers where only 4 could be used before.

Nick Maclaren,
University of Cambridge Computing Service,
New Museums Site, Pembroke Street, Cambridge CB2 3QH, England.
Tel.: +44 1223 334761 Fax: +44 1223 334679

Post a followup to this message

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