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; 3+ 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] 3+ messages in thread

* [Bug middle-end/45098] Missed induction variable optimization
  2010-07-28  2:39 [Bug middle-end/45098] New: Missed induction variable optimization carrot at google dot com
@ 2010-07-30 17:23 ` davidxl at gcc dot gnu dot org
  2010-08-02  7:55 ` ramana at gcc dot gnu dot org
  1 sibling, 0 replies; 3+ messages in thread
From: davidxl at gcc dot gnu dot org @ 2010-07-30 17:23 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from davidxl at gcc dot gnu dot org  2010-07-30 17:23 -------
Seems -Os specific -- also reproducible on x86. With -O2, the result is
expected.

David


-- 

davidxl at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |davidxl at gcc dot gnu dot
                   |                            |org


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


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

* [Bug middle-end/45098] Missed induction variable optimization
  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
  1 sibling, 0 replies; 3+ messages in thread
From: ramana at gcc dot gnu dot org @ 2010-08-02  7:55 UTC (permalink / raw)
  To: gcc-bugs



-- 

ramana at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
           Keywords|                            |missed-optimization
   Last reconfirmed|0000-00-00 00:00:00         |2010-08-02 07:55:00
               date|                            |


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


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

end of thread, other threads:[~2010-08-02  7:55 UTC | newest]

Thread overview: 3+ 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

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