Bug 29139 - GCC produces wrong code with SSE / inline functions
Summary: GCC produces wrong code with SSE / inline functions
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.1.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-09-19 11:32 UTC by Jesper de Jong
Modified: 2006-09-22 06:51 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
Source code that demonstrates the bug (2.28 KB, text/plain)
2006-09-19 11:33 UTC, Jesper de Jong
Details
Precompiled source (*.ii) (80.24 KB, text/plain)
2006-09-19 11:34 UTC, Jesper de Jong
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jesper de Jong 2006-09-19 11:32:41 UTC
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.
Comment 1 Jesper de Jong 2006-09-19 11:33:46 UTC
Created attachment 12294 [details]
Source code that demonstrates the bug

This is the source code that demonstrates bug 29139.
Comment 2 Jesper de Jong 2006-09-19 11:34:45 UTC
Created attachment 12295 [details]
Precompiled source (*.ii)

Precompiled code for gccbug.cpp of bug 29139.
Comment 3 Jesper de Jong 2006-09-22 06:51:13 UTC
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.
Comment 4 Jesper de Jong 2006-09-22 06:51:40 UTC
Marking this bug as invalid.