public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r11-5844] testsuite: Avoid strict aliasing violations in some avx512 tests
@ 2020-12-08 10:20 Jakub Jelinek
  0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2020-12-08 10:20 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:4c6a47c7dd010f4694097638a1763aa3c5e9a37c

commit r11-5844-g4c6a47c7dd010f4694097638a1763aa3c5e9a37c
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Tue Dec 8 11:19:49 2020 +0100

    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.

Diff:
---
 gcc/testsuite/gcc.target/i386/avx512dq-vandnpd-2.c | 7 +++++--
 gcc/testsuite/gcc.target/i386/avx512dq-vandnps-2.c | 7 +++++--
 gcc/testsuite/gcc.target/i386/avx512dq-vandpd-2.c  | 7 +++++--
 gcc/testsuite/gcc.target/i386/avx512dq-vandps-2.c  | 7 +++++--
 gcc/testsuite/gcc.target/i386/avx512dq-vorpd-2.c   | 7 +++++--
 gcc/testsuite/gcc.target/i386/avx512dq-vorps-2.c   | 7 +++++--
 gcc/testsuite/gcc.target/i386/avx512dq-vxorpd-2.c  | 7 +++++--
 gcc/testsuite/gcc.target/i386/avx512dq-vxorps-2.c  | 7 +++++--
 8 files changed, 40 insertions(+), 16 deletions(-)

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;
     }
 }


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-12-08 10:20 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-08 10:20 [gcc r11-5844] testsuite: Avoid strict aliasing violations in some avx512 tests Jakub Jelinek

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).