From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1078 invoked by alias); 9 Sep 2004 23:54:17 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 1041 invoked by uid 48); 9 Sep 2004 23:54:16 -0000 Date: Thu, 09 Sep 2004 23:54:00 -0000 From: "hjl at lucon dot org" To: gcc-bugs@gcc.gnu.org Message-ID: <20040909235415.17387.hjl@lucon.org> Reply-To: gcc-bugzilla@gcc.gnu.org Subject: [Bug c/17387] New: Redundant instructions in loop optimization X-Bugzilla-Reason: CC X-SW-Source: 2004-09/txt/msg00890.txt.bz2 List-Id: For this code: extern unsigned int S[]; extern unsigned int state[]; unsigned int foo () { register unsigned int t; register int j; j=0; t=0; for (j=0; j<16; j+=4) { t= state[j+ 0]^=S[t]; t= state[j+ 1]^=S[t]; t= state[j+ 2]^=S[t]; t= state[j+ 3]^=S[t]; } t=(t)&0xff; return t; } With -O3, gcc generates: foo: .LFB2: xorl %esi, %esi xorl %ecx, %ecx .p2align 4,,7 .L2: movslq %esi,%rdx mov %ecx, %eax movl S(,%rax,4), %eax xorl state(,%rdx,4), %eax movl %eax, state(,%rdx,4) leal 1(%rsi), %edx mov %eax, %eax <====== Why? movl S(,%rax,4), %eax movslq %edx,%rdx xorl state(,%rdx,4), %eax movl %eax, state(,%rdx,4) leal 2(%rsi), %edx mov %eax, %eax <====== Why? movl S(,%rax,4), %eax movslq %edx,%rdx xorl state(,%rdx,4), %eax movl %eax, state(,%rdx,4) leal 3(%rsi), %edx mov %eax, %eax <====== Why? movl S(,%rax,4), %ecx leal 4(%rsi), %eax movslq %edx,%rdx xorl state(,%rdx,4), %ecx cmpl $16, %eax movl %eax, %esi movl %ecx, state(,%rdx,4) jne .L2 movzbl %cl,%eax ret With -O3, gcc 3.4.3 gets foo: .LFB2: xorl %edi, %edi xorl %ecx, %ecx movl $state, %esi .p2align 4,,7 .L5: movslq %ecx,%rdx mov %edi, %eax addl $4, %ecx movl S(,%rax,4), %r11d xorl state(,%rdx,4), %r11d mov %r11d, %r10d <====== Why? movl %r11d, state(,%rdx,4) movl S(,%r10,4), %r9d xorl state+4(,%rdx,4), %r9d mov %r9d, %r8d <====== Why? movl %r9d, 4(%rsi,%rdx,4) movl S(,%r8,4), %edi xorl state+8(,%rdx,4), %edi mov %edi, %eax <====== Why? movl %edi, 8(%rsi,%rdx,4) movl S(,%rax,4), %eax xorl state+12(,%rdx,4), %eax cmpl $15, %ecx movl %eax, 12(%rsi,%rdx,4) movl %eax, %edi jle .L5 andl $255, %eax ret -- Summary: Redundant instructions in loop optimization Product: gcc Version: 4.0 Status: UNCONFIRMED Severity: normal Priority: P2 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: hjl at lucon dot org CC: gcc-bugs at gcc dot gnu dot org GCC build triplet: x86_64-unknown-linux-gnu GCC host triplet: x86_64-unknown-linux-gnu GCC target triplet: x86_64-unknown-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17387