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.


-- 
           Summary: GCC produces wrong code with SSE / inline functions
           Product: gcc
           Version: 4.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: jespdj at hotmail dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29139

Reply via email to