This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
optimizer question
- From: <Zoltan dot 2 dot Varga at nokia dot com>
- To: <gcc-help at gcc dot gnu dot org>
- Date: Fri, 20 Sep 2002 21:15:23 +0200
- Subject: optimizer question
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 of the optimizer or some feature of C I don't
understand ? When I replace the 'x' in the division with '2', a shift is generated. I'm using gcc-3.2 -O3 on x86 linux.
thanks
Zoltan