optimizations
Reza Roboubi
reza@linisoft.com
Tue Jan 14 22:58:00 GMT 2003
In the following code, it is clear that the return value of mm() can be
eliminated. In fact, many optimizations are possible here. Yet gcc seems not
to be able to do these optimizations. Below, I posted the assembly code that
gcc generated (for the while() loop).
I compiled this code with gcc -O2 -Wall.
I was wondering if I am doing something wrong. If not, then please comment on
current gcc developments in this regard, and what it takes to add some of these
features.
Please also comment on how other compilers would compare with gcc in this case.
Are there any non-obvious remedies you have for this case?
PS: Please tell me if I must report this as a gcc bug.
Thanks in advance for any help you provide.
inline int mm(int *i)
{
if((*i)==0x10){return 0;}
(*i)++;return 1;
}
int
main(){
int k=0;
while (mm(&k)){}
write(1,&k,1);
return 0;
}
Associated assembly code for the while() loop:
0x80483b0 <main+16>: mov 0xfffffffc(%ebp),%eax
0x80483b3 <main+19>: xor %edx,%edx
0x80483b5 <main+21>: cmp $0x10,%eax
0x80483b8 <main+24>: je 0x80483c3 <main+35>
0x80483ba <main+26>: inc %eax
0x80483bb <main+27>: mov $0x1,%edx
0x80483c0 <main+32>: mov %eax,0xfffffffc(%ebp)
0x80483c3 <main+35>: test %edx,%edx
0x80483c5 <main+37>: jne 0x80483b0 <main+16>
More information about the Gcc
mailing list