Output of gcc -v: Using built-in specs. Target: i686-pc-cygwin Configured with: ../../source/gcc-4.1.1/configure --enable-threads=posix --enable-languages=c,c++ --disable-win32-registry Thread model: posix gcc version 4.1.1 I wrote a Vector class that I wanted to optimize by using some inline assembly with SSE instructions. I noticed that with certain optimizations on, GCC version 4.1.1 produces wrong code. The source code consists of my Vector class and some test code. When I compile this with the following command line I get the error: g++ -Wall -O2 -msse -finline-functions gccbug.cpp -o gccbug Output of the program: Start FAILED: expected (1.5;3;4.5) but value is (1;3;4.5): bug in operator* FAILED: expected (1.5;3;4.5) but value is (1;3;4.5): bug in operator* FAILED: expected (0.5;1;1.5) but value is (1;1;1.5): bug in operator/ FAILED: expected (1.5;3;4.5) but value is (1;3;4.5): bug in operator* FAILED: expected (1.5;3;4.5) but value is (1;3;4.5): bug in operator* FAILED: expected (0.5;1;1.5) but value is (1;1;1.5): bug in operator/ Finished in 14338932 ticks Ther are some computations with vectors, and when I compile it with these settings, there are errors in the compilation. Note that the first element of the result vector is 1 instead of 1.5 (for the multiplication) or 0.5 (for the division). When I compile this code with different options, for example: 1. Without "-msse": g++ -Wall -O2 -finline-functions gccbug.cpp -o gccbug 2. Without "-finline-functions": g++ -Wall -O2 -msse gccbug.cpp -o gccbug Then the program works correctly! Conclusion: GCC produces wrong code with this combination of optimization options.
Created attachment 12294 [details] Source code that demonstrates the bug This is the source code that demonstrates bug 29139.
Created attachment 12295 [details] Precompiled source (*.ii) Precompiled code for gccbug.cpp of bug 29139.
I've been looking at my code some more time, and I noticed that there are bugs in it. For example, I'm not using the '&' early clobber modifier in the embedded asm, which is necessary if the output operand is modified before the input operands are used. I don't believe it's a bug in GCC after all. Sorry. Please don't use the code I added in the attachments, it has more issues besides what I mentioned above.
Marking this bug as invalid.