Boost logo

Boost-Build :

From: Chris Fairles (chris.fairles_at_[hidden])
Date: 2007-07-11 15:51:28


Just so we're clear, here's the descriptions of the extra
optimizations -O3 turns on.

-funswitch-loops
    Move branches with loop invariant conditions out of the loop, with
duplicates of the loop on both branches (modified according to result
of the condition).

So, for example:

for i = 0 ... 100
  if (a > 0) f(i);
  else g(i);
end for

can become:

if (a > 0)
  for i = 0..100
    f(i)
  end for
else
  for i = 0..100
    g(i)
  end for
end if

It doubles code which can be an issue for embedded platforms but
hopefully they're using -Os anyway. I can't conjure up a scenario
where this might cause code to run slower.

-finline-functions
    Integrate all simple functions into their callers. The compiler
heuristically decides which functions are simple enough to be worth
integrating in this way. If all calls to a given function are
integrated, and the function is declared static, then the function is
normally not output as assembler code in its own right.

Dependant on the hueristics of the compiler but inlining is not always
best for some functions. I think this has the greatest potential for
not being "safe" and/or slowing down code as opposed to making it
faster. See:
http://www.new-brunswick.net/workshop/c++/faq/inline-functions.html#faq-9.3

I

-fgcse-after-reload
    When -fgcse-after-reload is enabled, a redundant load elimination
pass is performed after reload. The purpose of this pass is to cleanup
redundant spilling.

Not clear what issues can arise with this one.

I as well opt for -O2 99% of the time and use a workaround (cxxflags)
to force -O2.

Chris

On 7/11/07, Jos Hickson <jos.hickson_at_[hidden]> wrote:
> I've trawled the GCC mailing list and found the following from 01/2007:
>
> <quote>
> Andreas Bogk <andreas_at_[hidden]> writes:
>
> > Then maybe it shouldn't be the default in autoconf. But wasn't -O3 the
> > set of optimizations considered potentially unsafe?
>
> No. -O3 is a set of optimizations which are useful for many program
> but which will cause a substantial number of programs to run slower.
> -O2 is a set of optimizations which we believe will make (almost) all
> programs run faster. -O1 also makes (almost) all programs run faster.
> The difference between -O1 and -O2 is that it takes longer to run the
> compiler with -O2.
>
> gcc never enables unsafe optimizations except by explicit request via
> -f options (e.g., -ffast-math), where "unsafe" is defined as
> "violating the language standard."
> </quote>
>
> This is from http://gcc.gnu.org/ml/gcc/2007-01/msg01095.html. So, I
> am mistaken in my belief and apologies for that. However, here we
> have had problems with the inlining turned on by O3 even in a very
> simple program that I don't have to hand right now though this
> particular problem at least may well be a GCC bug, we're not sure yet.
>
> However, it is interesting to note that the author of the response
> above says that -O3 "will cause a substantial number of programs to
> run slower." How "official" this statement is, I don't know.
>
> Regards,
>
> Jos
>
>
>
>
>
>
> On 11/07/07, Dean Michael Berris <mikhailberis_at_[hidden]> wrote:
> > On 7/11/07, Jos Hickson <jos.hickson_at_[hidden]> wrote:
> > > [snip]
> > > >
> > > > > One thing I was wonder was why -O3 is the default as that is usually
> > > > > considered a bit risky?
> > > >
> > > > Is it? I'm not aware of that.
> > > >
> > >
> > > To quote from the Gentoo Linux "Safe CFLAGS" page
> > > (http://gentoo-wiki.com/Safe_Cflags) as an example:
> > >
> > > <quote>
> > > Note that -O2 is regarded as safer than "-O3", and "-O3" can often be
> > > a counter-productive attempt at optimization.
> > > </quote>
> > >
> >
> > Any particular reason why this would be the case? How is "safety"
> > defined in this manner? Does conservative optimization mean safer?
> >
> > --
> > Dean Michael C. Berris
> > http://cplusplus-soup.blogspot.com/
> > mikhailberis AT gmail DOT com
> > +63 928 7291459
> > _______________________________________________
> > Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost-build
> >
> _______________________________________________
> Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost-build
>


Boost-Build list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk