From: Jakub Jelinek Date: Tue, 8 Dec 2020 10:19:49 +0000 (+0100) Subject: testsuite: Avoid strict aliasing violations in some avx512 tests X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=4c6a47c7dd010f4694097638a1763aa3c5e9a37c;p=gcc.git 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 * 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. --- diff --git a/gcc/testsuite/gcc.target/i386/avx512dq-vandnpd-2.c b/gcc/testsuite/gcc.target/i386/avx512dq-vandnpd-2.c index 0be2b7ceeb7..0a7d19b77be 100644 --- a/gcc/testsuite/gcc.target/i386/avx512dq-vandnpd-2.c +++ b/gcc/testsuite/gcc.target/i386/avx512dq-vandnpd-2.c @@ -16,8 +16,11 @@ CALC (double *s1, double *s2, double *r) for (i = 0; i < SIZE; i++) { - tmp = (~(*(long long *) &s1[i])) & (*(long long *) &s2[i]); - r[i] = *(double *) &tmp; + union U { double d; long long l; } u1, u2; + u1.d = s1[i]; + u2.d = s2[i]; + u1.l = (~u1.l) & u2.l; + r[i] = u1.d; } } diff --git a/gcc/testsuite/gcc.target/i386/avx512dq-vandnps-2.c b/gcc/testsuite/gcc.target/i386/avx512dq-vandnps-2.c index 39a45c1417f..836a7abada6 100644 --- a/gcc/testsuite/gcc.target/i386/avx512dq-vandnps-2.c +++ b/gcc/testsuite/gcc.target/i386/avx512dq-vandnps-2.c @@ -16,8 +16,11 @@ CALC (float *s1, float *s2, float *r) for (i = 0; i < SIZE; i++) { - tmp = (~(*(int *) &s1[i])) & (*(int *) &s2[i]); - r[i] = *(float *) &tmp; + union U { float f; int i; } u1, u2; + u1.f = s1[i]; + u2.f = s2[i]; + u1.i = (~u1.i) & u2.i; + r[i] = u1.f; } } diff --git a/gcc/testsuite/gcc.target/i386/avx512dq-vandpd-2.c b/gcc/testsuite/gcc.target/i386/avx512dq-vandpd-2.c index 208336b6532..b629c9fa8f1 100644 --- a/gcc/testsuite/gcc.target/i386/avx512dq-vandpd-2.c +++ b/gcc/testsuite/gcc.target/i386/avx512dq-vandpd-2.c @@ -16,8 +16,11 @@ CALC (double *s1, double *s2, double *r) for (i = 0; i < SIZE; i++) { - tmp = (*(long long *) &s1[i]) & (*(long long *) &s2[i]); - r[i] = *(double *) &tmp; + union U { double d; long long l; } u1, u2; + u1.d = s1[i]; + u2.d = s2[i]; + u1.l &= u2.l; + r[i] = u1.d; } } diff --git a/gcc/testsuite/gcc.target/i386/avx512dq-vandps-2.c b/gcc/testsuite/gcc.target/i386/avx512dq-vandps-2.c index 50268b907e0..6e55e66b8e3 100644 --- a/gcc/testsuite/gcc.target/i386/avx512dq-vandps-2.c +++ b/gcc/testsuite/gcc.target/i386/avx512dq-vandps-2.c @@ -16,8 +16,11 @@ CALC (float *s1, float *s2, float *r) for (i = 0; i < SIZE; i++) { - tmp = (*(int *) &s1[i]) & (*(int *) &s2[i]); - r[i] = *(float *) &tmp; + union U { float f; int i; } u1, u2; + u1.f = s1[i]; + u2.f = s2[i]; + u1.i &= u2.i; + r[i] = u1.f; } } diff --git a/gcc/testsuite/gcc.target/i386/avx512dq-vorpd-2.c b/gcc/testsuite/gcc.target/i386/avx512dq-vorpd-2.c index 97fe84ea3d6..6376c1cdd9f 100644 --- a/gcc/testsuite/gcc.target/i386/avx512dq-vorpd-2.c +++ b/gcc/testsuite/gcc.target/i386/avx512dq-vorpd-2.c @@ -15,8 +15,11 @@ CALC (double *src1, double *src2, double *dst) for (i = 0; i < SIZE; i++) { - long long tmp = (*(long long *) &src1[i]) | (*(long long *) &src2[i]); - dst[i] = *(double *) &tmp; + union U { double d; long long l; } u1, u2; + u1.d = src1[i]; + u2.d = src2[i]; + u1.l |= u2.l; + dst[i] = u1.d; } } diff --git a/gcc/testsuite/gcc.target/i386/avx512dq-vorps-2.c b/gcc/testsuite/gcc.target/i386/avx512dq-vorps-2.c index 95a7c5f29ed..3d30247e032 100644 --- a/gcc/testsuite/gcc.target/i386/avx512dq-vorps-2.c +++ b/gcc/testsuite/gcc.target/i386/avx512dq-vorps-2.c @@ -15,8 +15,11 @@ CALC (float *src1, float *src2, float *dst) for (i = 0; i < SIZE; i++) { - int tmp = (*(int *) &src1[i]) | (*(int *) &src2[i]); - dst[i] = *(float *) &tmp; + union U { float f; int i; } u1, u2; + u1.f = src1[i]; + u2.f = src2[i]; + u1.i |= u2.i; + dst[i] = u1.f; } } diff --git a/gcc/testsuite/gcc.target/i386/avx512dq-vxorpd-2.c b/gcc/testsuite/gcc.target/i386/avx512dq-vxorpd-2.c index 4f4a07e0e56..068be60ae90 100644 --- a/gcc/testsuite/gcc.target/i386/avx512dq-vxorpd-2.c +++ b/gcc/testsuite/gcc.target/i386/avx512dq-vxorpd-2.c @@ -15,8 +15,11 @@ CALC (double *src1, double *src2, double *dst) for (i = 0; i < SIZE; i++) { - long long tmp = (*(long long *) &src1[i]) ^ (*(long long *) &src2[i]); - dst[i] = *(double *) &tmp; + union U { double d; long long l; } u1, u2; + u1.d = src1[i]; + u2.d = src2[i]; + u1.l ^= u2.l; + dst[i] = u1.d; } } diff --git a/gcc/testsuite/gcc.target/i386/avx512dq-vxorps-2.c b/gcc/testsuite/gcc.target/i386/avx512dq-vxorps-2.c index 144283e36a4..716bb81c6db 100644 --- a/gcc/testsuite/gcc.target/i386/avx512dq-vxorps-2.c +++ b/gcc/testsuite/gcc.target/i386/avx512dq-vxorps-2.c @@ -15,8 +15,11 @@ CALC (float *src1, float *src2, float *dst) for (i = 0; i < SIZE; i++) { - int tmp = (*(int *) &src1[i]) ^ (*(int *) &src2[i]); - dst[i] = *(float *) &tmp; + union U { float f; int i; } u1, u2; + u1.f = src1[i]; + u2.f = src2[i]; + u1.i ^= u2.i; + dst[i] = u1.f; } }