In the attached example, the store of type_t is not optimized by gcc. Instead 
of storing one 32-bit value, four 8-bit values are stored. 
 
gcc-4.0.1 produces the following code: 
 
 /home/fm3/foo.c:16 
 80483b7:       c6 05 13 96 04 08 04    movb   $0x4,0x8049613 
 80483be:       c6 05 12 96 04 08 03    movb   $0x3,0x8049612 
 80483c5:       c6 05 11 96 04 08 02    movb   $0x2,0x8049611 
 80483cc:       c6 05 10 96 04 08 01    movb   $0x1,0x8049610 
 
gcc-3.4.5 produces the following code: 
 
 /home/fm3/foo.c:16 
 8048391:       ba 01 02 03 04          mov    $0x4030201,%edx 
 /home/fm3/foo.c:15 
 8048396:       89 e5                   mov    %esp,%ebp 
 8048398:       83 ec 18                sub    $0x18,%esp 
 804839b:       83 e4 f0                and    $0xfffffff0,%esp 
 804839e:       83 ec 10                sub    $0x10,%esp 
 /home/fm3/foo.c:16 
 80483a1:       89 15 1c 96 04 08       mov    %edx,0x804961c 
 
  (better) 
 
gcc-2.95.4 produces the following code: 
 
 /home/fm3/foo.c:16 
 80483f7:       c7 05 84 96 04 08 01    movl   $0x4030201,0x8049684 
 80483fe:       02 03 04 
 
 (best because no register allocation) 
 
The example: 
 
#include <stdio.h> 
 
typedef struct 
{ 
  unsigned char a; 
  unsigned char b; 
  unsigned char c; 
  unsigned char d; 
} type_t; 
 
static type_t u; 
 
int 
main(void) 
{ 
  u = (type_t){ 1, 2, 3, 4}; 
 
  printf("%d %d %d %d\n", u.a, u.b, u.c, u.d); 
 
  return 0; 
} 
 
gcc-4.0 -v -save-temps -g -o foo -W -Wall -Wformat=2 -O3 -Wall -W 
-fomit-frame-pointer -march=pentium3 -g foo.c: 
 
Using built-in specs. 
Target: i486-linux 
Configured with: ../src/configure -v 
--enable-languages=c,c++,java,f95,objc,ada,treelang --prefix=/usr 
--enable-shared --with-system-zlib --libexecdir=/usr/lib --enable-nls 
--without-included-gettext --enable-threads=posix --program-suffix=-4.0 
--enable-__cxa_atexit --enable-libstdcxx-allocator=mt --enable-clocale=gnu 
--enable-libstdcxx-debug --enable-java-gc=boehm --enable-java-awt=gtk 
--enable-mpfr --disable-werror --enable-checking=release i486-linux 
Thread model: posix 
gcc version 4.0.1 20050522 (prerelease) (Debian 4.0.0-9) 
 /usr/lib/gcc/i486-linux/4.0.1/cc1 -E -quiet -v foo.c -march=pentium3 -W -Wall 
-Wformat=2 -Wall -W -fomit-frame-pointer -fworking-directory -O3 
-fpch-preprocess -o foo.i 
ignoring nonexistent directory 
"/usr/lib/gcc/i486-linux/4.0.1/../../../../i486-linux/include" 
#include "..." search starts here: 
#include <...> search starts here: 
 /usr/local/include 
 /usr/lib/gcc/i486-linux/4.0.1/include 
 /usr/include 
End of search list. 
 /usr/lib/gcc/i486-linux/4.0.1/cc1 -fpreprocessed foo.i -quiet -dumpbase foo.c 
-march=pentium3 -auxbase foo -g -g -O3 -W -Wall -Wformat=2 -Wall -W -version 
-fomit-frame-pointer -o foo.s 
GNU C version 4.0.1 20050522 (prerelease) (Debian 4.0.0-9) (i486-linux) 
        compiled by GNU C version 4.0.1 20050522 (prerelease) (Debian 
4.0.0-9). 
GGC heuristics: --param ggc-min-expand=64 --param ggc-min-heapsize=64260 
 as -V -Qy --32 -o foo.o foo.s 
GNU assembler version 2.15 (i486-linux-gnu) using BFD version 2.15 
 /usr/lib/gcc/i486-linux/4.0.1/collect2 --eh-frame-hdr -m elf_i386 
-dynamic-linker /lib/ld-linux.so.2 -o 
foo /usr/lib/gcc/i486-linux/4.0.1/../../../../lib/crt1.o 
/usr/lib/gcc/i486-linux/4.0.1/../../../../lib/crti.o 
/usr/lib/gcc/i486-linux/4.0.1/crtbegin.o 
-L/usr/lib/gcc/i486-linux/4.0.1 -L/usr/lib/gcc/i486-linux/4.0.1 
-L/usr/lib/gcc/i486-linux/4.0.1/../../../../lib 
-L/usr/lib/gcc/i486-linux/4.0.1/../../.. -L/lib/../lib -L/usr/lib/../lib foo.o 
-lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s 
--no-as-needed /usr/lib/gcc/i486-linux/4.0.1/crtend.o 
/usr/lib/gcc/i486-linux/4.0.1/../../../../lib/crtn.o

-- 
           Summary: Missing optimization when storing structures
           Product: gcc
           Version: 4.0.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: fm3 at os dot inf dot tu-dresden dot de
                CC: gcc-bugs at gcc dot gnu dot org
  GCC host triplet: i486-linux
GCC target triplet: i486-linux


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

Reply via email to