public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "acahalan at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug middle-end/29174]  New: does not recognize memcpy and optimize it
Date: Thu, 21 Sep 2006 20:12:00 -0000	[thread overview]
Message-ID: <bug-29174-12219@http.gcc.gnu.org/bugzilla/> (raw)

In the code below, gcc fails to optimize a hand-crafted memcpy as a call to the
memcpy function. (or perhaps as "rep;movsb" when compiling with "-Os") I've
tried "-O2", "-O3", and "-Os". There are probably a great number of similar
optimizations that could be done.

This optimization is not unheard of; it is done by Visual Studio 2005. IMHO it
is not really any more insane than autovectorization.

junk 0 $ cat foo.c
void *foo(void *restrict, const void *restrict, unsigned long);
void *foo(void *restrict dst, const void *restrict src, unsigned long n)
{
        const char *p = src;
        char *q = dst;
        while (n--) {
                *q++ = *p++;
        }
        return dst;
}
junk 0 $ gcc -m32 -std=gnu99 -fomit-frame-pointer -Os -S foo.c
junk 0 $ cat foo.s
        .file   "foo.c"
        .text
.globl foo
        .type   foo, @function
foo:
        pushl   %ebx
        movl    16(%esp), %ebx
        movl    8(%esp), %ecx
        movl    12(%esp), %edx
        jmp     .L2
.L3:
        movb    -1(%edx), %al
        movb    %al, -1(%ecx)
.L2:
        decl    %ebx
        incl    %ecx
        incl    %edx
        cmpl    $-1, %ebx
        jne     .L3
        movl    8(%esp), %eax
        popl    %ebx
        ret
        .size   foo, .-foo
        .ident  "GCC: (GNU) 4.1.1 20060828 (Red Hat 4.1.1-20)"
        .section        .note.GNU-stack,"",@progbits
junk 0 $ gcc -v
Using built-in specs.
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --enable-shared --enable-threads=posix
--enable-checking=release --with-system-zlib --enable-__cxa_atexit
--disable-libunwind-exceptions --enable-libgcj-multifile
--enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk
--disable-dssi --enable-plugin
--with-java-home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre --with-cpu=generic
--host=x86_64-redhat-linux
Thread model: posix
gcc version 4.1.1 20060828 (Red Hat 4.1.1-20)
junk 0 $


-- 
           Summary: does not recognize memcpy and optimize it
           Product: gcc
           Version: 4.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: acahalan at gmail dot com


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


             reply	other threads:[~2006-09-21 20:12 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-09-21 20:12 acahalan at gmail dot com [this message]
2006-09-21 20:37 ` [Bug middle-end/29174] " pinskia at gcc dot gnu dot org
2006-09-21 20:39 ` pinskia 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-29174-12219@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).