public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "tony.poppleton at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug rtl-optimization/47582] New: Combine chains of movl into movq
Date: Tue, 01 Feb 2011 21:36:00 -0000	[thread overview]
Message-ID: <bug-47582-4@http.gcc.gnu.org/bugzilla/> (raw)

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

           Summary: Combine chains of movl into movq
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: rtl-optimization
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: tony.poppleton@gmail.com


The following C code (adapted from
http://stackoverflow.com/questions/4544804/in-what-cases-should-i-use-memcpy-over-standard-operators-in-c)
shows that adjacent sequences of movl could be combined into movq.

extern float a[5];
extern float b[5];

int main()
{
#if defined(M1)
    a[0] = b[0];
    a[1] = b[1];
    a[2] = b[2];
    a[3] = b[3];
    a[4] = b[4];
#elif defined(M2)
    memcpy(a, b, 5*sizeof(float));
 #endif
}

When compiled with "-O2 -fomit-frame-pointer" on GCC 4.3.5, 4.4.5, 4.5.2 and
4.6.0 (20110129), the following asm is produced for the -DM1 branch:
        movl    b(%rip), %eax
        movl    %eax, a(%rip)
        movl    b+4(%rip), %eax
        movl    %eax, a+4(%rip)
        movl    b+8(%rip), %eax
        movl    %eax, a+8(%rip)
        movl    b+12(%rip), %eax
        movl    %eax, a+12(%rip)
        movl    b+16(%rip), %eax
        movl    %eax, a+16(%rip)
        ret

However for the -DM2 branch, the memcpy implementation shows that this can be
done more efficiently:
        movq    b(%rip), %rax
        movq    %rax, a(%rip)
        movq    b+8(%rip), %rax
        movq    %rax, a+8(%rip)
        movl    b+16(%rip), %eax
        movl    %eax, a+16(%rip)
        ret

I presume that the memcpy is being done in hand-written asm?  If so, then once
this enhancment is done, then presumably that portion of memcpy code could be
converted to C code and be just as efficient.


             reply	other threads:[~2011-02-01 21:36 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-01 21:36 tony.poppleton at gmail dot com [this message]
2011-02-01 22:46 ` [Bug rtl-optimization/47582] " pinskia at gcc dot gnu.org
2015-06-10 16:16 ` tony.poppleton at gmail dot com
2015-06-10 16:30 ` tony.poppleton at gmail dot com

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