System in question is a 2GHz opteron running Fedora Core 2 Reading specs from /usr/local/lib/gcc/x86_64-unknown-linux-gnu/4.0.0/specs Configured with: ../gcc-4.0-20041212/configure --disable-nls --with-system-zlib --with-libiconv-prefix=/usr/local --program-suffix=40 --disable-shared --disable -libgcj --disable-multilib Thread model: posix gcc version 4.0.0 20041212 (experimental)
The package at www.boo.net/~jasonp/gccbug.tar.bz2 contains driver.c: driver program graph.h: header with a few definitions graph.c: contains code to find the number of vertices and connected components of a very large graph. This is an excerpt from a much larger source file, and contains the problem code graph.dat: the input graph; contains 80000 edges, each given by a pair of integers in hex format. I'm sorry I can't get the input set to be any smaller; the full dataset this came from is 20x larger than this This program prints out the computed number of connected components for the graph described by graph.dat; compiling with gcc40 *.c {-O1|-O2|-O3} and running a.out yields '57670' as output. Compiling with 'gcc40 *.c' or using gcc 3.4.1 with or without optimization, produces '57671' for output. The difference is only 1 here, but for the full dataset it is quite noticeably off. The loop that I believe is responsible for the discrepancy starts at graph.c:124 and is labeled with a comment that reads /* OPTIMIZATION PRODUCES A BUG IN THIS LOOP */ Declaring the two variables above this comment to be volatile causes the resulting code to work correctly with any level of optimization in gcc 4.0...I've tried to understand the assembly code generated by the compiler but it's a bit too convoluted for me. I'll be happy to provide additional clarification if it's needed. jasonp -- Summary: optimization bug in 4.0-20041212 snapshot Product: gcc Version: 4.0.0 Status: UNCONFIRMED Severity: normal Priority: P2 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: jasonp at boo dot net CC: gcc-bugs at gcc dot gnu dot org GCC build triplet: x86_64-unknown-linux-gnu GCC host triplet: x86_64-unknown-linux-gnu GCC target triplet: x86_64-unknown-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19050