On Fri, 20 Aug 1999, Caolan McNamara wrote:
> with no optimization gcc calls strlen, but with optimization turned on
> gcc converts the strlen call on the literal "test" directly into the
> value 4, which made my day, coz it was what i hoped to see. cute eh..
this form of optimization (afaik) is known as constant folding and/or
constant propogation. Basically, any expression that can be calculated at
compile time will be calculated and the result will be used during
run-time.
> But what i wondered was, if there was a list of what gcc does to optimize
> anywhere, or it is just a hodgepodge of magic rules that you have to trawl
> through experimentation or the gcc source to determine.
A reference of what optimizations gcc performs according to what options
you pass it can be found at www.delorie.com/gnu/docs/gcc/gcc_10.html
Each optimization in gcc is complete/modular .. the translated source code
is stored in an intermediate representation (IR) internally and each
optimization makes a "pass" over this, generating a new IR which is used
for the next optimization, until all optimizations are completed.
There is an option to make gcc print out a copy of the IR after each
phase if you want to figure out which phase made the optimization :
gcc -da foo.c
You can also print out the IR after specific phases, see
http://www.delorie.com/gnu/docs/gcc/gcc_9.html for more info.
-hugh
Maintained by the ILUG website team. The aim of Linux.ie is to
support and help commercial and private users of Linux in Ireland. You can
display ILUG news in your own webpages, read backend
information to find out how. Networking services kindly provided by HEAnet, server kindly donated by
Dell. Linux is a trademark of Linus Torvalds,
used with permission. No penguins were harmed in the production or maintenance
of this highly praised website. Looking for the
Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!