public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] rs6000: MMA built-ins reject typedefs of MMA types
@ 2020-08-07 22:16 Peter Bergner
  2020-08-07 23:52 ` Segher Boessenkool
  0 siblings, 1 reply; 5+ messages in thread
From: Peter Bergner @ 2020-08-07 22:16 UTC (permalink / raw)
  To: Segher Boessenkool
  Cc: GCC Patches, Bill Schmidt, Rajalakshmi Srinivasaraghavan

We do not allow conversions between the MMA types and other types.
However, we are being too strict in not matching MMA types with
typdefs of those types.  Use TYPE_CANONICAL to see through the
types to their canonical types before comparing them.

This is currently bootstrapping and regtesting.  Ok for trunk if
tests are clean?   Ok for GCC 10 too, after a couple of days?

Peter


gcc/
	PR target/96530
	* config/rs6000/rs6000.c (rs6000_invalid_conversion): Use canonical
	types for type comparisons.  Refactor code to simplify it.

gcc/testsuite/
	PR target/96530
	* gcc.target/powerpc/pr96530.c: New test.

diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c
index d26a18f3ece..9124796ff76 100644
--- a/gcc/config/rs6000/rs6000.c
+++ b/gcc/config/rs6000/rs6000.c
@@ -26803,34 +26803,48 @@ rs6000_cannot_substitute_mem_equiv_p (rtx mem)
 static const char *
 rs6000_invalid_conversion (const_tree fromtype, const_tree totype)
 {
-  if (element_mode (fromtype) != element_mode (totype))
+  /* Make sure we're working with the canonical types.  */
+  if (TYPE_CANONICAL (fromtype) != NULL_TREE)
+    fromtype = TYPE_CANONICAL (fromtype);
+  if (TYPE_CANONICAL (totype) != NULL_TREE)
+    totype = TYPE_CANONICAL (totype);
+
+  machine_mode frommode = element_mode (fromtype);
+  machine_mode tomode = element_mode (totype);
+
+  if (frommode != tomode)
     {
       /* Do not allow conversions to/from PXImode and POImode types.  */
-      if (TYPE_MODE (fromtype) == PXImode)
+      if (frommode == PXImode)
 	return N_("invalid conversion from type %<__vector_quad%>");
-      if (TYPE_MODE (totype) == PXImode)
+      if (tomode == PXImode)
 	return N_("invalid conversion to type %<__vector_quad%>");
-      if (TYPE_MODE (fromtype) == POImode)
+      if (frommode == POImode)
 	return N_("invalid conversion from type %<__vector_pair%>");
-      if (TYPE_MODE (totype) == POImode)
+      if (tomode == POImode)
 	return N_("invalid conversion to type %<__vector_pair%>");
     }
   else if (POINTER_TYPE_P (fromtype) && POINTER_TYPE_P (totype))
     {
+      /* We really care about the modes of the base types.  */
+      frommode = element_mode (TREE_TYPE (fromtype));
+      tomode = element_mode (TREE_TYPE (totype));
+
       /* Do not allow conversions to/from PXImode and POImode pointer
 	 types, except to/from void pointers.  */
-      if (TYPE_MODE (TREE_TYPE (fromtype)) == PXImode
-	  && TYPE_MODE (TREE_TYPE (totype)) != VOIDmode)
-	return N_("invalid conversion from type %<* __vector_quad%>");
-      if (TYPE_MODE (TREE_TYPE (totype)) == PXImode
-	  && TYPE_MODE (TREE_TYPE (fromtype)) != VOIDmode)
-	return N_("invalid conversion to type %<* __vector_quad%>");
-      if (TYPE_MODE (TREE_TYPE (fromtype)) == POImode
-	  && TYPE_MODE (TREE_TYPE (totype)) != VOIDmode)
-	return N_("invalid conversion from type %<* __vector_pair%>");
-      if (TYPE_MODE (TREE_TYPE (totype)) == POImode
-	  && TYPE_MODE (TREE_TYPE (fromtype)) != VOIDmode)
-	return N_("invalid conversion to type %<* __vector_pair%>");
+      if (frommode != tomode
+	  && frommode != VOIDmode
+	  && tomode != VOIDmode)
+	{
+	  if (frommode == PXImode)
+	    return N_("invalid conversion from type %<* __vector_quad%>");
+	  if (tomode == PXImode)
+	    return N_("invalid conversion to type %<* __vector_quad%>");
+	  if (frommode == POImode)
+	    return N_("invalid conversion from type %<* __vector_pair%>");
+	  if (tomode == POImode)
+	    return N_("invalid conversion to type %<* __vector_pair%>");
+	}
     }
 
   /* Conversion allowed.  */
diff --git a/gcc/testsuite/gcc.target/powerpc/pr96530.c b/gcc/testsuite/gcc.target/powerpc/pr96530.c
new file mode 100644
index 00000000000..29bb9e3cc53
--- /dev/null
+++ b/gcc/testsuite/gcc.target/powerpc/pr96530.c
@@ -0,0 +1,20 @@
+/* PR target/96530 */
+/* { dg-do compile } */
+/* { dg-require-effective-target power10_ok } */
+/* { dg-options "-mdejagnu-cpu=power10 -O2" } */
+
+/* Verify we do not reject bar() below due to the typedef.  */
+
+typedef __vector_quad vquad_t;
+
+void
+foo (__vector_quad *dst)
+{
+  __builtin_mma_xxsetaccz (dst);
+}
+
+void
+bar (vquad_t *dst)
+{
+  __builtin_mma_xxsetaccz (dst);
+}

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] rs6000: MMA built-ins reject typedefs of MMA types
  2020-08-07 22:16 [PATCH] rs6000: MMA built-ins reject typedefs of MMA types Peter Bergner
@ 2020-08-07 23:52 ` Segher Boessenkool
  2020-08-08  1:59   ` Peter Bergner
  0 siblings, 1 reply; 5+ messages in thread
From: Segher Boessenkool @ 2020-08-07 23:52 UTC (permalink / raw)
  To: Peter Bergner; +Cc: GCC Patches, Bill Schmidt, Rajalakshmi Srinivasaraghavan

Hi!

On Fri, Aug 07, 2020 at 05:16:30PM -0500, Peter Bergner wrote:
> We do not allow conversions between the MMA types and other types.
> However, we are being too strict in not matching MMA types with
> typdefs of those types.  Use TYPE_CANONICAL to see through the
> types to their canonical types before comparing them.

> --- a/gcc/config/rs6000/rs6000.c
> +++ b/gcc/config/rs6000/rs6000.c
> @@ -26803,34 +26803,48 @@ rs6000_cannot_substitute_mem_equiv_p (rtx mem)
>  static const char *
>  rs6000_invalid_conversion (const_tree fromtype, const_tree totype)
>  {
> -  if (element_mode (fromtype) != element_mode (totype))
> +  /* Make sure we're working with the canonical types.  */
> +  if (TYPE_CANONICAL (fromtype) != NULL_TREE)
> +    fromtype = TYPE_CANONICAL (fromtype);
> +  if (TYPE_CANONICAL (totype) != NULL_TREE)
> +    totype = TYPE_CANONICAL (totype);
> +
> +  machine_mode frommode = element_mode (fromtype);
> +  machine_mode tomode = element_mode (totype);
> +
> +  if (frommode != tomode)
>      {
>        /* Do not allow conversions to/from PXImode and POImode types.  */
> -      if (TYPE_MODE (fromtype) == PXImode)
> +      if (frommode == PXImode)

The element_mode vs. TYPE_MODE here does not matter, because we never
deal with vector modes here, and they will error elsewhere anyway?

Okay for trunk if that is true (or with the necessary adjustments), and
okay for 10 after letting it soak for a bit.  Thanks!


Segher

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] rs6000: MMA built-ins reject typedefs of MMA types
  2020-08-07 23:52 ` Segher Boessenkool
@ 2020-08-08  1:59   ` Peter Bergner
  2020-08-08 16:59     ` Peter Bergner
  0 siblings, 1 reply; 5+ messages in thread
From: Peter Bergner @ 2020-08-08  1:59 UTC (permalink / raw)
  To: Segher Boessenkool
  Cc: GCC Patches, Bill Schmidt, Rajalakshmi Srinivasaraghavan

On 8/7/20 6:52 PM, Segher Boessenkool wrote:
> The element_mode vs. TYPE_MODE here does not matter, because we never
> deal with vector modes here, and they will error elsewhere anyway?

Agreed, TYPE_MODE is fine here.


> Okay for trunk if that is true (or with the necessary adjustments), and
> okay for 10 after letting it soak for a bit.  Thanks!

Ok, I did s/element_mode/TYPE_MODE/g here and am retesting.
I'll commit it once regtesting comes back clean.  Thanks!

Peter



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] rs6000: MMA built-ins reject typedefs of MMA types
  2020-08-08  1:59   ` Peter Bergner
@ 2020-08-08 16:59     ` Peter Bergner
  2020-08-10  3:13       ` Peter Bergner
  0 siblings, 1 reply; 5+ messages in thread
From: Peter Bergner @ 2020-08-08 16:59 UTC (permalink / raw)
  To: Segher Boessenkool
  Cc: GCC Patches, Bill Schmidt, Rajalakshmi Srinivasaraghavan

On 8/7/20 8:59 PM, Peter Bergner wrote:
> On 8/7/20 6:52 PM, Segher Boessenkool wrote:
>> Okay for trunk if that is true (or with the necessary adjustments), and
>> okay for 10 after letting it soak for a bit.  Thanks!
> 
> Ok, I did s/element_mode/TYPE_MODE/g here and am retesting.
> I'll commit it once regtesting comes back clean.  Thanks!

Testing was clean, so I pushed this to trunk.  Will wait before
backporting.  Thanks!

Peter



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] rs6000: MMA built-ins reject typedefs of MMA types
  2020-08-08 16:59     ` Peter Bergner
@ 2020-08-10  3:13       ` Peter Bergner
  0 siblings, 0 replies; 5+ messages in thread
From: Peter Bergner @ 2020-08-10  3:13 UTC (permalink / raw)
  To: Segher Boessenkool
  Cc: GCC Patches, Bill Schmidt, Rajalakshmi Srinivasaraghavan

On 8/8/20 11:59 AM, Peter Bergner wrote:
> Testing was clean, so I pushed this to trunk.  Will wait before
> backporting.  Thanks!

Scanning through Bill Seurer's testsuite runs for POWER, I see no fallout,
so I have pushed this to the GCC 10 branch.

Peter



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-08-10  3:13 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-07 22:16 [PATCH] rs6000: MMA built-ins reject typedefs of MMA types Peter Bergner
2020-08-07 23:52 ` Segher Boessenkool
2020-08-08  1:59   ` Peter Bergner
2020-08-08 16:59     ` Peter Bergner
2020-08-10  3:13       ` Peter Bergner

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