x86: Avoid -Wuninitialized warnings on _mm*_undefined_* in C++ [PR105593]

Message ID Y8CndZxq5djLlAB/@tucnak
State Unresolved
Headers
Series x86: Avoid -Wuninitialized warnings on _mm*_undefined_* in C++ [PR105593] |

Checks

Context Check Description
snail/gcc-patch-check warning Git am fail log

Commit Message

Jakub Jelinek Jan. 13, 2023, 12:36 a.m. UTC
  Hi!

In https://gcc.gnu.org/pipermail/gcc-patches/2023-January/609844.html
I've posted a patch to allow ignoring -Winit-self using GCC diagnostic
pragmas, such that one can mark self-initialization as intentional
disabling of -Wuninitialized warnings.

The following incremental patch uses that in the x86 intrinsic
headers.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk
if the above mentioned patch is approved/committed?

2023-01-13  Jakub Jelinek  <jakub@redhat.com>

	PR c++/105593
gcc/
	* config/i386/xmmintrin.h (_mm_undefined_ps): Temporarily
	disable -Winit-self using pragma GCC diagnostic ignored.
	* config/i386/emmintrin.h (_mm_undefined_pd, _mm_undefined_si128):
	Likewise.
	* config/i386/avxintrin.h (_mm256_undefined_pd, _mm256_undefined_ps,
	_mm256_undefined_si256): Likewise.
	* config/i386/avx512fintrin.h (_mm512_undefined_pd,
	_mm512_undefined_ps, _mm512_undefined_epi32): Likewise.
	* config/i386/avx512fp16intrin.h (_mm_undefined_ph,
	_mm256_undefined_ph, _mm512_undefined_ph): Likewise.
gcc/testsuite/
	* g++.target/i386/pr105593.C: New test.


	Jakub
  

Comments

Uros Bizjak Jan. 13, 2023, 6:58 a.m. UTC | #1
On Fri, Jan 13, 2023 at 1:36 AM Jakub Jelinek <jakub@redhat.com> wrote:
>
> Hi!
>
> In https://gcc.gnu.org/pipermail/gcc-patches/2023-January/609844.html
> I've posted a patch to allow ignoring -Winit-self using GCC diagnostic
> pragmas, such that one can mark self-initialization as intentional
> disabling of -Wuninitialized warnings.
>
> The following incremental patch uses that in the x86 intrinsic
> headers.
>
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk
> if the above mentioned patch is approved/committed?
>
> 2023-01-13  Jakub Jelinek  <jakub@redhat.com>
>
>         PR c++/105593
> gcc/
>         * config/i386/xmmintrin.h (_mm_undefined_ps): Temporarily
>         disable -Winit-self using pragma GCC diagnostic ignored.
>         * config/i386/emmintrin.h (_mm_undefined_pd, _mm_undefined_si128):
>         Likewise.
>         * config/i386/avxintrin.h (_mm256_undefined_pd, _mm256_undefined_ps,
>         _mm256_undefined_si256): Likewise.
>         * config/i386/avx512fintrin.h (_mm512_undefined_pd,
>         _mm512_undefined_ps, _mm512_undefined_epi32): Likewise.
>         * config/i386/avx512fp16intrin.h (_mm_undefined_ph,
>         _mm256_undefined_ph, _mm512_undefined_ph): Likewise.
> gcc/testsuite/
>         * g++.target/i386/pr105593.C: New test.

LGTM.

Thanks,
Uros.

>
> --- gcc/config/i386/xmmintrin.h.jj      2022-11-07 10:30:42.741629972 +0100
> +++ gcc/config/i386/xmmintrin.h 2023-01-12 15:33:21.685483809 +0100
> @@ -112,7 +112,10 @@ typedef float __v4sf __attribute__ ((__v
>  extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
>  _mm_undefined_ps (void)
>  {
> +#pragma GCC diagnostic push
> +#pragma GCC diagnostic ignored "-Winit-self"
>    __m128 __Y = __Y;
> +#pragma GCC diagnostic pop
>    return __Y;
>  }
>
> --- gcc/config/i386/emmintrin.h.jj      2022-03-14 14:48:04.299055735 +0100
> +++ gcc/config/i386/emmintrin.h 2023-01-12 15:33:04.148735997 +0100
> @@ -99,7 +99,10 @@ _mm_setr_pd (double __W, double __X)
>  extern __inline __m128d __attribute__((__gnu_inline__, __always_inline__, __artificial__))
>  _mm_undefined_pd (void)
>  {
> +#pragma GCC diagnostic push
> +#pragma GCC diagnostic ignored "-Winit-self"
>    __m128d __Y = __Y;
> +#pragma GCC diagnostic pop
>    return __Y;
>  }
>
> @@ -785,7 +788,10 @@ _mm_move_epi64 (__m128i __A)
>  extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
>  _mm_undefined_si128 (void)
>  {
> +#pragma GCC diagnostic push
> +#pragma GCC diagnostic ignored "-Winit-self"
>    __m128i __Y = __Y;
> +#pragma GCC diagnostic pop
>    return __Y;
>  }
>
> --- gcc/config/i386/avxintrin.h.jj      2022-01-11 23:11:21.763298965 +0100
> +++ gcc/config/i386/avxintrin.h 2023-01-12 15:34:15.395711408 +0100
> @@ -1207,21 +1207,30 @@ _mm256_movemask_ps (__m256 __A)
>  extern __inline __m256d __attribute__((__gnu_inline__, __always_inline__, __artificial__))
>  _mm256_undefined_pd (void)
>  {
> +#pragma GCC diagnostic push
> +#pragma GCC diagnostic ignored "-Winit-self"
>    __m256d __Y = __Y;
> +#pragma GCC diagnostic pop
>    return __Y;
>  }
>
>  extern __inline __m256 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
>  _mm256_undefined_ps (void)
>  {
> +#pragma GCC diagnostic push
> +#pragma GCC diagnostic ignored "-Winit-self"
>    __m256 __Y = __Y;
> +#pragma GCC diagnostic pop
>    return __Y;
>  }
>
>  extern __inline __m256i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
>  _mm256_undefined_si256 (void)
>  {
> +#pragma GCC diagnostic push
> +#pragma GCC diagnostic ignored "-Winit-self"
>    __m256i __Y = __Y;
> +#pragma GCC diagnostic pop
>    return __Y;
>  }
>
> --- gcc/config/i386/avx512fintrin.h.jj  2022-04-25 13:54:38.277309716 +0200
> +++ gcc/config/i386/avx512fintrin.h     2023-01-12 15:35:09.868928035 +0100
> @@ -185,7 +185,10 @@ extern __inline __m512
>  __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
>  _mm512_undefined_ps (void)
>  {
> +#pragma GCC diagnostic push
> +#pragma GCC diagnostic ignored "-Winit-self"
>    __m512 __Y = __Y;
> +#pragma GCC diagnostic pop
>    return __Y;
>  }
>
> @@ -195,7 +198,10 @@ extern __inline __m512d
>  __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
>  _mm512_undefined_pd (void)
>  {
> +#pragma GCC diagnostic push
> +#pragma GCC diagnostic ignored "-Winit-self"
>    __m512d __Y = __Y;
> +#pragma GCC diagnostic pop
>    return __Y;
>  }
>
> @@ -203,7 +209,10 @@ extern __inline __m512i
>  __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
>  _mm512_undefined_epi32 (void)
>  {
> +#pragma GCC diagnostic push
> +#pragma GCC diagnostic ignored "-Winit-self"
>    __m512i __Y = __Y;
> +#pragma GCC diagnostic pop
>    return __Y;
>  }
>
> --- gcc/config/i386/avx512fp16intrin.h.jj       2022-11-21 10:28:24.284544313 +0100
> +++ gcc/config/i386/avx512fp16intrin.h  2023-01-12 15:35:41.070479329 +0100
> @@ -204,7 +204,10 @@ extern __inline __m128h
>  __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
>  _mm_undefined_ph (void)
>  {
> +#pragma GCC diagnostic push
> +#pragma GCC diagnostic ignored "-Winit-self"
>    __m128h __Y = __Y;
> +#pragma GCC diagnostic pop
>    return __Y;
>  }
>
> @@ -212,7 +215,10 @@ extern __inline __m256h
>  __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
>  _mm256_undefined_ph (void)
>  {
> +#pragma GCC diagnostic push
> +#pragma GCC diagnostic ignored "-Winit-self"
>    __m256h __Y = __Y;
> +#pragma GCC diagnostic pop
>    return __Y;
>  }
>
> @@ -220,7 +226,10 @@ extern __inline __m512h
>  __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
>  _mm512_undefined_ph (void)
>  {
> +#pragma GCC diagnostic push
> +#pragma GCC diagnostic ignored "-Winit-self"
>    __m512h __Y = __Y;
> +#pragma GCC diagnostic pop
>    return __Y;
>  }
>
> --- gcc/testsuite/g++.target/i386/pr105593.C.jj 2023-01-12 15:58:59.668363504 +0100
> +++ gcc/testsuite/g++.target/i386/pr105593.C    2023-01-12 16:01:17.785377769 +0100
> @@ -0,0 +1,20 @@
> +// PR c++/105593
> +// { dg-do compile { target c++14 } }
> +// { dg-options "-mavx512fp16 -W -Wall -O2" }
> +
> +#include <x86intrin.h>
> +
> +auto f1 () { return _mm_undefined_pd (); }
> +auto f2 () { return _mm_undefined_ps (); }
> +auto f3 () { return _mm_undefined_si128 (); }
> +auto f4 () { return _mm_undefined_ph (); }
> +auto f5 () { return _mm256_undefined_pd (); }
> +auto f6 () { return _mm256_undefined_ps (); }
> +auto f7 () { return _mm256_undefined_si256 (); }
> +auto f8 () { return _mm256_undefined_ph (); }
> +auto f9 () { return _mm512_undefined_pd (); }
> +auto f10 () { return _mm512_undefined_ps (); }
> +auto f11 () { return _mm512_undefined_epi32 (); }
> +auto f12 () { return _mm512_undefined_ph (); }
> +
> +// { dg-bogus "is used uninitialized" "" { target *-*-* } 0 }
>
>         Jakub
>
  

Patch

--- gcc/config/i386/xmmintrin.h.jj	2022-11-07 10:30:42.741629972 +0100
+++ gcc/config/i386/xmmintrin.h	2023-01-12 15:33:21.685483809 +0100
@@ -112,7 +112,10 @@  typedef float __v4sf __attribute__ ((__v
 extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
 _mm_undefined_ps (void)
 {
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Winit-self"
   __m128 __Y = __Y;
+#pragma GCC diagnostic pop
   return __Y;
 }
 
--- gcc/config/i386/emmintrin.h.jj	2022-03-14 14:48:04.299055735 +0100
+++ gcc/config/i386/emmintrin.h	2023-01-12 15:33:04.148735997 +0100
@@ -99,7 +99,10 @@  _mm_setr_pd (double __W, double __X)
 extern __inline __m128d __attribute__((__gnu_inline__, __always_inline__, __artificial__))
 _mm_undefined_pd (void)
 {
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Winit-self"
   __m128d __Y = __Y;
+#pragma GCC diagnostic pop
   return __Y;
 }
 
@@ -785,7 +788,10 @@  _mm_move_epi64 (__m128i __A)
 extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
 _mm_undefined_si128 (void)
 {
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Winit-self"
   __m128i __Y = __Y;
+#pragma GCC diagnostic pop
   return __Y;
 }
 
--- gcc/config/i386/avxintrin.h.jj	2022-01-11 23:11:21.763298965 +0100
+++ gcc/config/i386/avxintrin.h	2023-01-12 15:34:15.395711408 +0100
@@ -1207,21 +1207,30 @@  _mm256_movemask_ps (__m256 __A)
 extern __inline __m256d __attribute__((__gnu_inline__, __always_inline__, __artificial__))
 _mm256_undefined_pd (void)
 {
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Winit-self"
   __m256d __Y = __Y;
+#pragma GCC diagnostic pop
   return __Y;
 }
 
 extern __inline __m256 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
 _mm256_undefined_ps (void)
 {
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Winit-self"
   __m256 __Y = __Y;
+#pragma GCC diagnostic pop
   return __Y;
 }
 
 extern __inline __m256i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
 _mm256_undefined_si256 (void)
 {
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Winit-self"
   __m256i __Y = __Y;
+#pragma GCC diagnostic pop
   return __Y;
 }
 
--- gcc/config/i386/avx512fintrin.h.jj	2022-04-25 13:54:38.277309716 +0200
+++ gcc/config/i386/avx512fintrin.h	2023-01-12 15:35:09.868928035 +0100
@@ -185,7 +185,10 @@  extern __inline __m512
 __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
 _mm512_undefined_ps (void)
 {
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Winit-self"
   __m512 __Y = __Y;
+#pragma GCC diagnostic pop
   return __Y;
 }
 
@@ -195,7 +198,10 @@  extern __inline __m512d
 __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
 _mm512_undefined_pd (void)
 {
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Winit-self"
   __m512d __Y = __Y;
+#pragma GCC diagnostic pop
   return __Y;
 }
 
@@ -203,7 +209,10 @@  extern __inline __m512i
 __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
 _mm512_undefined_epi32 (void)
 {
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Winit-self"
   __m512i __Y = __Y;
+#pragma GCC diagnostic pop
   return __Y;
 }
 
--- gcc/config/i386/avx512fp16intrin.h.jj	2022-11-21 10:28:24.284544313 +0100
+++ gcc/config/i386/avx512fp16intrin.h	2023-01-12 15:35:41.070479329 +0100
@@ -204,7 +204,10 @@  extern __inline __m128h
 __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
 _mm_undefined_ph (void)
 {
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Winit-self"
   __m128h __Y = __Y;
+#pragma GCC diagnostic pop
   return __Y;
 }
 
@@ -212,7 +215,10 @@  extern __inline __m256h
 __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
 _mm256_undefined_ph (void)
 {
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Winit-self"
   __m256h __Y = __Y;
+#pragma GCC diagnostic pop
   return __Y;
 }
 
@@ -220,7 +226,10 @@  extern __inline __m512h
 __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
 _mm512_undefined_ph (void)
 {
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Winit-self"
   __m512h __Y = __Y;
+#pragma GCC diagnostic pop
   return __Y;
 }
 
--- gcc/testsuite/g++.target/i386/pr105593.C.jj	2023-01-12 15:58:59.668363504 +0100
+++ gcc/testsuite/g++.target/i386/pr105593.C	2023-01-12 16:01:17.785377769 +0100
@@ -0,0 +1,20 @@ 
+// PR c++/105593
+// { dg-do compile { target c++14 } }
+// { dg-options "-mavx512fp16 -W -Wall -O2" }
+
+#include <x86intrin.h>
+
+auto f1 () { return _mm_undefined_pd (); }
+auto f2 () { return _mm_undefined_ps (); }
+auto f3 () { return _mm_undefined_si128 (); }
+auto f4 () { return _mm_undefined_ph (); }
+auto f5 () { return _mm256_undefined_pd (); }
+auto f6 () { return _mm256_undefined_ps (); }
+auto f7 () { return _mm256_undefined_si256 (); }
+auto f8 () { return _mm256_undefined_ph (); }
+auto f9 () { return _mm512_undefined_pd (); }
+auto f10 () { return _mm512_undefined_ps (); }
+auto f11 () { return _mm512_undefined_epi32 (); }
+auto f12 () { return _mm512_undefined_ph (); }
+
+// { dg-bogus "is used uninitialized" "" { target *-*-* } 0 }