public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Ian Lance Taylor <ian@airs.com>
To: Lei Ming <ming.lei@oracle.com>
Cc: gcc-help@gcc.gnu.org
Subject: Re: GCC Unrolling Simple Loop Generates Rubbish Code?
Date: Tue, 19 Jul 2005 04:00:00 -0000	[thread overview]
Message-ID: <m3hderxx5e.fsf@gossamer.airs.com> (raw)
In-Reply-To: <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

  reply	other threads:[~2005-07-19  4:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-07-19  2:51 Lei Ming
2005-07-19  4:00 ` Ian Lance Taylor [this message]
2005-07-19 16:14 ` jlh

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m3hderxx5e.fsf@gossamer.airs.com \
    --to=ian@airs.com \
    --cc=gcc-help@gcc.gnu.org \
    --cc=ming.lei@oracle.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).