public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "msieweke at broadcom dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/39755]  New: inline memcpy() incorrectly optimized on MIPS target
Date: Mon, 13 Apr 2009 19:52:00 -0000	[thread overview]
Message-ID: <bug-39755-7832@http.gcc.gnu.org/bugzilla/> (raw)

In one case the C compiler can optimize away an inline memcpy() on a
MIPS target.  The problem was duplicated with GCC 3.2.1 and 3.3.3.
The problem does not affect x86 targets or GCC 4.x (tested on 4.2.4).
The MIPS cross-compiler runs under RHEL.  Tested MIPS cross-compilers
under Cygwin and Mingw with the same results.

This is the test code and the resulting output.  The "if" statement and
16-byte memcpy() are optimized away, leaving only the 4-byte memcpy.

Compile with:  mipsisa32-elf-gcc -O2 -c test.c
---------------------------
#include <string.h>
typedef struct {
    char C[16];
    int  E;
} st;

void f( st *S, char* c );
void f( st *S, char* c )
{
    if ( S->E == 6 )
        memcpy( &S->C, c, 16 );
    else
        memcpy( &S->C, c, 4 );
}
---------------------------
00000000 <f>:
   0:   88a20000        lwl     v0,0(a1)
   4:   98a20003        lwr     v0,3(a1)
   8:   a8820000        swl     v0,0(a0)
   c:   03e00008        jr      ra
  10:   b8820003        swr     v0,3(a0)
---------------------------

Compiler info:
$ mipsisa32-elf-gcc -v                  
Reading specs from
/tools/ecos/3.2.1_opt/Linux/opt/ecos/gnutools/mipsisa32-elf/bin/../lib/gcc-lib/mipsisa32-elf/3.2.1/specs
Configured with: /home/msieweke/ecos20/gnutools-src/gcc-3.2.1/configure
--target=mipsisa32-elf --prefix=/home/msieweke/gnutools_321
--enable-languages=c,c++ --enable-gofast --with-gnu-as --with-gnu-ld
--with-newlib
--with-gxx-include-dir=/home/msieweke/gnutools_321/mipsisa32-elf/include -v
Thread model: single
gcc version 3.2.1


-- 
           Summary: inline memcpy() incorrectly optimized on MIPS target
           Product: gcc
           Version: 3.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: msieweke at broadcom dot com
 GCC build triplet: i386-gnu-linux
  GCC host triplet: i386-gnu-linux
GCC target triplet: mipsisa32-elf


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


             reply	other threads:[~2009-04-13 19:52 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-13 19:52 msieweke at broadcom dot com [this message]
2009-04-14 10:14 ` [Bug c/39755] " rguenth at gcc dot gnu dot org
2009-04-16 15:06 ` msieweke at broadcom dot com
2009-04-16 15:56 ` rguenth 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-39755-7832@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).