public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/15820] New: GCC emits MOVAPS to load unaligned data in case when -O2 is invoked
@ 2004-06-04 13:09 dimfair at yahoo dot com
  2004-06-04 13:12 ` [Bug c++/15820] " pinskia at gcc dot gnu dot org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: dimfair at yahoo dot com @ 2004-06-04 13:09 UTC (permalink / raw)
  To: gcc-bugs

When -O2 option is invoked, GCC emits MOVAPS as part of _mm_loadh_pi intrinsic 
to load of unaligned data.  
 
For the code like 
	float *float_ptr; 
	__m128 a; 
	... 
	_mm_loadh_pi( a, (__m64 *)(float_ptr + 22) ); 
 
GCC emits following asm code 
	movaps	88(%eax), %xmm1		;; eax -> float_ptr 
	movhps	%xmm1, -120(%ebp) 
Compiled program faults on movaps because 88(%eax) isn't 16-byte aligned. 
This bug appears only when -O2 option is invoked (-O1, -O3 are OK). 
 
Command line: 
	g++ -O2 -g -march=pentium4 -msse2 test.cpp 
 
test.cpp: 
- begin ------------------------------------------------------------- 
#include <iostream> 
#include <xmmintrin.h> 
 
bool Invert_6x6_fast( float *src ) 
{ 
	__m128	det, tmp1, tmp2; 
	__m128	row[6]; 
 
	tmp1 = _mm_setzero_ps(); 
	tmp2 = _mm_setzero_ps(); 
 
	row[0]	= _mm_shuffle_ps( tmp1, tmp2, 0x88 ); 
	row[1]	= _mm_shuffle_ps( tmp1, tmp2, 0xDD ); 
	tmp1	= _mm_loadh_pi( _mm_loadl_pi( tmp1, (__m64*)(&src[11]) ), 
(__m64*)(&src[22]) ); 
	row[2]	= _mm_shuffle_ps( tmp1, tmp2, 0x88 ); 
	row[3]	= _mm_shuffle_ps( tmp1, tmp2, 0x44 ); 
 
	tmp1	= _mm_loadh_pi( _mm_loadl_pi( tmp1, (__m64*)(&src[16]) ), 
(__m64*)(&src[20]) ); 
	row[5]	= _mm_shuffle_ps( tmp1, tmp2, 0x22 ); 
 
	tmp2	= _mm_load_ss( &src[0] ); 
	tmp2	= _mm_sub_ss( _mm_add_ss( tmp1, tmp1 ), _mm_mul_ss( tmp2, 
_mm_mul_ss( tmp1, tmp1 ) ) ); 
 
	_mm_store_ss( &src[0], tmp2 ); 
 
	row[1]	= _mm_sub_ps( row[1], tmp1); 
	row[3]	= _mm_sub_ps( row[3], tmp1); 
	row[5]	= _mm_sub_ps( row[5], _mm_mul_ps( row[0], tmp1 ) ); 
 
	// ----------------------------------------------- 
	det		= _mm_mul_ps( row[2], tmp1 ); 
 
	if( _mm_movemask_ps( det )  ) 
		return false; 
 
	det		= _mm_sub_ss( tmp1, det ); 
 
	return true; 
} // Invert_6x6_fast 
 
 
using namespace std; 
 
 
int main() 
{ 
	cout << "Hello, World!" << endl; 
 
	float data[64] __attribute__((aligned(16))); 
 
	for(int i=0;i < 64;i++) 
		data[i] = (float)i*i + 1; 
 
	Invert_6x6_fast(data); 
 
	for(int i=0;i < 16;i++) 
		cout << i << ": " << data[i] << endl; 
 
	return 0;	 
} 
- end ---------------------------------------------------------------

-- 
           Summary: GCC emits MOVAPS to load unaligned data in case when -O2
                    is invoked
           Product: gcc
           Version: 3.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: dimfair at yahoo dot com
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/15820] GCC emits MOVAPS to load unaligned data in case when -O2 is invoked
  2004-06-04 13:09 [Bug c++/15820] New: GCC emits MOVAPS to load unaligned data in case when -O2 is invoked dimfair at yahoo dot com
@ 2004-06-04 13:12 ` pinskia at gcc dot gnu dot org
  2004-06-04 13:44 ` bangerth at dealii dot org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-06-04 13:12 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-06-04 13:11 -------
Invalid as you are chaning the alignment of the type and alignment requirments of the variable:
        _mm_loadh_pi( a, (__m64 *)(float_ptr + 22) ); 

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/15820] GCC emits MOVAPS to load unaligned data in case when -O2 is invoked
  2004-06-04 13:09 [Bug c++/15820] New: GCC emits MOVAPS to load unaligned data in case when -O2 is invoked dimfair at yahoo dot com
  2004-06-04 13:12 ` [Bug c++/15820] " pinskia at gcc dot gnu dot org
@ 2004-06-04 13:44 ` bangerth at dealii dot org
  2004-06-04 14:26 ` dimfair at yahoo dot com
  2004-06-04 14:37 ` [Bug target/15820] " pinskia at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: bangerth at dealii dot org @ 2004-06-04 13:44 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From bangerth at dealii dot org  2004-06-04 13:44 -------
To be more explicit: if you pass this function an unaligned pointer, 
how can you expect the compiler to do something about it? 
 
W. 

-- 


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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/15820] GCC emits MOVAPS to load unaligned data in case when -O2 is invoked
  2004-06-04 13:09 [Bug c++/15820] New: GCC emits MOVAPS to load unaligned data in case when -O2 is invoked dimfair at yahoo dot com
  2004-06-04 13:12 ` [Bug c++/15820] " pinskia at gcc dot gnu dot org
  2004-06-04 13:44 ` bangerth at dealii dot org
@ 2004-06-04 14:26 ` dimfair at yahoo dot com
  2004-06-04 14:37 ` [Bug target/15820] " pinskia at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: dimfair at yahoo dot com @ 2004-06-04 14:26 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From dimfair at yahoo dot com  2004-06-04 14:26 -------
(In reply to comment #2) 
> To be more explicit: if you pass this function an unaligned pointer,  
> how can you expect the compiler to do something about it?  
>   
> W.  
 
test function is a (specially) simplified inversion of 6x6 matrix function 
which get src aligned parameter always.  
I'm sure this is a compiler's bug, because gcc uses MOVAPS for loading of __m64 
parameter of _mm_loadh_pi which _can be unaligned_ according to Intel's specs 
(BTW, I found this bug when I ported healthy program from Intel's compiler to 
GCC). 
 
NOTE: test function is meaningless (but correct!) because I tried to make the 
shortest testcase (try to comment ANY line and bug disappeared). 
 
Dmitry (it's my name :)) ) 
 
 

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |UNCONFIRMED
         Resolution|INVALID                     |


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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug target/15820] GCC emits MOVAPS to load unaligned data in case when -O2 is invoked
  2004-06-04 13:09 [Bug c++/15820] New: GCC emits MOVAPS to load unaligned data in case when -O2 is invoked dimfair at yahoo dot com
                   ` (2 preceding siblings ...)
  2004-06-04 14:26 ` dimfair at yahoo dot com
@ 2004-06-04 14:37 ` pinskia at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-06-04 14:37 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-06-04 14:37 -------
Fixed on the mainline:
_Z15Invert_6x6_fastPf:
.LFB1894:
        pushl   %ebp
.LCFI5:
        xorps   %xmm0, %xmm0
        movl    %esp, %ebp
.LCFI6:
        subl    $104, %esp
.LCFI7:
        movaps  %xmm0, %xmm1
        movl    8(%ebp), %eax
        movlps  44(%eax), %xmm1
        movss   (%eax), %xmm2
        movhps  88(%eax), %xmm1
        movaps  %xmm1, %xmm3
        movlps  64(%eax), %xmm1
        movhps  80(%eax), %xmm1
        shufps  $136, %xmm0, %xmm3
        movaps  %xmm1, %xmm0
        mulps   %xmm1, %xmm3
        mulss   %xmm1, %xmm0
        mulss   %xmm0, %xmm2
        movaps  %xmm1, %xmm0
        addss   %xmm1, %xmm0
        subss   %xmm2, %xmm0
        movss   %xmm0, (%eax)
        movmskps        %xmm3, %eax
        testl   %eax, %eax
        leave
        sete    %al
        movzbl  %al, %eax
        ret

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
          Component|c++                         |target
           Keywords|                            |wrong-code
         Resolution|                            |FIXED
   Target Milestone|---                         |3.5.0


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


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2004-06-04 14:37 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-06-04 13:09 [Bug c++/15820] New: GCC emits MOVAPS to load unaligned data in case when -O2 is invoked dimfair at yahoo dot com
2004-06-04 13:12 ` [Bug c++/15820] " pinskia at gcc dot gnu dot org
2004-06-04 13:44 ` bangerth at dealii dot org
2004-06-04 14:26 ` dimfair at yahoo dot com
2004-06-04 14:37 ` [Bug target/15820] " pinskia at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).