public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "carrot at google dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug target/45335]  New: Use ldrd to load two consecutive words
Date: Thu, 19 Aug 2010 07:18:00 -0000	[thread overview]
Message-ID: <bug-45335-17659@http.gcc.gnu.org/bugzilla/> (raw)

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

struct S
{
    void* p1;
    void* p2;
    void* p3;
    void* p4;
};

void foo1(struct S* fp, struct S* otherSaveArea)
{
    struct S* saveArea = fp - 1;
    printf("StackSaveArea for fp %p [%p/%p]:\n", fp, saveArea, otherSaveArea);
    printf("  prevFrame=%p savedPc=%p meth=%p curPc=%p fp[0]=0x%08x\n",
       saveArea->p1, saveArea->p2,saveArea->p3,saveArea->p4,*(unsigned
int*)fp);
}

GCC 4.6 generates

foo1:
        push    {r4, r5, r6, lr}
        mov     r4, r0
        ldr     r5, .L2
        sub     sp, sp, #8
        mov     r3, r1
        sub     r2, r0, #16
.LPIC0:
        add     r5, pc
        mov     r1, r0
        mov     r0, r5
        bl      printf(PLT)
        ldr     r6, [r4, #-4]     // A
        ldr     r5, [r4, #0]      // B
        ldr     r0, .L2+4
        ldr     r1, [r4, #-16]    // C
        ldr     r2, [r4, #-12]    // D
.LPIC1:
        add     r0, pc
        ldr     r3, [r4, #-8]
        str     r6, [sp, #0]      // E
        str     r5, [sp, #4]      // F
        bl      printf(PLT)
        add     sp, sp, #8
        pop     {r4, r5, r6, pc}

Notice instructions A and B loading two consecutive words, they can be written
as a single instruction
        ldrd    r6, r5, [r4, -4]

It results in shorter and potentially faster code. Similarly instructions C and
D can be replace by a ldrd. Instructions E and F shows a chance for strd
instruction.

We don't have a ldrd insn pattern to represent two separate loads. Maybe we can
define one and let combine to find the chances.

There is also the same opportunity for ARM instructions, but there are more
constraints on register usage. In arm mode, the first register must be even
numbered and the second register number must be exact successor of the first
one. These are similar to the constraints of ldm and stm, and our register
allocator can't handle them.


-- 
           Summary: Use ldrd to load two consecutive words
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: target
        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=45335


             reply	other threads:[~2010-08-19  7:18 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-19  7:18 carrot at google dot com [this message]
2010-08-20  3:13 ` [Bug target/45335] " carrot at google dot com
2010-08-23  8:24 ` ramana at gcc dot gnu dot 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-45335-17659@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).