Bug 28792 - Incorrect i386 code for inlined function with -O2 -mtune=generic
Incorrect i386 code for inlined function with -O2 -mtune=generic
Status: RESOLVED DUPLICATE of bug 21920
Product: gcc
Classification: Unclassified
Component: target
4.1.1
: P3 normal
: ---
Assigned To: Not yet assigned to anyone
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2006-08-21 15:10 UTC by Jerome Chiabaut
Modified: 2006-08-21 15:23 UTC (History)
5 users (show)

See Also:
Host: i386-redhat-linux
Target: i386-redhat-linux
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
C source file (2.30 KB, text/plain)
2006-08-21 15:16 UTC, Jerome Chiabaut
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jerome Chiabaut 2006-08-21 15:10:53 UTC
gcc 4.1.1 generates incorrect 386 code with -O2 or -O3 flag for an inlined function if the -mtune cpu-type is one of: generic, i586, i686, pentium2, pentium3, pentium-m. The generated code seems to be correct for the following cpu-types: i386, i486, pentium4 & prescott.
The problem is also present in gcc version 3.4.4 (cygming special).
Comment 1 Jerome Chiabaut 2006-08-21 15:16:32 UTC
Created attachment 12110 [details]
C source file
Comment 2 Jerome Chiabaut 2006-08-21 15:20:01 UTC
gcc -v -save-temps -g -Wall -O2 -mtune=generic bug.c
Using built-in specs.
Target: i386-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 --with-java-home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre --with-cpu=generic --host=i386-redhat-linux
Thread model: posix
gcc version 4.1.1 20060525 (Red Hat 4.1.1-1)
 /usr/libexec/gcc/i386-redhat-linux/4.1.1/cc1 -E -quiet -v bug.c -mtune=generic -Wall -fworking-directory -O2 -fpch-preprocess -o bug.i
ignoring nonexistent directory "/usr/lib/gcc/i386-redhat-linux/4.1.1/../../../../i386-redhat-linux/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 /usr/lib/gcc/i386-redhat-linux/4.1.1/include
 /usr/include
End of search list.
 /usr/libexec/gcc/i386-redhat-linux/4.1.1/cc1 -fpreprocessed bug.i -quiet -dumpbase bug.c -mtune=generic -auxbase bug -g -O2 -Wall -version -o bug.s
GNU C version 4.1.1 20060525 (Red Hat 4.1.1-1) (i386-redhat-linux)
        compiled by GNU C version 4.1.1 20060525 (Red Hat 4.1.1-1).
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 7a31534f101210f86e6343d2c0c239f8
 as -V -Qy -o bug.o bug.s
GNU assembler version 2.16.91.0.6 (i386-redhat-linux) using BFD version 2.16.91.0.6 20060212
 /usr/libexec/gcc/i386-redhat-linux/4.1.1/collect2 --eh-frame-hdr -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 /usr/lib/gcc/i386-redhat-linux/4.1.1/../../../crt1.o /usr/lib/gcc/i386-redhat-linux/4.1.1/../../../crti.o /usr/lib/gcc/i386-redhat-linux/4.1.1/crtbegin.o -L/usr/lib/gcc/i386-redhat-linux/4.1.1 -L/usr/lib/gcc/i386-redhat-linux/4.1.1 -L/usr/lib/gcc/i386-redhat-linux/4.1.1/../../.. bug.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc/i386-redhat-linux/4.1.1/crtend.o /usr/lib/gcc/i386-redhat-linux/4.1.1/../../../crtn.o
Comment 3 Andrew Pinski 2006-08-21 15:23:14 UTC
The code violates C aliasing rules:
    struct pseudoheader ph;
    csum = my_chksum_tcp((u_int16_t *)&ph, (u_int16_t *)pkt, len);
.....
static unsigned short my_chksum_tcp( unsigned short *h, unsigned short * d, int dlen )
....
   cksum = h[0];

*** This bug has been marked as a duplicate of 21920 ***