This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: optimizer question


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]