[Bug c/17387] New: Redundant instructions in loop optimization
hjl at lucon dot org
gcc-bugzilla@gcc.gnu.org
Thu Sep 9 23:54:00 GMT 2004
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
More information about the Gcc-bugs
mailing list