public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/45098]  New: Missed induction variable optimization
@ 2010-07-28  2:39 carrot at google dot com
  2010-07-30 17:23 ` [Bug middle-end/45098] " davidxl at gcc dot gnu dot org
  2010-08-02  7:55 ` ramana at gcc dot gnu dot org
  0 siblings, 2 replies; 20+ messages in thread
From: carrot at google dot com @ 2010-07-28  2:39 UTC (permalink / raw)
  To: gcc-bugs

Compile the following code with options -march=armv7-a -mthumb -Os

extern void foo(int*);
void tr(int array[], int n)
{
  int i;
  for (i=0; i<n; i++)
    foo(&array[i]);
}

GCC 4.6 generates:

        push    {r4, r5, r6, lr}
        mov     r6, r1
        mov     r5, r0
        movs    r4, #0
        b       .L2
.L3:
        mov     r0, r5
        adds    r4, r4, #1
        bl      foo
        adds    r5, r5, #4
.L2:
        cmp     r4, r6
        blt     .L3
        pop     {r4, r5, r6, pc}

We can see that both r4 and r5 are loop induction variables, and r4 is used for
loop counter only. So we can transform it to

        push    {r4, r5, r6, lr}
        mov     r5, r0
        add     r6, r5, r1 << 2
        b       .L2
.L3:
        mov     r0, r5
        bl      foo
        adds    r5, r5, #4
.L2:
        cmp     r5, r6
        blt     .L3
        pop     {r4, r5, r6, pc}

This new code is shorter and faster than original result, it uses one less
register at the same time.

Both tree-ssa and rtl loop optimizations missed this optimization.


-- 
           Summary: Missed induction variable optimization
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: middle-end
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: carrot at google dot com
 GCC build triplet: i686-linux
  GCC host triplet: i686-linux
GCC target triplet: arm-eabi


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


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

end of thread, other threads:[~2011-07-11 16:32 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-07-28  2:39 [Bug middle-end/45098] New: Missed induction variable optimization carrot at google dot com
2010-07-30 17:23 ` [Bug middle-end/45098] " davidxl at gcc dot gnu dot org
2010-08-02  7:55 ` ramana at gcc dot gnu dot org
     [not found] <bug-45098-4@http.gcc.gnu.org/bugzilla/>
2011-05-18 10:43 ` vries at gcc dot gnu.org
2011-05-18 19:04 ` vries at gcc dot gnu.org
2011-05-19  9:02 ` vries at gcc dot gnu.org
2011-05-19  9:21 ` vries at gcc dot gnu.org
2011-05-19 10:01 ` vries at gcc dot gnu.org
2011-05-20 20:00 ` vries at gcc dot gnu.org
2011-05-22 19:14 ` vries at gcc dot gnu.org
2011-05-22 20:20 ` vries at gcc dot gnu.org
2011-05-23  7:26 ` vries at gcc dot gnu.org
2011-05-23  8:17 ` vries at gcc dot gnu.org
2011-06-04  8:21 ` ramana at gcc dot gnu.org
2011-06-04  8:43 ` vries at gcc dot gnu.org
2011-06-14 14:30 ` vries at gcc dot gnu.org
2011-06-14 15:05 ` vries at gcc dot gnu.org
2011-06-16 17:58 ` vries at gcc dot gnu.org
2011-06-16 18:01 ` vries at gcc dot gnu.org
2011-07-11 16:32 ` vries at gcc dot gnu.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).