This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: optimizations
- From: Andrew Pinski <pinskia at physics dot uc dot edu>
- To: Reza Roboubi <reza at linisoft dot com>
- Cc: gcc-help <gcc-help at gcc dot gnu dot org>, "gcc at gcc dot gnu dot org" <gcc at gcc dot gnu dot org>
- Date: Tue, 14 Jan 2003 12:59:22 -0800
- Subject: Re: optimizations
What version of gcc?
This seems like it was fixed at one point doing the 3.x series because
it does not happen with 3.3 (prerelease) or 3.4 (experimental).
Thanks,
Andrew Pinski
On Tuesday, Jan 14, 2003, at 12:35 US/Pacific, Reza Roboubi wrote:
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>