This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/15820] New: GCC emits MOVAPS to load unaligned data in case when -O2 is invoked
- From: "dimfair at yahoo dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 4 Jun 2004 13:09:45 -0000
- Subject: [Bug c++/15820] New: GCC emits MOVAPS to load unaligned data in case when -O2 is invoked
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
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