public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "xinliangli at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug middle-end/27986] [4.0/4.1/4.2/4.3 Regression] jump to middle of loop on entry with using old version of an variable
Date: Tue, 19 Feb 2008 06:01:00 -0000	[thread overview]
Message-ID: <20080219060044.31980.qmail@sourceware.org> (raw)
In-Reply-To: <bug-27986-5748@http.gcc.gnu.org/bugzilla/>



------- Comment #10 from xinliangli at gmail dot com  2008-02-19 06:00 -------
(In reply to comment #0)
> in the following code gcc choses the registers in such a way that it causes
> itself an extra copy for every loop iteration and has to jump past the copy to
> start the loop... it's probably easiest to describe just by looking at the
> code:
> 
> % cat jmp-over.c
> void foo(int *v, int *d, int g)
> {
>   int s = v[1];
>   int s0;
>   do {
>     s0 = s;
>     s += *d;
>     ++d;
>   } while (s < g);
>   v[0] = s0;
> }
> 
> % gcc -g -O3 -Wall   -c -o jmp-over.o jmp-over.c
> % objdump -dr jmp-over.o
> 
> jmp-over.o:     file format elf64-x86-64
> 
> Disassembly of section .text:
> 
> 0000000000000000 <foo>:
>    0:   8b 4f 04                mov    0x4(%rdi),%ecx
>    3:   eb 02                   jmp    7 <foo+0x7>
>    5:   89 c1                   mov    %eax,%ecx
>    7:   89 c8                   mov    %ecx,%eax
>    9:   03 06                   add    (%rsi),%eax
>    b:   48 83 c6 04             add    $0x4,%rsi
>    f:   39 d0                   cmp    %edx,%eax
>   11:   7c f2                   jl     5 <foo+0x5>
>   13:   89 0f                   mov    %ecx,(%rdi)
>   15:   c3                      retq
> 
> the jump-over is unnecessary...
> 
>         mov    0x4(%rdi),%ecx
> 1:      mov    %ecx,%eax
>         add    (%rsi),%ecx
>         add    $0x4,%rsi
>         cmp    %edx,%ecx
>         jl     1b
>         mov    %eax,(%rdi)
>         retq
> 
> -dean
> 
> % gcc -v
> Using built-in specs.
> Target: x86_64-linux-gnu
> Configured with: ../gcc/configure --prefix=/home/odo/gcc
> --host=x86_64-linux-gnu --disable-multilib --enable-languages=c,c++
> --disable-bootstrap
> Thread model: posix
> gcc version 4.2.0 20060603 (experimental)
> 


// David Li

Note that assignment of s0 = s in the loop is mostly dead except for the last
occurence. So it should be optimized into:

do {
   s += *d;
   ++d;
} while (s < g);
v[0] = (s-*(d-1));


-- 

xinliangli at gmail dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |xinliangli at gmail dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27986


  parent reply	other threads:[~2008-02-19  6:01 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-06-10 22:32 [Bug pending/27986] New: unnecessary jump to middle of loop on entry dean at arctic dot org
2006-06-11  8:35 ` [Bug middle-end/27986] jump to middle of loop on entry with using old version of an variable pinskia at gcc dot gnu dot org
2006-09-03  7:19 ` [Bug middle-end/27986] [4.0/4.1/4.2 Regression] " pinskia at gcc dot gnu dot org
2006-09-07  1:14 ` mmitchel at gcc dot gnu dot org
2006-09-30  9:25 ` steven at gcc dot gnu dot org
2006-10-02 13:56 ` amacleod at redhat dot com
2006-10-02 14:01 ` amacleod at redhat dot com
2006-10-02 21:46 ` steven at gcc dot gnu dot org
2006-10-02 22:14 ` amacleod at redhat dot com
2007-02-03 17:36 ` [Bug middle-end/27986] [4.0/4.1/4.2/4.3 " gdr at gcc dot gnu dot org
2007-02-03 20:42 ` pinskia at gcc dot gnu dot org
2007-02-14  9:12 ` mmitchel at gcc dot gnu dot org
2007-03-10  1:41 ` mmitchel at gcc dot gnu dot org
2008-02-19  6:01 ` xinliangli at gmail dot com [this message]
2008-02-19 17:43 ` [Bug middle-end/27986] [4.0/4.1/4.2/4.3/4.4 " dean at arctic dot org
2008-07-04 21:23 ` [Bug middle-end/27986] [4.2/4.3/4.4 " jsm28 at gcc dot gnu dot org
2009-02-12 13:59 ` [Bug middle-end/27986] [4.2 " ubizjak at gmail dot com
2009-03-30 16:58 ` jsm28 at gcc dot gnu dot org

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=20080219060044.31980.qmail@sourceware.org \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /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).