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

           Summary: Use constants in registers preferably to inline
                    constants (-Os)
           Product: gcc
           Version: 4.6.1
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: rtl-optimization
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: etienne_lorr...@yahoo.fr


When GCC needs to zero out an integer in memory, and it already has one
register at value zero, it takes less code bytes to write the register than
inline a constant, i.e.:

etienne@etienne-server:~/projet$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/i386-linux-gnu/gcc/i486-linux-gnu/4.6.1/lto-wrapper
Target: i486-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 4.6.1-4'
--with-bugurl=file:///usr/share/doc/gcc-4.6/README.Bugs
--enable-languages=c,c++,fortran,objc,obj-c++,go --prefix=/usr
--program-suffix=-4.6 --enable-shared --enable-multiarch
--with-multiarch-defaults=i386-linux-gnu --enable-linker-build-id
--with-system-zlib --libexecdir=/usr/lib/i386-linux-gnu
--without-included-gettext --enable-threads=posix
--with-gxx-include-dir=/usr/include/c++/4.6 --libdir=/usr/lib/i386-linux-gnu
--enable-nls --enable-clocale=gnu --enable-libstdcxx-debug
--enable-libstdcxx-time=yes --enable-plugin --enable-objc-gc
--enable-targets=all --with-arch-32=i586 --with-tune=generic
--enable-checking=release --build=i486-linux-gnu --host=i486-linux-gnu
--target=i486-linux-gnu
Thread model: posix
gcc version 4.6.1 (Debian 4.6.1-4) 

etienne@etienne-server:~/projet$ cat tmp.c
unsigned a, b;
unsigned fct (void)
  {
  a = b = 0;
  return 0;
  }
etienne@etienne-server:~/projet$ gcc -Os -fomit-frame-pointer tmp.c -c -o tmp.o
etienne@etienne-server:~/projet$ objdump -d tmp.o

tmp.o:     file format elf32-i386


Disassembly of section .text:

00000000 <fct>:
   0:    c7 05 00 00 00 00 00     movl   $0x0,0x0
   7:    00 00 00 
   a:    31 c0                    xor    %eax,%eax
   c:    c7 05 00 00 00 00 00     movl   $0x0,0x0
  13:    00 00 00 
  16:    c3                       ret    
etienne@etienne-server:~/projet$ 

It would be shorter to get this assembly:
0:    31 c0                    xor    %eax,%eax
2:    a3 00 00 00 00            mov    %eax,a
7:    a3 00 00 00 00            mov    %eax,b
c:    c3                        ret

Regards,
Etienne.

Reply via email to