[Bug c++/29139] New: GCC produces wrong code with SSE / inline functions

2006-09-19 Thread jespdj at hotmail dot com
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



[Bug c++/29139] GCC produces wrong code with SSE / inline functions

2006-09-19 Thread jespdj at hotmail dot com


--- Comment #1 from jespdj at hotmail dot com  2006-09-19 11:33 ---
Created an attachment (id=12294)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=12294&action=view)
Source code that demonstrates the bug

This is the source code that demonstrates bug 29139.


-- 


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



[Bug c++/29139] GCC produces wrong code with SSE / inline functions

2006-09-19 Thread jespdj at hotmail dot com


--- Comment #2 from jespdj at hotmail dot com  2006-09-19 11:34 ---
Created an attachment (id=12295)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=12295&action=view)
Precompiled source (*.ii)

Precompiled code for gccbug.cpp of bug 29139.


-- 


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



[Bug target/29139] GCC produces wrong code with SSE / inline functions

2006-09-21 Thread jespdj at hotmail dot com


--- Comment #3 from jespdj at hotmail dot com  2006-09-22 06:51 ---
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.


-- 


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



[Bug target/29139] GCC produces wrong code with SSE / inline functions

2006-09-21 Thread jespdj at hotmail dot com


--- Comment #4 from jespdj at hotmail dot com  2006-09-22 06:51 ---
Marking this bug as invalid.


-- 

jespdj at hotmail dot com changed:

   What|Removed |Added

 Status|UNCONFIRMED |RESOLVED
 Resolution||INVALID


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



[Bug c++/29249] New: Alignment error with static const variable in inline function

2006-09-27 Thread jespdj at hotmail dot com
Look at the following source code:

#include 

typedef int __attribute__ ((aligned (16))) aint;

inline void function() {
static const aint x = 123;

unsigned long a = (unsigned long) &x;
printf("Address of x: 0x%lX - %s\n", a, a & 15L ? "ALIGNMENT ERROR" :
"ok");
}

int main() {
function();
return 0;
}

The output on my system is:

Address of x: 0x40E3E8 - ALIGNMENT ERROR

The variable x is supposed to be aligned on a 16 byte boundary, but it is not.
Note that this only happens when the function is inline and the variable is
static. If I remove either "inline" or "static", the alignment seems to work
properly.

I am aware of bug #15795, but this is a different issue, since I'm not
dynamically allocating memory here.

Compiled like this:
  g++ tst.cpp -o tst

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 am using Cygwin on Windows 2000 Professional and Windows XP, and compiled GCC
4.1.1 from source using the configuration as specified above.


-- 
   Summary: Alignment error with static const variable in inline
function
   Product: gcc
   Version: 4.1.1
Status: UNCONFIRMED
  Severity: major
  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=29249



[Bug c++/29249] Alignment error with static const variable in inline function

2006-09-27 Thread jespdj at hotmail dot com


--- Comment #1 from jespdj at hotmail dot com  2006-09-27 08:55 ---
Created an attachment (id=12336)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=12336&action=view)
Source code that demonstrates the bug


-- 


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



[Bug c++/29249] Alignment error with static const variable in inline function

2006-09-27 Thread jespdj at hotmail dot com


--- Comment #2 from jespdj at hotmail dot com  2006-09-27 08:55 ---
Created an attachment (id=12337)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=12337&action=view)
Precompiled source (*.ii)


-- 


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



[Bug target/29249] Alignment error with static const variable in inline function

2006-09-27 Thread jespdj at hotmail dot com


--- Comment #5 from jespdj at hotmail dot com  2006-09-27 21:11 ---
Created an attachment (id=12342)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=12342&action=view)
output of g++ tst.cpp -S

Here is the assembler source produced with g++ tst.cpp -S

At the bottom of the file is this:

.globl __ZZ8functionvE1x
.section.rdata$_ZZ8functionvE1x,"dr"
.linkonce same_size
.align 16
__ZZ8functionvE1x:
.long   123
.def_printf;.scl2;  .type   32; .endef

Indeed there is an ".align 16", but despite this, I get the alignment error.
When I comment out "inline" on the function, the assembly source looks slightly
different. I will attach the assembly file in a separate attachment.


-- 


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



[Bug target/29249] Alignment error with static const variable in inline function

2006-09-27 Thread jespdj at hotmail dot com


--- Comment #6 from jespdj at hotmail dot com  2006-09-27 21:12 ---
Created an attachment (id=12343)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=12343&action=view)
assembly source without "inline"

This is the assembly file I get when I compile without "inline", so the source
looks like:

#include 

typedef int __attribute__ ((aligned (16))) aint;

// no inline
void function() {
static const aint x = 123;

unsigned long a = (unsigned long) &x;
printf("Address of x: 0x%lX - %s\n", a, a & 15L ? "ALIGNMENT ERROR" :
"ok");
}

int main() {
function();
return 0;
}

The bottom of the assembly file now looks like this:

popl%ebp
leal-4(%ecx), %esp
ret
.section .rdata,"dr"
.align 16
__ZZ8functionvE1x:
.long   123
.def_printf;.scl2;  .type   32; .endef


-- 


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



[Bug target/29249] Alignment error with static const variable in inline function

2006-09-28 Thread jespdj at hotmail dot com


--- Comment #8 from jespdj at hotmail dot com  2006-09-28 07:45 ---
Ok, I filed a bug report for binutils about this.
http://sourceware.org/bugzilla/show_bug.cgi?id=3276


-- 


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