This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: GCC Unrolling Simple Loop Generates Rubbish Code?
- From: Ian Lance Taylor <ian at airs dot com>
- To: Lei Ming <ming dot lei at oracle dot com>
- Cc: gcc-help at gcc dot gnu dot org
- Date: 18 Jul 2005 21:00:45 -0700
- Subject: Re: GCC Unrolling Simple Loop Generates Rubbish Code?
- References: <200507191049.49412.ming.lei@oracle.com>
Lei Ming <ming.lei@oracle.com> writes:
> This simple code:
>
> int
> main (void)
> {
> int s = 0;
> int i;
> for (i = 0; i < 100; i++)
> s += i;
> return 0;
> }
>
> After compiled with "-O3 -funroll-all-loops", will generate this piece of
> assembly code for the loop:
>
> movl $99, %eax
> .L6:
> subl $25, %eax <==
> jns .L6
> xorl %eax, %eax
> leave
> ret
I tried compiling with current gcc mainline with -O3
-funroll-all-loops. I got this:
0: 55 push %ebp
1: 31 c0 xor %eax,%eax
3: 89 e5 mov %esp,%ebp
5: 83 ec 08 sub $0x8,%esp
8: 83 e4 f0 and $0xfffffff0,%esp
b: 83 ec 10 sub $0x10,%esp
e: c9 leave
f: c3 ret
So I think things are better now.
I also see the behaviour you report with gcc 3.2.3. It does seem
pretty incomprehensible. Since it seems to be fixed, I haven't
bothered to figure out why it used to behave like that.
Ian