This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Calculating elements addresses from arrays once
- From: Ranjit Mathew <rmathew at gmail dot com>
- To: gcc at gcc dot gnu dot org
- Date: Thu, 20 May 2004 16:47:00 +0530
- Subject: Re: Calculating elements addresses from arrays once
- References: <40AC8D73.9080808@ifrance.com>
Gruik wrote:
>>>My question is : do you think GCC, in this kind of loops, performs a
>>>little optimisation by saving somewhere the address of my_array[i] ?
>>
>> Yes, gcc should be doing this kind of optimisation; it's a type of CSE.
>>I'm not sure if -O1 will do it but -O2 certainly ought to.
>
>
> What do you mean about -01 and -02 ? i use gcc 3.3.3
He means use the "-O1" or "-O2" optimisation options like:
gcc -O1 foobar.c
or
gcc -O2 foobar.c
As for your original question, if you're a bit familiar
with assembly language you can readily check how well
GCC is able to optimise your code by looking at the
assembly output like so:
gcc -O2 -S foobar.c
This would create a file named "foobar.s" which by
default uses the AT&T assembler syntax - use "-masm=intel"
(on x86 boxes) to use the more popular Intel assembler
syntax, like so:
gcc -O2 -S -masm=intel foobar.c
Hope this helps,
Ranjit.
--
Ranjit Mathew Email: rmathew AT gmail DOT com
Bangalore, INDIA. Web: http://ranjitmathew.tripod.com/