Re: Short-circuiting the optimizer




In article <ao2lm3-c7m.ln1@xxxxxxxxxxxxxxxxxxxxxxx>,
Terje Mathisen <terje.mathisen@xxxxxxxxxxxxx> writes:
|> glen herrmannsfeldt wrote:
|> > Nick Maclaren wrote:
|> >
|> > (snip on fooling optimizers)
|> >
|> >> See my remark about global optimisation. What you are saying is that you
|> >> can produce code too complicated for the compiler to analyse. True. You
|> >> can - for any finite, fixed set of compilers. But, for every contortion
|> >> you go through, I could write a compiler that could recognise it.
|> >
|> >> This is the same problem as military intelligence, (deterministic) game
|> >> theory, security analysis and so on. If one side puts more or higher
|> >> quality resources into it than the other, it will usually win.
|> >
|> > Say one calls an external function that hasn't been written yet.
|> > Without a crystal ball, the compiler is going to have a hard
|> > time inlining that function. For systems that support linking
|> > of separately compiled functions, this should always work.

Nope :-) As Terje points out, that is true only if you have a guaranteed
dumb linker. Several current systems call fancy optimisers from their
linkers.

|> It does, as long as that external function is (or will be) written in a
|> language that cannot be analyzed by the compiler/linker, i.e. a
|> separately compiled function consisting of inline asm code is sufficient
|> for all compilers I've ever seen or expect to see.

I have a one word counter-example: ANDF.


Regards,
Nick Maclaren.
.



Relevant Pages

  • Re: framework & speed
    ... > like PHP. ... There are several optimizers for php. ... life applications they needed quite some compiler tuning. ... Now those Java people say that Java can be better ...
    (comp.lang.php)
  • Re: Interesting article by Randall Hyde
    ... > Compiler optimizers alternately amaze me and confound me. ... points to _or_ the pointer itself to point somewhere else. ... > length outside the loop, shove that value in a variable, and use that ...
    (comp.lang.asm.x86)
  • Re: Summarize array with respect to values in another...
    ... I'd agree with Glenn here. ... A sufficiently smart compiler might be able ... wouldn't bet on whether any particular compiler does or not. ... time trying to out-guess optimizers. ...
    (comp.lang.fortran)
  • Re: Interesting article by Randall Hyde
    ... Compiler construction is very much an ... Compiler optimizers alternately amaze me and confound me. ... length outside the loop, shove that value in a variable, and use that ... you can get some *very* good machine code output. ...
    (comp.lang.asm.x86)
  • Re: Short-circuiting the optimizer
    ... can produce code too complicated for the compiler to analyse. ... I could write a compiler that could recognise it. ... of separately compiled functions, this should always work. ... It does, as long as that external function is written in a language that cannot be analyzed by the compiler/linker, i.e. a separately compiled function consisting of inline asm code is sufficient for all compilers I've ever seen or expect to see. ...
    (comp.arch.arithmetic)