From: hugh (hugh at domain csn.ul.ie)
Date: Fri 20 Aug 1999 - 15:45:46 IST
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
> 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.
This archive was generated by hypermail 2.1.6 : Thu 06 Feb 2003 - 13:04:29 GMT