testsuite: Avoid strict aliasing violations in some avx512 tests

These tests violated strict aliasing, fixed by using a union and
type punning through that.

2020-12-08  Jakub Jelinek  <jakub@redhat.com>

	* gcc.target/i386/avx512dq-vandnpd-2.c (CALC): Use union
	to avoid aliasing violations.
	* gcc.target/i386/avx512dq-vandnps-2.c (CALC): Likewise.
	* gcc.target/i386/avx512dq-vandpd-2.c (CALC): Likewise.
	* gcc.target/i386/avx512dq-vandps-2.c (CALC): Likewise.
	* gcc.target/i386/avx512dq-vorpd-2.c (CALC): Likewise.
	* gcc.target/i386/avx512dq-vorps-2.c (CALC): Likewise.
	* gcc.target/i386/avx512dq-vxorpd-2.c (CALC): Likewise.
	* gcc.target/i386/avx512dq-vxorps-2.c (CALC): Likewise.
This commit is contained in:
Jakub Jelinek 2020-12-08 11:19:49 +01:00
parent 19c1ef85c3
commit 4c6a47c7dd
8 changed files with 40 additions and 16 deletions

View File

@ -16,8 +16,11 @@ CALC (double *s1, double *s2, double *r)
for (i = 0; i < SIZE; i++) for (i = 0; i < SIZE; i++)
{ {
tmp = (~(*(long long *) &s1[i])) & (*(long long *) &s2[i]); union U { double d; long long l; } u1, u2;
r[i] = *(double *) &tmp; u1.d = s1[i];
u2.d = s2[i];
u1.l = (~u1.l) & u2.l;
r[i] = u1.d;
} }
} }

View File

@ -16,8 +16,11 @@ CALC (float *s1, float *s2, float *r)
for (i = 0; i < SIZE; i++) for (i = 0; i < SIZE; i++)
{ {
tmp = (~(*(int *) &s1[i])) & (*(int *) &s2[i]); union U { float f; int i; } u1, u2;
r[i] = *(float *) &tmp; u1.f = s1[i];
u2.f = s2[i];
u1.i = (~u1.i) & u2.i;
r[i] = u1.f;
} }
} }

View File

@ -16,8 +16,11 @@ CALC (double *s1, double *s2, double *r)
for (i = 0; i < SIZE; i++) for (i = 0; i < SIZE; i++)
{ {
tmp = (*(long long *) &s1[i]) & (*(long long *) &s2[i]); union U { double d; long long l; } u1, u2;
r[i] = *(double *) &tmp; u1.d = s1[i];
u2.d = s2[i];
u1.l &= u2.l;
r[i] = u1.d;
} }
} }

View File

@ -16,8 +16,11 @@ CALC (float *s1, float *s2, float *r)
for (i = 0; i < SIZE; i++) for (i = 0; i < SIZE; i++)
{ {
tmp = (*(int *) &s1[i]) & (*(int *) &s2[i]); union U { float f; int i; } u1, u2;
r[i] = *(float *) &tmp; u1.f = s1[i];
u2.f = s2[i];
u1.i &= u2.i;
r[i] = u1.f;
} }
} }

View File

@ -15,8 +15,11 @@ CALC (double *src1, double *src2, double *dst)
for (i = 0; i < SIZE; i++) for (i = 0; i < SIZE; i++)
{ {
long long tmp = (*(long long *) &src1[i]) | (*(long long *) &src2[i]); union U { double d; long long l; } u1, u2;
dst[i] = *(double *) &tmp; u1.d = src1[i];
u2.d = src2[i];
u1.l |= u2.l;
dst[i] = u1.d;
} }
} }

View File

@ -15,8 +15,11 @@ CALC (float *src1, float *src2, float *dst)
for (i = 0; i < SIZE; i++) for (i = 0; i < SIZE; i++)
{ {
int tmp = (*(int *) &src1[i]) | (*(int *) &src2[i]); union U { float f; int i; } u1, u2;
dst[i] = *(float *) &tmp; u1.f = src1[i];
u2.f = src2[i];
u1.i |= u2.i;
dst[i] = u1.f;
} }
} }

View File

@ -15,8 +15,11 @@ CALC (double *src1, double *src2, double *dst)
for (i = 0; i < SIZE; i++) for (i = 0; i < SIZE; i++)
{ {
long long tmp = (*(long long *) &src1[i]) ^ (*(long long *) &src2[i]); union U { double d; long long l; } u1, u2;
dst[i] = *(double *) &tmp; u1.d = src1[i];
u2.d = src2[i];
u1.l ^= u2.l;
dst[i] = u1.d;
} }
} }

View File

@ -15,8 +15,11 @@ CALC (float *src1, float *src2, float *dst)
for (i = 0; i < SIZE; i++) for (i = 0; i < SIZE; i++)
{ {
int tmp = (*(int *) &src1[i]) ^ (*(int *) &src2[i]); union U { float f; int i; } u1, u2;
dst[i] = *(float *) &tmp; u1.f = src1[i];
u2.f = src2[i];
u1.i ^= u2.i;
dst[i] = u1.f;
} }
} }