The current gcc trunk (as well as gcc 4.7 and 4.8) produces wrong code for the attached testcase on x86_64-linux when compiled at -O3 in 32-bit mode. It is a regression from 4.6.x. This one has been quite nasty to reduce; the attached testcase is the simplest I was able to get. I believe it doesn't have any undefined behavior. $ gcc-trunk -v Using built-in specs. COLLECT_GCC=gcc-trunk COLLECT_LTO_WRAPPER=/usr/local/gcc-trunk/libexec/gcc/x86_64-unknown-linux-gnu/4.9.0/lto-wrapper Target: x86_64-unknown-linux-gnu Configured with: ../gcc-trunk/configure --enable-languages=c,c++,objc,obj-c++,fortran,lto --with-gmp=/usr/local/gcc-trunk --with-mpfr=/usr/local/gcc-trunk --with-mpc=/usr/local/gcc-trunk --with-cloog=/usr/local/gcc-trunk --prefix=/usr/local/gcc-trunk Thread model: posix gcc version 4.9.0 20130829 (experimental) [trunk revision 202067] (GCC) $ gcc-trunk -m32 -O2 small.c $ a.out 0 $ gcc-4.6 -m32 -O3 small.c $ a.out 0 $ gcc-trunk -m32 -O3 small.c $ a.out 0 Aborted (core dumped) $ gcc-4.7 -m32 -O3 small.c $ a.out 0 Aborted (core dumped) $ gcc-4.8 -m32 -O3 small.c $ a.out 0 Aborted (core dumped) $
Created attachment 30725 [details] testcase
I'm also attaching a related testcase (small2.c) for both 32-bit and 64-bit modes. $ gcc-trunk -m64 -O2 small2.c $ a.out $ gcc-4.6 -m64 -O3 small2.c $ a.out $ gcc-4.7 -m64 -O3 small2.c $ a.out Aborted (core dumped) $ gcc-4.8 -m64 -O3 small2.c $ a.out Aborted (core dumped) $ gcc-trunk -m64 -O3 small2.c $ a.out Aborted (core dumped) $
Created attachment 30726 [details] another testcase for both 32-bit and 64-bit modes
Both testcases started to fail with r181172.
Thus confirmed.
But, skimming through the dumps, it looks like it is the strlen pass that removes the important n = 0; store.
Created attachment 30728 [details] gcc49-pr58277.patch Untested fix.
Author: jakub Date: Fri Aug 30 12:41:17 2013 New Revision: 202104 URL: http://gcc.gnu.org/viewcvs?rev=202104&root=gcc&view=rev Log: PR tree-optimization/58277 * tree-ssa-strlen.c (strlen_enter_block): If do_invalidate gave up after seeing too many stmts with vdef in between dombb and current bb, invalidate everything. * gcc.c-torture/execute/pr58277-1.c: New test. * gcc.c-torture/execute/pr58277-2.c: New test. Added: trunk/gcc/testsuite/gcc.c-torture/execute/pr58277-1.c trunk/gcc/testsuite/gcc.c-torture/execute/pr58277-2.c Modified: trunk/gcc/ChangeLog trunk/gcc/testsuite/ChangeLog trunk/gcc/tree-ssa-strlen.c
Author: jakub Date: Fri Aug 30 12:53:47 2013 New Revision: 202105 URL: http://gcc.gnu.org/viewcvs?rev=202105&root=gcc&view=rev Log: PR tree-optimization/58277 * tree-ssa-strlen.c (strlen_enter_block): If do_invalidate gave up after seeing too many stmts with vdef in between dombb and current bb, invalidate everything. * gcc.c-torture/execute/pr58277-1.c: New test. * gcc.c-torture/execute/pr58277-2.c: New test. Added: branches/gcc-4_8-branch/gcc/testsuite/gcc.c-torture/execute/pr58277-1.c branches/gcc-4_8-branch/gcc/testsuite/gcc.c-torture/execute/pr58277-2.c Modified: branches/gcc-4_8-branch/gcc/ChangeLog branches/gcc-4_8-branch/gcc/testsuite/ChangeLog branches/gcc-4_8-branch/gcc/tree-ssa-strlen.c
Fixed for 4.8+ so far, thanks for reporting it.
(In reply to Jakub Jelinek from comment #10) > Fixed for 4.8+ so far, thanks for reporting it. Thanks Jakub. Wow, that's quick! You folks are wonderful.
Author: jakub Date: Wed May 7 16:01:24 2014 New Revision: 210171 URL: http://gcc.gnu.org/viewcvs?rev=210171&root=gcc&view=rev Log: Backported from mainline 2013-08-30 Jakub Jelinek <jakub@redhat.com> PR tree-optimization/58277 * tree-ssa-strlen.c (strlen_enter_block): If do_invalidate gave up after seeing too many stmts with vdef in between dombb and current bb, invalidate everything. * gcc.c-torture/execute/pr58277-1.c: New test. * gcc.c-torture/execute/pr58277-2.c: New test. Added: branches/gcc-4_7-branch/gcc/testsuite/gcc.c-torture/execute/pr58277-1.c branches/gcc-4_7-branch/gcc/testsuite/gcc.c-torture/execute/pr58277-2.c Modified: branches/gcc-4_7-branch/gcc/ChangeLog branches/gcc-4_7-branch/gcc/testsuite/ChangeLog branches/gcc-4_7-branch/gcc/tree-ssa-strlen.c
Fixed.