Hello, As instructed in http://gcc.gnu.org/ml/gcc/2010-04/msg00505.html i'm filing this. I've noticed gcc 4.5 has more trouble than it used to to removed dead stores when dealing with arrays, as exemplified by $ cat huh.cc struct foo_t { float x, y, z; foo_t() {} foo_t(float a, float b, float c) : x(a),y(b),z(c) {} friend foo_t operator*(foo_t lhs, float s) { return foo_t(lhs.x*s, lhs.y*s, lhs.z*s); } friend float dot(foo_t lhs, foo_t rhs) { return lhs.x*rhs.x + lhs.y*rhs.y + lhs.z*rhs.z; } }; struct bar_t { float m[3]; bar_t() {} bar_t(float a, float b, float c) { m[0]=a; m[1]=b; m[2]=c; } friend bar_t operator*(bar_t lhs, float s) { return bar_t(lhs.m[0]*s, lhs.m[1]*s, lhs.m[2]*s); } friend float dot(bar_t lhs, bar_t rhs) { return lhs.m[0]*rhs.m[0] + lhs.m[1]*rhs.m[1] + lhs.m[2]*rhs.m[2]; } }; namespace { template<typename T> float magsqr(T v) { return dot(v, v); } template<typename T> T norm(T v) { return v*(1/__builtin_sqrtf(magsqr(v))); } } void frob1(const foo_t &a, foo_t &b) { b = norm(a); } void frob2(const bar_t &a, bar_t &b) { b = norm(a); } int main() { return 0; } $ /usr/local/gcc-4.5.0/bin/g++ -O2 -ffast-math -march=native huh.cc
Whereas frob1 and frob2 do not differ with, say, gcc 4.4.1, they now do. $ /usr/local/gcc-4.5.0/bin/g++ -v Using built-in specs. COLLECT_GCC=/usr/local/gcc-4.5.0/bin/g++ COLLECT_LTO_WRAPPER=/usr/local/gcc-4.5.0/libexec/gcc/x86_64-unknown-linux-gnu/4.5.0/lto-wrapper Target: x86_64-unknown-linux-gnu Configured with: ../configure --prefix=/usr/local/gcc-4.5.0 --enable-languages=c,c++ --enable-threads=posix --disable-checking --disable-nls --with-system-zlib --disable-shared --enable-checking=none --disable-bootstrap --enable-mpfr --enable-gold Thread model: posix gcc version 4.5.0 (GCC) $ g++ -v Using built-in specs. Target: x86_64-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.4.1-4ubuntu9' --with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared --enable-multiarch --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.4 --program-suffix=-4.4 --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --disable-werror --with-arch-32=i486 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu Thread model: posix gcc version 4.4.1 (Ubuntu 4.4.1-4ubuntu9) -- Summary: 4.5.0 regression, array vs members, dead code removal issues Product: gcc Version: 4.5.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: tbptbp at gmail dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43846