[2/3] amdgcn: OpenMP SIMD routine support

Message ID ce4e830f2bd38454020309a366d4e09abe12290f.1660051134.git.ams@codesourcery.com
State New, archived
Headers
Series OpenMP SIMD routines |

Commit Message

Andrew Stubbs Aug. 9, 2022, 1:23 p.m. UTC
  Enable and configure SIMD clones for amdgcn.  This affects both the __simd__
function attribute, and the OpenMP "declare simd" directive.

Note that the masked SIMD variants are generated, but the middle end doesn't
actually support calling them yet.

gcc/ChangeLog:

	* config/gcn/gcn.cc (gcn_simd_clone_compute_vecsize_and_simdlen): New.
	(gcn_simd_clone_adjust): New.
	(gcn_simd_clone_usable): New.
	(TARGET_SIMD_CLONE_ADJUST): New.
	(TARGET_SIMD_CLONE_COMPUTE_VECSIZE_AND_SIMDLEN): New.
	(TARGET_SIMD_CLONE_USABLE): New.

gcc/testsuite/ChangeLog:

	* gcc.dg/vect/vect-simd-clone-1.c: Add dg-warning.
	* gcc.dg/vect/vect-simd-clone-2.c: Add dg-warning.
	* gcc.dg/vect/vect-simd-clone-3.c: Add dg-warning.
	* gcc.dg/vect/vect-simd-clone-4.c: Add dg-warning.
	* gcc.dg/vect/vect-simd-clone-5.c: Add dg-warning.
	* gcc.dg/vect/vect-simd-clone-8.c: Add dg-warning.
---
 gcc/config/gcn/gcn.cc                         | 63 +++++++++++++++++++
 gcc/testsuite/gcc.dg/vect/vect-simd-clone-1.c |  2 +
 gcc/testsuite/gcc.dg/vect/vect-simd-clone-2.c |  2 +
 gcc/testsuite/gcc.dg/vect/vect-simd-clone-3.c |  1 +
 gcc/testsuite/gcc.dg/vect/vect-simd-clone-4.c |  1 +
 gcc/testsuite/gcc.dg/vect/vect-simd-clone-5.c |  1 +
 gcc/testsuite/gcc.dg/vect/vect-simd-clone-8.c |  2 +
 7 files changed, 72 insertions(+)
  

Comments

Andrew Stubbs Aug. 30, 2022, 2:53 p.m. UTC | #1
On 09/08/2022 14:23, Andrew Stubbs wrote:
> 
> Enable and configure SIMD clones for amdgcn.  This affects both the __simd__
> function attribute, and the OpenMP "declare simd" directive.
> 
> Note that the masked SIMD variants are generated, but the middle end doesn't
> actually support calling them yet.
> 
> gcc/ChangeLog:
> 
> 	* config/gcn/gcn.cc (gcn_simd_clone_compute_vecsize_and_simdlen): New.
> 	(gcn_simd_clone_adjust): New.
> 	(gcn_simd_clone_usable): New.
> 	(TARGET_SIMD_CLONE_ADJUST): New.
> 	(TARGET_SIMD_CLONE_COMPUTE_VECSIZE_AND_SIMDLEN): New.
> 	(TARGET_SIMD_CLONE_USABLE): New.
> 
> gcc/testsuite/ChangeLog:
> 
> 	* gcc.dg/vect/vect-simd-clone-1.c: Add dg-warning.
> 	* gcc.dg/vect/vect-simd-clone-2.c: Add dg-warning.
> 	* gcc.dg/vect/vect-simd-clone-3.c: Add dg-warning.
> 	* gcc.dg/vect/vect-simd-clone-4.c: Add dg-warning.
> 	* gcc.dg/vect/vect-simd-clone-5.c: Add dg-warning.
> 	* gcc.dg/vect/vect-simd-clone-8.c: Add dg-warning.

The dependency was approved, so this is now committed.

Andrew
  

Patch

diff --git a/gcc/config/gcn/gcn.cc b/gcc/config/gcn/gcn.cc
index 96295e23aad..ceb69000807 100644
--- a/gcc/config/gcn/gcn.cc
+++ b/gcc/config/gcn/gcn.cc
@@ -52,6 +52,7 @@ 
 #include "rtl-iter.h"
 #include "dwarf2.h"
 #include "gimple.h"
+#include "cgraph.h"
 
 /* This file should be included last.  */
 #include "target-def.h"
@@ -4555,6 +4556,61 @@  gcn_vectorization_cost (enum vect_cost_for_stmt ARG_UNUSED (type_of_cost),
   return 1;
 }
 
+/* Implement TARGET_SIMD_CLONE_COMPUTE_VECSIZE_AND_SIMDLEN.  */
+
+static int
+gcn_simd_clone_compute_vecsize_and_simdlen (struct cgraph_node *ARG_UNUSED (node),
+					    struct cgraph_simd_clone *clonei,
+					    tree base_type,
+					    int ARG_UNUSED (num))
+{
+  unsigned int elt_bits = GET_MODE_BITSIZE (SCALAR_TYPE_MODE (base_type));
+
+  if (known_eq (clonei->simdlen, 0U))
+    clonei->simdlen = 64;
+  else if (maybe_ne (clonei->simdlen, 64U))
+    {
+      /* Note that x86 has a similar message that is likely to trigger on
+	 sizes that are OK for gcn; the user can't win.  */
+      warning_at (DECL_SOURCE_LOCATION (node->decl), 0,
+		  "unsupported simdlen %wd (amdgcn)",
+		  clonei->simdlen.to_constant ());
+      return 0;
+    }
+
+  clonei->vecsize_mangle = 'n';
+  clonei->vecsize_int = 0;
+  clonei->vecsize_float = 0;
+
+  /* DImode ought to be more natural here, but VOIDmode produces better code,
+     at present, due to the shift-and-test steps not being optimized away
+     inside the in-branch clones.  */
+  clonei->mask_mode = VOIDmode;
+
+  return 1;
+}
+
+/* Implement TARGET_SIMD_CLONE_ADJUST.  */
+
+static void
+gcn_simd_clone_adjust (struct cgraph_node *ARG_UNUSED (node))
+{
+  /* This hook has to be defined when
+     TARGET_SIMD_CLONE_COMPUTE_VECSIZE_AND_SIMDLEN is defined, but we don't
+     need it to do anything yet.  */
+}
+
+/* Implement TARGET_SIMD_CLONE_USABLE.  */
+
+static int
+gcn_simd_clone_usable (struct cgraph_node *ARG_UNUSED (node))
+{
+  /* We don't need to do anything here because
+     gcn_simd_clone_compute_vecsize_and_simdlen currently only returns one
+     possibility.  */
+  return 0;
+}
+
 /* }}}  */
 /* {{{ md_reorg pass.  */
 
@@ -6643,6 +6699,13 @@  gcn_dwarf_register_span (rtx rtl)
 #define TARGET_SECTION_TYPE_FLAGS gcn_section_type_flags
 #undef  TARGET_SCALAR_MODE_SUPPORTED_P
 #define TARGET_SCALAR_MODE_SUPPORTED_P gcn_scalar_mode_supported_p
+#undef  TARGET_SIMD_CLONE_ADJUST
+#define TARGET_SIMD_CLONE_ADJUST gcn_simd_clone_adjust
+#undef  TARGET_SIMD_CLONE_COMPUTE_VECSIZE_AND_SIMDLEN
+#define TARGET_SIMD_CLONE_COMPUTE_VECSIZE_AND_SIMDLEN \
+  gcn_simd_clone_compute_vecsize_and_simdlen
+#undef  TARGET_SIMD_CLONE_USABLE
+#define TARGET_SIMD_CLONE_USABLE gcn_simd_clone_usable
 #undef  TARGET_SMALL_REGISTER_CLASSES_FOR_MODE_P
 #define TARGET_SMALL_REGISTER_CLASSES_FOR_MODE_P \
   gcn_small_register_classes_for_mode_p
diff --git a/gcc/testsuite/gcc.dg/vect/vect-simd-clone-1.c b/gcc/testsuite/gcc.dg/vect/vect-simd-clone-1.c
index 50429049500..cd65fc343f1 100644
--- a/gcc/testsuite/gcc.dg/vect/vect-simd-clone-1.c
+++ b/gcc/testsuite/gcc.dg/vect/vect-simd-clone-1.c
@@ -56,3 +56,5 @@  main ()
   return 0;
 }
 
+/* { dg-warning {unsupported simdlen 8 \(amdgcn\)} "" { target amdgcn*-*-* } 18 } */
+/* { dg-warning {unsupported simdlen 4 \(amdgcn\)} "" { target amdgcn*-*-* } 18 } */
diff --git a/gcc/testsuite/gcc.dg/vect/vect-simd-clone-2.c b/gcc/testsuite/gcc.dg/vect/vect-simd-clone-2.c
index f89c73a961b..ffcbf9380d6 100644
--- a/gcc/testsuite/gcc.dg/vect/vect-simd-clone-2.c
+++ b/gcc/testsuite/gcc.dg/vect/vect-simd-clone-2.c
@@ -50,3 +50,5 @@  main ()
   return 0;
 }
 
+/* { dg-warning {unsupported simdlen 8 \(amdgcn\)} "" { target amdgcn*-*-* } 18 } */
+/* { dg-warning {unsupported simdlen 4 \(amdgcn\)} "" { target amdgcn*-*-* } 18 } */
diff --git a/gcc/testsuite/gcc.dg/vect/vect-simd-clone-3.c b/gcc/testsuite/gcc.dg/vect/vect-simd-clone-3.c
index 75ce696ed66..18d68779cc5 100644
--- a/gcc/testsuite/gcc.dg/vect/vect-simd-clone-3.c
+++ b/gcc/testsuite/gcc.dg/vect/vect-simd-clone-3.c
@@ -43,3 +43,4 @@  main ()
   return 0;
 }
 
+/* { dg-warning {unsupported simdlen 4 \(amdgcn\)} "" { target amdgcn*-*-* } 15 } */
diff --git a/gcc/testsuite/gcc.dg/vect/vect-simd-clone-4.c b/gcc/testsuite/gcc.dg/vect/vect-simd-clone-4.c
index debbe77b79d..e9af0b83162 100644
--- a/gcc/testsuite/gcc.dg/vect/vect-simd-clone-4.c
+++ b/gcc/testsuite/gcc.dg/vect/vect-simd-clone-4.c
@@ -46,3 +46,4 @@  main ()
   return 0;
 }
 
+/* { dg-warning {unsupported simdlen 8 \(amdgcn\)} "" { target amdgcn*-*-* } 17 } */
diff --git a/gcc/testsuite/gcc.dg/vect/vect-simd-clone-5.c b/gcc/testsuite/gcc.dg/vect/vect-simd-clone-5.c
index 6a098d9a51a..46da496524d 100644
--- a/gcc/testsuite/gcc.dg/vect/vect-simd-clone-5.c
+++ b/gcc/testsuite/gcc.dg/vect/vect-simd-clone-5.c
@@ -41,3 +41,4 @@  main ()
   return 0;
 }
 
+/* { dg-warning {unsupported simdlen 4 \(amdgcn\)} "" { target amdgcn*-*-* } 15 } */
diff --git a/gcc/testsuite/gcc.dg/vect/vect-simd-clone-8.c b/gcc/testsuite/gcc.dg/vect/vect-simd-clone-8.c
index 1bfd19dc8ab..f414285a170 100644
--- a/gcc/testsuite/gcc.dg/vect/vect-simd-clone-8.c
+++ b/gcc/testsuite/gcc.dg/vect/vect-simd-clone-8.c
@@ -92,3 +92,5 @@  main ()
   return 0;
 }
 
+/* { dg-warning {unsupported simdlen 8 \(amdgcn\)} "" { target amdgcn*-*-* } 17 } */
+/* { dg-warning {unsupported simdlen 8 \(amdgcn\)} "" { target amdgcn*-*-* } 24 } */