GCC - Optimal Optimization

Nikolas Britton nikolas.britton at gmail.com
Sat Aug 19 02:40:26 UTC 2006

On 8/18/06, Sean M. <sigma_zk at yahoo.com> wrote:
> --- Oliver Fromme <olli at lurza.secnetix.de> wrote:
> > The default is "-O2 -fno-strict-aliasing -pipe".
> info gcc --index "optimize options" says the default is '-O0'.

That's true for stock GCC but FreeBSD (6.x) CFLAGS, COPTFLAGS, and
CXXFLAGS defaults to "-O2 -fno-strict-aliasing -pipe". Try compiling a
port without setting CFLAGS in /etc/make.conf and you will see what we

> > You said you don't want an increase in size.  But that's
> > exactly what -O3 (via inlining) and -funroll-loops do.
> > If you want not to increase size, use the default flags.
> > You could even use -Os, which instructs the compiler to
> > optimize for small size (it's somewhere between -O and
> > -O2).
> "-O3" was a typo, I meant "-O2". And I'm not against an absolute
> increase in size, just a significant one (>10% is about where I'd start
> to care)

-O2 is the default in FreeBSD 6.x maybe even in 5.5 too. Here's my
make.conf, I run FreeBSD 6.1/i386 on an Athlon64 3200+:

CFLAGS+= -mtune=athlon64
COPTFLAGS+= -mtune=athlon64

.if ${.CURDIR:M*/devel/sdl1*}

Note that I don't have "-O2 -march=athlon-xp -mfpmath=sse
-funroll-loops -pipe -ffast-math" etc. etc. in my conf file. The
reason I don't have it in there is it breaks things! A better way to
do this is on a port by port basis, that's what the .if block is for.
Also note that I don't set CXXFLAGS. Why? because CXXFLAGS is set to
whatever CFLAGS is set to. Also note the use of += and ?=, and the
creative use of -mtune= to optimize the parts of the kernel, world,
and ports that ignore CPUTYPE... BTW never put -march= in CFLAGS
because it WILL break your system... Use CPUTYPE?= to set -march.

> --- Nikolas Britton <nikolas.britton at gmail.com> wrote:
> > IIRC the Duron should be set to athlon or athlon-tbird. The athlon-4,
> > athlon-xp, athlon-mp knobs should only be used on Athlons with a
> > Palomino core or better, your Duron is to slow to be based off
> > Palomino. Also -mfp-math=sse does nothing for you because your chip
> > doesn't have full SSE support.
> No, athlon-xp is valid:
> "The second-generation Duron, the "Morgan" core, was sold in speed
> grades between 900 and 1300 MHz, and was based on the 180 nm "Palomino"
> Athlon XP core." [wikipedia.org]

My bad.

> And -mfp-math=sse actually does nothing because there's not supposed to
> be a hyphen between "fp" and "math".

You will break your system if you use that unconditionally. Use the
.if .endif block I showed you if you really feel like using it...
and... you better benchmark before and after because you may actually
be slowing down the app.

BSD Podcasts @:

More information about the freebsd-questions mailing list