public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/29174]  New: does not recognize memcpy and optimize it
@ 2006-09-21 20:12 acahalan at gmail dot com
  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
  0 siblings, 2 replies; 3+ messages in thread
From: acahalan at gmail dot com @ 2006-09-21 20:12 UTC (permalink / raw)
  To: gcc-bugs

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


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

* [Bug middle-end/29174] does not recognize memcpy and optimize it
  2006-09-21 20:12 [Bug middle-end/29174] New: does not recognize memcpy and optimize it acahalan at gmail dot com
@ 2006-09-21 20:37 ` pinskia at gcc dot gnu dot org
  2006-09-21 20:39 ` pinskia at gcc dot gnu dot org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-09-21 20:37 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2006-09-21 20:37 -------
Yes this is known issue.
http://www.gccsummit.org/2006/view_abstract.php?content_key=27


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2006-09-21 20:37:44
               date|                            |


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


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

* [Bug middle-end/29174] does not recognize memcpy and optimize it
  2006-09-21 20:12 [Bug middle-end/29174] New: does not recognize memcpy and optimize it acahalan at gmail dot com
  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
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-09-21 20:39 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from pinskia at gcc dot gnu dot org  2006-09-21 20:39 -------
Also mentioned in with results also:
http://www.gccsummit.org/2006/2006-GCC-Summit-Proceedings.pdf


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |missed-optimization


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


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

end of thread, other threads:[~2006-09-21 20:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-09-21 20:12 [Bug middle-end/29174] New: does not recognize memcpy and optimize it acahalan at gmail dot com
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

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