This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: optimizer question
- From: Jeff Law <law at porcupine dot slc dot redhat dot com>
- To: Zoltan dot 2 dot Varga at nokia dot com
- Cc: gcc-help at gcc dot gnu dot org
- Date: Fri, 20 Sep 2002 13:35:09 -0600
- Subject: Re: optimizer question
- Reply-to: law at redhat dot com
In message <214ABAB6BF4DC24EAD9AB1C7461DA6A1045116@buebe002.europe.nokia.com>,
Zoltan.2.Varga@nokia.com writes:
>
> Hi,
>
> When confronted with the following code:
>
>void main()
>{
> int x = 2;
> int y;
>
> y = rand();
> y = y / x;
> printf("%d.\n", y);
>}
>
>Why does gcc generate a division instead of a shift ? Is this a shortcoming o
>f the optimizer or some feature of C I don't
>understand ? When I replace the 'x' in the division with '2', a shift is gene
>rated. I'm using gcc-3.2 -O3 on x86 linux.
Because conversion of division into shifts happens before constant propagation.
jeff