From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 32096 invoked by alias); 19 Feb 2008 06:01:27 -0000 Received: (qmail 31981 invoked by uid 48); 19 Feb 2008 06:00:44 -0000 Date: Tue, 19 Feb 2008 06:01:00 -0000 Message-ID: <20080219060044.31980.qmail@sourceware.org> X-Bugzilla-Reason: CC References: 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 In-Reply-To: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "xinliangli at gmail dot com" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2008-02/txt/msg02018.txt.bz2 ------- 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 : > 0: 8b 4f 04 mov 0x4(%rdi),%ecx > 3: eb 02 jmp 7 > 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 > 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