Hi, Given the following test C++ file:
class Class { public: void func(); float *buf; int size; }; void Class::func() { for (int i = 0; i < size; ++i) { buf[i] = 0; } } 4.6 (see below for exact version) will generate larger code (36 vs. 30 bytes) than 4.5.1 (Debian 4.5.1-6) given -Os. The output is 00000000 <Class::func()>: 0: 55 push %ebp 1: 31 c0 xor %eax,%eax 3: 89 e5 mov %esp,%ebp 5: 8b 4d 08 mov 0x8(%ebp),%ecx 8: 53 push %ebx 9: 8b 59 04 mov 0x4(%ecx),%ebx c: eb 10 jmp 1e <Class::func()+0x1e> e: 8d 14 85 00 00 00 00 lea 0x0(,%eax,4),%edx 15: 40 inc %eax 16: 03 11 add (%ecx),%edx 18: c7 02 00 00 00 00 movl $0x0,(%edx) 1e: 39 d8 cmp %ebx,%eax 20: 7c ec jl e <Class::func()+0xe> 22: 5b pop %ebx 23: 5d pop %ebp 24: c3 ret Basically the problem is that the lea is large (due to the zero immediate taking up 32 bits); 4.5 uses a variation where the address calculation takes both a base and an index register, which has a shorter form not requiring to store the zero. (The joys of x86; lea edx, [eax*4 + ecx] takes less space then lea edx, [eax*4]...) === Configured with: ../src/configure -v --with-pkgversion='Debian 20100828-1' --with-bugurl=file:///usr/share/doc/gcc-snapshot/README.Bugs --enable-languages=c,ada,c++,fortran,objc,obj-c++ --prefix=/usr/lib/gcc-snapshot --enable-shared --enable-multiarch --enable-linker-build-id --with-system-zlib --disable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-plugin --enable-gold --with-plugin-ld=ld.gold --enable-objc-gc --enable-targets=all --with-arch-32=i586 --with-tune=generic --disable-werror --enable-checking=yes --build=i486-linux-gnu --host=i486-linux-gnu --target=i486-linux-gnu Thread model: posix gcc version 4.6.0 20100828 (experimental) [trunk revision 163616] (Debian 20100828-1) -- Summary: Less efficient x86 addressing mode selection on 4.6, causes -Os size regression from 4.5 Product: gcc Version: 4.6.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: rtl-optimization AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: sgunderson at bigfoot dot com GCC build triplet: i486-linux-gnu GCC host triplet: i486-linux-gnu GCC target triplet: i486-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45670