public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
[parent not found: <bug-22041-10391@http.gcc.gnu.org/bugzilla/>]
* [Bug tree-optimization/22041] New: Reverse loop order for increased efficiency
@ 2005-06-12 20:57 tkoenig at gcc dot gnu dot org
  2005-06-12 23:44 ` [Bug tree-optimization/22041] " pinskia at gcc dot gnu dot org
  2005-07-07 23:42 ` pinskia at gcc dot gnu dot org
  0 siblings, 2 replies; 9+ messages in thread
From: tkoenig at gcc dot gnu dot org @ 2005-06-12 20:57 UTC (permalink / raw)
  To: gcc-bugs

The loop in the following code

$ cat stride.c
void foo(float *a, float *b, int n, int stride_a, int stride_b)
{
  int i;
  for (i=0; i<n; i++)
    {
      a[i*stride_a] = b[i*stride_b];
    }
}

is translated with "gcc -O3 -fdump-tree-optimized -S stride.c" into

<L0>:;
  *(float *) ivtmp.14 = *(float *) ivtmp.12;
  i = i + 1;
  ivtmp.12 = ivtmp.12 + ivtmp.18;
  ivtmp.14 = ivtmp.14 + ivtmp.17;
  if (n != i) goto <L0>; else goto <L2>;

and (on i686-pc-linux-gnu):

.L4:
        movl    (%ecx), %eax
        incl    %ebx
        addl    %edi, %ecx
        movl    %eax, (%edx)
        addl    %esi, %edx
        cmpl    %ebx, 16(%ebp)
        jne     .L4

The code

$ cat stride2.c
void foo(float *a, float *b, int n, int stride_a, int stride_b)
{
  int i;
  for (i=n; i>0; i--)
    {
      a[(n-i)*stride_a] = b[(n-i)*stride_b];
    }
}

is translated to

<L0>:;
  *(float *) ivtmp.16 = *(float *) ivtmp.14;
  i = i - 1;
  ivtmp.14 = ivtmp.14 + ivtmp.20;
  ivtmp.16 = ivtmp.16 + ivtmp.19;
  if (i != 0) goto <L0>; else goto <L2>;

and further

.L4:
        movl    (%ebx), %eax
        addl    %edi, %ebx
        movl    %eax, (%ecx)
        addl    %esi, %ecx
        decl    %edx
        jne     .L4

which saves one instruction and one load from memory.

-- 
           Summary: Reverse loop order for increased efficiency
           Product: gcc
           Version: 4.1.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: enhancement
          Priority: P2
         Component: tree-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: tkoenig at gcc dot gnu dot org
                CC: gcc-bugs at gcc dot gnu dot org


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


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2021-03-03 18:47 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-22041-4@http.gcc.gnu.org/bugzilla/>
2010-12-30 12:29 ` [Bug tree-optimization/22041] Reverse loop order for increased efficiency tkoenig at gcc dot gnu.org
2013-03-17 17:13 ` tkoenig at gcc dot gnu.org
2021-03-03 18:47 ` pinskia at gcc dot gnu.org
     [not found] <bug-22041-10391@http.gcc.gnu.org/bugzilla/>
2006-02-27 14:06 ` steven at gcc dot gnu dot org
2006-05-28 14:10 ` tkoenig at gcc dot gnu dot org
2006-05-28 14:25 ` rakdver at atrey dot karlin dot mff dot cuni dot cz
2006-06-05 21:36 ` tkoenig at gcc dot gnu dot org
2005-06-12 20:57 [Bug tree-optimization/22041] New: " tkoenig at gcc dot gnu dot org
2005-06-12 23:44 ` [Bug tree-optimization/22041] " pinskia at gcc dot gnu dot org
2005-07-07 23:42 ` pinskia 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).