public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "philb at gnu dot org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug target/49421] New: [arm] suboptimal choice of working regs
Date: Wed, 15 Jun 2011 12:02:00 -0000	[thread overview]
Message-ID: <bug-49421-4@http.gcc.gnu.org/bugzilla/> (raw)

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.


             reply	other threads:[~2011-06-15 12:02 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-15 12:02 philb at gnu dot org [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-49421-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).