Re: optimization gcc

On Mon, 25 Aug 2003 15:15:35 +0200, Albert Pala <a Pala polkomtel com pl>  said:

> Which flags should I set in gcc to get best optimized code in C ( for speed )?
> Currently I use:
> gcc -Wall -O2 march=athlon -funroll-all-loops -fomit-frame-pointer -c xyz.c
> How can i get the fastest code?

-O3 will enable some more optimizations.  Note that there is reason to believe
that -fomit-frame-pointer may generate *slower* code in some cases - not having
the frame pointer forces a register reload for memory accesses, so your code
ends up bigger and slower.  Also, look into inlining options for small
functions that are performance critical.

Contrary to popular myth, -On for n > 3 doesn't do anything extra in modern gcc.

And remember to benchmark, benchmark, benchmark.  Quite often, the results are
non-intuitive.  I've seen code that turned on aggressive inlining run slower
because the resulting code was bigger and ended up causing L1 I-cache

And keep in mind that at -O2, gcc is already doing almost as much as it can to
optimize. Don't expect to get more than another 4-5% performance *at best* by
tweaking the compiler flags.  If you need more than that, you *REALLY* need to
go back and recode your application - start looking for places where you're
using a linked list where maybe a hash table should be used, etc Use the -pg
flags to gcc to profile your code.  Figure out why it's spending the time where
it is.  Concentrate on those parts of the code.

Attachment: pgpehaCS3z107.pgp
Description: PGP signature

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]