-O0 nearly twice as fast to build as -O2

Pavel Troller patrol at sinus.cz
Fri Jun 13 01:08:08 CDT 2008

> Pavel Troller wrote:
> >> OK, this was confusing.  I was getting repeatable five minute
> >> builds, i.e. "make clean; reboot; time make -j3" (more or less :-)
> >> was reliably showing five minutes wall clock time.
> >>
> >> Then I did "make distclean; ./configure; make depend".
> >>
> >> After that, I got repeatable nine minute builds, i.e.
> >> make clean; reboot; time make -j3
> >> was showing nine minute wall clock time.
> >>
> >> Turns out, the difference was... I had been building without
> >> optimization.  So configuring with CFLAGS="-g -O0" is
> >> almost a 2x speedup!
> >>
> > Hi!
> >   Yes, you are right, turning optimization off speeds up the compilation
> > substantially.
> >   HOWEVER, it changes the generated code and due to various features of the
> > compiler (like inlining or another) being present/absent, the code can,
> > in rare cases, behave differently. I have many experiences that for example
> > a program was repeatedly crashing, when compiled by default way, i.e. with
> > optimalization, and when I compiled it without optimalization and with -g
> > for debugging, it never crashed and worked perfectly under the debugger.
> > I had to debug the optimized version, which is harder, because the generated
> > code doesn't track the source exactly anymore.
> >   With regards, Pavel Troller
> > 
> > 
> Is that a GCC bug then?  And, more importantly, was that with a recent
> GCC version?
 It cannot be clearly said. Some nuances of the C language are "implementation
dependent" and it's perfectly OK to compile them differently with or without
optimization. Sometimes the programmer incorrectly relies on such a nuance and
then using the different set of options can cause his program to behave
incorrectly. However, yes, there were, and maybe still are, GCC bugs regarding
optimisation, but in recent versions they are very rare.
  And my experiences mentioned above don't count only for wine, there are many
other programs, which do this.
  With regards, Pavel Troller

More information about the wine-devel mailing list