Bug 21149 - invalid code generation for _mm_movehl_ps SSE intrisinc
Summary: invalid code generation for _mm_movehl_ps SSE intrisinc
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.0.0
: P2 normal
Target Milestone: 4.0.2
Assignee: Not yet assigned to anyone
URL: http://gcc.gnu.org/ml/gcc-patches/200...
Keywords: patch, ssemmx, wrong-code
Depends on:
Blocks:
 
Reported: 2005-04-21 13:07 UTC by julien pommier
Modified: 2005-07-21 20:33 UTC (History)
1 user (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work:
Known to fail:
Last reconfirmed: 2005-07-20 15:20:16


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description julien pommier 2005-04-21 13:07:42 UTC
The following code does generate wrong results when optimization is turned on :

#include <stdio.h>
#include <xmmintrin.h>

void pv(const char *s, __m128 v) {
  float *p = (float*)&v;
  printf("%s=[%g %g %g %g]\n", s,p[0],p[1],p[2],p[3]);
}

#define P(x) pv(#x,x)


static void plop(__m128 *Y) {
  __m128 zero = _mm_setzero_ps();
  __m128 foo = _mm_movehl_ps(zero, *Y);
  __m128 bar = _mm_movehl_ps(*Y, zero);
  P(*Y);P(foo);P(bar);
}

int main() {
  __m128 y=_mm_set_ps(-3,2,1,9);
  plop(&y); 
  return 0;
}

Here are some outputs:

> gcc-3.4 -O3 -Wall -W -msse  -o toto toto.c && ./toto
*Y=[9 1 2 -3]
foo=[0 0 9 1]
bar=[9 1 0 0]

> gcc-4.0 -g -O0 -Wall -W -msse -o toto toto.c && ./toto
*Y=[9 1 2 -3]
foo=[2 -3 0 0]
bar=[0 0 2 -3]   (this one is correct)

> gcc-4.0 -O3 -Wall -W -msse  -o toto toto.c && ./toto
*Y=[9 1 2 -3]
foo=[9 1 0 0]
bar=[0 0 2 -3]
(same output with gcc-4.1 from cvs)


Tested with:
gcc-3.4 (GCC) 3.4.4 20050314 (prerelease) (Debian 3.4.3-12)
gcc-4.0 (GCC) 4.0.0 20050410 (prerelease) (Debian 4.0-0pre10)
gcc (GCC) 4.0.0 20050418 (prerelease)
gcc (GCC) 4.1.0 20050421 (experimental)
Comment 1 Andrew Pinski 2005-07-06 14:36:39 UTC
Note You are validing C aliasing rules:
  float *p = (float*)&v;

Use an union or -fno-strict-aliasing.
But that does not change the problem.
Comment 2 Andrew Pinski 2005-07-20 15:20:15 UTC
Patch here: <http://gcc.gnu.org/ml/gcc-patches/2005-07/msg01318.html>.
Comment 3 CVS Commits 2005-07-21 19:58:40 UTC
Subject: Bug 21149

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-4_0-branch
Changes by:	rth@gcc.gnu.org	2005-07-21 19:58:31

Modified files:
	gcc            : ChangeLog 
	gcc/config/i386: sse.md 

Log message:
	PR target/21149
	* config/i386/i386.md (sse_movhlps): Fix vec_select values.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=2.7592.2.326&r2=2.7592.2.327
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/config/i386/sse.md.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.7&r2=1.7.14.1

Comment 4 CVS Commits 2005-07-21 19:59:17 UTC
Subject: Bug 21149

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	rth@gcc.gnu.org	2005-07-21 19:59:09

Modified files:
	gcc            : ChangeLog 
	gcc/config/i386: sse.md 

Log message:
	PR target/21149
	* config/i386/i386.md (sse_movhlps): Fix vec_select values.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.9505&r2=2.9506
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/config/i386/sse.md.diff?cvsroot=gcc&r1=1.21&r2=1.22

Comment 5 Andrew Pinski 2005-07-21 20:33:35 UTC
Fixed.
Comment 6 CVS Commits 2005-07-28 14:38:22 UTC
Subject: Bug 21149

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	jakub@gcc.gnu.org	2005-07-28 14:38:13

Modified files:
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/gcc.target/i386: sse-3.c 

Log message:
	PR target/21149
	* gcc.target/i386/sse-3.c: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.5838&r2=1.5839
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.target/i386/sse-3.c.diff?cvsroot=gcc&r1=NONE&r2=1.1

Comment 7 CVS Commits 2005-07-28 14:41:29 UTC
Subject: Bug 21149

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-4_0-branch
Changes by:	jakub@gcc.gnu.org	2005-07-28 14:41:25

Modified files:
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/gcc.target/i386: sse-3.c 

Log message:
	PR target/21149
	* gcc.target/i386/sse-3.c: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.5084.2.305&r2=1.5084.2.306
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.target/i386/sse-3.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=NONE&r2=1.1.2.1