public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/17387] New:  Redundant instructions in loop optimization
@ 2004-09-09 23:54 hjl at lucon dot org
  2004-09-10  0:36 ` [Bug rtl-optimization/17387] " pinskia at gcc dot gnu dot org
                   ` (20 more replies)
  0 siblings, 21 replies; 27+ messages in thread
From: hjl at lucon dot org @ 2004-09-09 23:54 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 27+ messages in thread
[parent not found: <bug-17387-682@http.gcc.gnu.org/bugzilla/>]

end of thread, other threads:[~2007-05-25 20:32 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-09-09 23:54 [Bug c/17387] New: Redundant instructions in loop optimization hjl at lucon dot org
2004-09-10  0:36 ` [Bug rtl-optimization/17387] " pinskia at gcc dot gnu dot org
2004-09-10  2:50 ` law at gcc dot gnu dot org
2004-09-10  8:05 ` pinskia at gcc dot gnu dot org
2004-09-10  9:53 ` hubicka at gcc dot gnu dot org
2004-09-10 23:22 ` pinskia at gcc dot gnu dot org
2004-09-11 19:55 ` rakdver at gcc dot gnu dot org
2004-11-27 20:49 ` pinskia at gcc dot gnu dot org
2005-01-23 13:36 ` steven at gcc dot gnu dot org
2005-01-24 18:17 ` hjl at lucon dot org
2005-01-24 18:53 ` pinskia at gcc dot gnu dot org
2005-01-27  1:27 ` steven at gcc dot gnu dot org
2005-01-27  1:36 ` steven at gcc dot gnu dot org
2005-01-27  1:43 ` steven at gcc dot gnu dot org
2005-01-27  4:03 ` hjl at lucon dot org
2005-01-27  6:05 ` rth at gcc dot gnu dot org
2005-01-27  7:14 ` stevenb at suse dot de
2005-01-27 10:14 ` steven at gcc dot gnu dot org
2005-01-27 10:27 ` steven at gcc dot gnu dot org
2005-01-27 10:28 ` steven at gcc dot gnu dot org
2005-01-27 13:36 ` pinskia at gcc dot gnu dot org
2005-09-29  3:44 ` pinskia at gcc dot gnu dot org
     [not found] <bug-17387-682@http.gcc.gnu.org/bugzilla/>
2006-01-15 20:30 ` pinskia at gcc dot gnu dot org
2006-02-27 23:55 ` hjl at lucon dot org
2007-04-20 20:58 ` steven at gcc dot gnu dot org
2007-04-20 21:10 ` steven at gcc dot gnu dot org
2007-05-25 20:32 ` steven at gcc dot gnu dot org

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).