public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/49421] New: [arm] suboptimal choice of working regs
@ 2011-06-15 12:02 philb at gnu dot org
  2011-06-29 20:47 ` [Bug target/49421] " ramana at gcc dot gnu.org
  2024-03-28  6:23 ` pinskia at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: philb at gnu dot org @ 2011-06-15 12:02 UTC (permalink / raw)
  To: gcc-bugs

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

           Summary: [arm] suboptimal choice of working regs
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: target
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: philb@gnu.org


If a leaf function requires one more working register than can be accomodated
in the call-clobbered set, gcc currently tends to push r4 and use that next. 
However, in the specific case of a leaf function, it would be better to push lr
and use that as the working register, since then the return can be done with a
single pop.  Consider the made-up example:

int f(int *a, int *b, int *c, int *d)
{
  int i;
  for (i = 0; i < 4; i++)
    if (a[i] || b[i] || c[i] || d[i])
      return 1;

  return 0;
}

which compiles (-march=armv6 -mtune=arm1136jf-s -O2) to:

f:
    @ args = 0, pretend = 0, frame = 0
    @ frame_needed = 0, uses_anonymous_args = 0
    @ link register save eliminated.
    mov    ip, #0
    str    r4, [sp, #-4]!
.L3:
    ldr    r4, [r0, ip]
    cmp    r4, #0
    bne    .L7
    ldr    r4, [r1, ip]
    cmp    r4, #0
    bne    .L7
    ldr    r4, [r2, ip]
    cmp    r4, #0
    bne    .L7
    ldr    r4, [r3, ip]
    add    ip, ip, #4
    cmp    r4, #0
    bne    .L7
    cmp    ip, #16
    bne    .L3
    mov    r0, r4
.L2:
    ldmfd    sp!, {r4}
    bx    lr
.L7:
    mov    r0, #1
    b    .L2

If lr had been pushed instead of r4 then the return could have simply been "pop
{lr}".

Also, since this is arm11, it is no more expensive to push two words than one. 
If the compiler had stacked both r4 and lr, it would have freed up an extra
register for the loop which would probably have allowed the loads to be
scheduled better.


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

* [Bug target/49421] [arm] suboptimal choice of working regs
  2011-06-15 12:02 [Bug target/49421] New: [arm] suboptimal choice of working regs philb at gnu dot org
@ 2011-06-29 20:47 ` ramana at gcc dot gnu.org
  2024-03-28  6:23 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: ramana at gcc dot gnu.org @ 2011-06-29 20:47 UTC (permalink / raw)
  To: gcc-bugs

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

Ramana Radhakrishnan <ramana at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |missed-optimization
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2011.06.29 20:47:18
                 CC|                            |ramana at gcc dot gnu.org
     Ever Confirmed|0                           |1

--- Comment #1 from Ramana Radhakrishnan <ramana at gcc dot gnu.org> 2011-06-29 20:47:18 UTC ---
confirmed -


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

* [Bug target/49421] [arm] suboptimal choice of working regs
  2011-06-15 12:02 [Bug target/49421] New: [arm] suboptimal choice of working regs philb at gnu dot org
  2011-06-29 20:47 ` [Bug target/49421] " ramana at gcc dot gnu.org
@ 2024-03-28  6:23 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-03-28  6:23 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=49421

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|NEW                         |RESOLVED
      Known to work|                            |5.4.0

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Fixed since at least GCC 5.
lr is the only thing pushed/poped:
        str     lr, [sp, #-4]!
...
        ldr     pc, [sp], #4
.L7:
        mov     r0, #1
        ldr     pc, [sp], #4

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

end of thread, other threads:[~2024-03-28  6:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-06-15 12:02 [Bug target/49421] New: [arm] suboptimal choice of working regs philb at gnu dot org
2011-06-29 20:47 ` [Bug target/49421] " ramana at gcc dot gnu.org
2024-03-28  6:23 ` pinskia 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).