public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Hongtao Liu <crazylht@gmail.com>
To: Richard Biener <richard.guenther@gmail.com>
Cc: liuhongt <hongtao.liu@intel.com>,
	Richard Sandiford <richard.sandiford@arm.com>,
	 GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] Check the type of mask while generating cond_op in gimple simplication.
Date: Tue, 31 Aug 2021 18:24:31 +0800	[thread overview]
Message-ID: <CAMZc-bxR35bTV_SdjGe8=Vb6BUZ5TuLOmjwuGfF9kRcjqoB3LA@mail.gmail.com> (raw)
In-Reply-To: <CAFiYyc3Ox08Qq1XONJQf1WBEokoeGb1ycWmiYuN03U4QvxRCdA@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 7354 bytes --]

On Mon, Aug 30, 2021 at 8:25 PM Richard Biener via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> On Fri, Aug 27, 2021 at 8:53 AM liuhongt <hongtao.liu@intel.com> wrote:
> >
> >   When gimple simplifcation try to combine op and vec_cond_expr to cond_op,
> > it doesn't check if mask type matches. It causes an ICE when expand cond_op
> > with mismatched mode.
> >   This patch add a function named cond_vectorized_internal_fn_supported_p
> >  to additionally check mask type than vectorized_internal_fn_supported_p.
> >
> >   Bootstrapped and regtested on x86_64-linux-gnu{-m32,}.
> >   Ok for trunk?
> >
> > gcc/ChangeLog:
> >
> >         PR middle-end/102080
> >         * internal-fn.c (cond_vectorized_internal_fn_supported_p): New functions.
> >         * internal-fn.h (cond_vectorized_internal_fn_supported_p): New declaration.
> >         * match.pd: Check the type of mask while generating cond_op in
> >         gimple simplication.
> >
> > gcc/testsuite/ChangeLog:
> >
> >         PR middle-end/102080
> >         * gcc.target/i386/pr102080.c: New test.
> > ---
> >  gcc/internal-fn.c                        | 22 ++++++++++++++++++++++
> >  gcc/internal-fn.h                        |  1 +
> >  gcc/match.pd                             | 24 ++++++++++++++++--------
> >  gcc/testsuite/gcc.target/i386/pr102080.c | 16 ++++++++++++++++
> >  4 files changed, 55 insertions(+), 8 deletions(-)
> >  create mode 100644 gcc/testsuite/gcc.target/i386/pr102080.c
> >
> > diff --git a/gcc/internal-fn.c b/gcc/internal-fn.c
> > index 1360a00f0b9..8b2b65db1a7 100644
> > --- a/gcc/internal-fn.c
> > +++ b/gcc/internal-fn.c
> > @@ -4102,6 +4102,28 @@ expand_internal_call (gcall *stmt)
> >    expand_internal_call (gimple_call_internal_fn (stmt), stmt);
> >  }
> >
> > +/* Check cond_op for vector modes since vectorized_internal_fn_supported_p
> > +   doesn't check if mask type matches.  */
> > +bool
> > +cond_vectorized_internal_fn_supported_p (internal_fn ifn, tree type,
> > +                                        tree mask_type)
> > +{
> > +  if (!vectorized_internal_fn_supported_p (ifn, type))
> > +    return false;
> > +
> > +  machine_mode mask_mode;
> > +  machine_mode vmode = TYPE_MODE (type);
> > +  int size1, size2;
> > +  if (VECTOR_MODE_P (vmode)
> > +      && targetm.vectorize.get_mask_mode (vmode).exists(&mask_mode)
> > +      && GET_MODE_SIZE (mask_mode).is_constant (&size1)
> > +      && GET_MODE_SIZE (TYPE_MODE (mask_type)).is_constant (&size2)
> > +      && size1 != size2)
>
> Why do we check for equal size rather than just mode equality which
I originally thought  TYPE_MODE of vector(8) <signed-boolean:1> was
not QImode, Changed the patch to check mode equality.
Update patch.

> I think would work for non-constant sized modes as well?  And when
> using sizes you'd instead use maybe_ne (GET_MODE_SIZE (mask_mode),
> GET_MODE_SIZE (TYPE_MODE (mask_type)))
>
> Thanks,
> Richard.
>
> > +    return false;
> > +
> > +  return true;
> > +}
> > +
> >  /* If TYPE is a vector type, return true if IFN is a direct internal
> >     function that is supported for that type.  If TYPE is a scalar type,
> >     return true if IFN is a direct internal function that is supported for
> > diff --git a/gcc/internal-fn.h b/gcc/internal-fn.h
> > index 19d0f849a5a..f0aea00103c 100644
> > --- a/gcc/internal-fn.h
> > +++ b/gcc/internal-fn.h
> > @@ -236,5 +236,6 @@ extern void expand_PHI (internal_fn, gcall *);
> >  extern void expand_SHUFFLEVECTOR (internal_fn, gcall *);
> >
> >  extern bool vectorized_internal_fn_supported_p (internal_fn, tree);
> > +extern bool cond_vectorized_internal_fn_supported_p (internal_fn, tree, tree);
> >
> >  #endif
> > diff --git a/gcc/match.pd b/gcc/match.pd
> > index e5bbb123a6a..72b1bc674db 100644
> > --- a/gcc/match.pd
> > +++ b/gcc/match.pd
> > @@ -6987,14 +6987,18 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
> >       cond_op (COND_BINARY)
> >   (simplify
> >    (vec_cond @0 (view_convert? (uncond_op@4 @1 @2)) @3)
> > -  (with { tree op_type = TREE_TYPE (@4); }
> > -   (if (vectorized_internal_fn_supported_p (as_internal_fn (cond_op), op_type)
> > +  (with { tree op_type = TREE_TYPE (@4);
> > +         tree mask_type = TREE_TYPE (@0); }
> > +   (if (cond_vectorized_internal_fn_supported_p (as_internal_fn (cond_op),
> > +                                                op_type, mask_type)
> >         && element_precision (type) == element_precision (op_type))
> >      (view_convert (cond_op @0 @1 @2 (view_convert:op_type @3))))))
> >   (simplify
> >    (vec_cond @0 @1 (view_convert? (uncond_op@4 @2 @3)))
> > -  (with { tree op_type = TREE_TYPE (@4); }
> > -   (if (vectorized_internal_fn_supported_p (as_internal_fn (cond_op), op_type)
> > +  (with { tree op_type = TREE_TYPE (@4);
> > +         tree mask_type = TREE_TYPE (@0); }
> > +   (if (cond_vectorized_internal_fn_supported_p (as_internal_fn (cond_op),
> > +                                                op_type, mask_type)
> >         && element_precision (type) == element_precision (op_type))
> >      (view_convert (cond_op (bit_not @0) @2 @3 (view_convert:op_type @1)))))))
> >
> > @@ -7003,14 +7007,18 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
> >       cond_op (COND_TERNARY)
> >   (simplify
> >    (vec_cond @0 (view_convert? (uncond_op@5 @1 @2 @3)) @4)
> > -  (with { tree op_type = TREE_TYPE (@5); }
> > -   (if (vectorized_internal_fn_supported_p (as_internal_fn (cond_op), op_type)
> > +  (with { tree op_type = TREE_TYPE (@5);
> > +         tree mask_type = TREE_TYPE (@0); }
> > +   (if (cond_vectorized_internal_fn_supported_p (as_internal_fn (cond_op),
> > +                                                op_type, mask_type)
> >         && element_precision (type) == element_precision (op_type))
> >      (view_convert (cond_op @0 @1 @2 @3 (view_convert:op_type @4))))))
> >   (simplify
> >    (vec_cond @0 @1 (view_convert? (uncond_op@5 @2 @3 @4)))
> > -  (with { tree op_type = TREE_TYPE (@5); }
> > -   (if (vectorized_internal_fn_supported_p (as_internal_fn (cond_op), op_type)
> > +  (with { tree op_type = TREE_TYPE (@5);
> > +         tree mask_type = TREE_TYPE (@0); }
> > +   (if (cond_vectorized_internal_fn_supported_p (as_internal_fn (cond_op),
> > +                                                op_type, mask_type)
> >         && element_precision (type) == element_precision (op_type))
> >      (view_convert (cond_op (bit_not @0) @2 @3 @4
> >                   (view_convert:op_type @1)))))))
> > diff --git a/gcc/testsuite/gcc.target/i386/pr102080.c b/gcc/testsuite/gcc.target/i386/pr102080.c
> > new file mode 100644
> > index 00000000000..6a40a75e1c5
> > --- /dev/null
> > +++ b/gcc/testsuite/gcc.target/i386/pr102080.c
> > @@ -0,0 +1,16 @@
> > +#include<immintrin.h>
> > +typedef float __m256 __attribute__((__vector_size__(32)));
> > +__m256 _mm256_blendv_ps___Y, _mm256_blendv_ps___M, _mm256_mul_ps___A,
> > +  _mm256_mul_ps___B, IfThenElse___trans_tmp_9;
> > +
> > +void
> > +__attribute__ ((target("avx")))
> > +IfThenElse (__m256 no) {
> > +  IfThenElse___trans_tmp_9 = _mm256_blendv_ps (no, _mm256_blendv_ps___Y, _mm256_blendv_ps___M);
> > +}
> > +void
> > +__attribute__ ((target("avx512vl")))
> > +EncodedFromDisplay() {
> > +  __m256 __trans_tmp_11 = _mm256_mul_ps___A * _mm256_mul_ps___B;
> > +  IfThenElse(__trans_tmp_11);
> > +}
> > --
> > 2.18.1
> >



-- 
BR,
Hongtao

[-- Attachment #2: 0001-Check-the-type-of-mask-while-generating-cond_op-in-g.patch --]
[-- Type: text/x-patch, Size: 5654 bytes --]

From 5ace48ad0f30d234e3f2e25503a4f041138b4952 Mon Sep 17 00:00:00 2001
From: liuhongt <hongtao.liu@intel.com>
Date: Fri, 27 Aug 2021 12:50:13 +0800
Subject: [PATCH] Check the type of mask while generating cond_op in gimple
 simplication.

gcc/ChangeLog:

	PR middle-end/102080
	* internal-fn.c (cond_vectorized_internal_fn_supported_p): New functions.
	* internal-fn.h (cond_vectorized_internal_fn_supported_p): New declaration.
	* match.pd: Check the type of mask while generating cond_op in
	gimple simplication.

gcc/testsuite/ChangeLog:

	PR middle-end/102080
	* gcc.target/i386/pr102080.c: New test.
---
 gcc/internal-fn.c                        | 20 ++++++++++++++++++++
 gcc/internal-fn.h                        |  1 +
 gcc/match.pd                             | 24 ++++++++++++++++--------
 gcc/testsuite/gcc.target/i386/pr102080.c | 19 +++++++++++++++++++
 4 files changed, 56 insertions(+), 8 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/i386/pr102080.c

diff --git a/gcc/internal-fn.c b/gcc/internal-fn.c
index 1360a00f0b9..7f643f545d9 100644
--- a/gcc/internal-fn.c
+++ b/gcc/internal-fn.c
@@ -4102,6 +4102,26 @@ expand_internal_call (gcall *stmt)
   expand_internal_call (gimple_call_internal_fn (stmt), stmt);
 }
 
+/* Check cond_op for vector modes since vectorized_internal_fn_supported_p
+   doesn't check if mask type matches.  */
+bool
+cond_vectorized_internal_fn_supported_p (internal_fn ifn, tree type,
+					 tree mask_type)
+{
+  if (!vectorized_internal_fn_supported_p (ifn, type))
+    return false;
+
+  machine_mode mask_mode;
+  machine_mode vmode = TYPE_MODE (type);
+  int size1, size2;
+  if (VECTOR_MODE_P (vmode)
+      && targetm.vectorize.get_mask_mode (vmode).exists(&mask_mode)
+      && mask_mode != TYPE_MODE (mask_type))
+    return false;
+
+  return true;
+}
+
 /* If TYPE is a vector type, return true if IFN is a direct internal
    function that is supported for that type.  If TYPE is a scalar type,
    return true if IFN is a direct internal function that is supported for
diff --git a/gcc/internal-fn.h b/gcc/internal-fn.h
index 19d0f849a5a..f0aea00103c 100644
--- a/gcc/internal-fn.h
+++ b/gcc/internal-fn.h
@@ -236,5 +236,6 @@ extern void expand_PHI (internal_fn, gcall *);
 extern void expand_SHUFFLEVECTOR (internal_fn, gcall *);
 
 extern bool vectorized_internal_fn_supported_p (internal_fn, tree);
+extern bool cond_vectorized_internal_fn_supported_p (internal_fn, tree, tree);
 
 #endif
diff --git a/gcc/match.pd b/gcc/match.pd
index f421c74b62c..ded68ec6c71 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -6986,14 +6986,18 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
      cond_op (COND_BINARY)
  (simplify
   (vec_cond @0 (view_convert? (uncond_op@4 @1 @2)) @3)
-  (with { tree op_type = TREE_TYPE (@4); }
-   (if (vectorized_internal_fn_supported_p (as_internal_fn (cond_op), op_type)
+  (with { tree op_type = TREE_TYPE (@4);
+	  tree mask_type = TREE_TYPE (@0); }
+   (if (cond_vectorized_internal_fn_supported_p (as_internal_fn (cond_op),
+						 op_type, mask_type)
 	&& element_precision (type) == element_precision (op_type))
     (view_convert (cond_op @0 @1 @2 (view_convert:op_type @3))))))
  (simplify
   (vec_cond @0 @1 (view_convert? (uncond_op@4 @2 @3)))
-  (with { tree op_type = TREE_TYPE (@4); }
-   (if (vectorized_internal_fn_supported_p (as_internal_fn (cond_op), op_type)
+  (with { tree op_type = TREE_TYPE (@4);
+	  tree mask_type = TREE_TYPE (@0); }
+   (if (cond_vectorized_internal_fn_supported_p (as_internal_fn (cond_op),
+						 op_type, mask_type)
 	&& element_precision (type) == element_precision (op_type))
     (view_convert (cond_op (bit_not @0) @2 @3 (view_convert:op_type @1)))))))
 
@@ -7002,14 +7006,18 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
      cond_op (COND_TERNARY)
  (simplify
   (vec_cond @0 (view_convert? (uncond_op@5 @1 @2 @3)) @4)
-  (with { tree op_type = TREE_TYPE (@5); }
-   (if (vectorized_internal_fn_supported_p (as_internal_fn (cond_op), op_type)
+  (with { tree op_type = TREE_TYPE (@5);
+	  tree mask_type = TREE_TYPE (@0); }
+   (if (cond_vectorized_internal_fn_supported_p (as_internal_fn (cond_op),
+						 op_type, mask_type)
 	&& element_precision (type) == element_precision (op_type))
     (view_convert (cond_op @0 @1 @2 @3 (view_convert:op_type @4))))))
  (simplify
   (vec_cond @0 @1 (view_convert? (uncond_op@5 @2 @3 @4)))
-  (with { tree op_type = TREE_TYPE (@5); }
-   (if (vectorized_internal_fn_supported_p (as_internal_fn (cond_op), op_type)
+  (with { tree op_type = TREE_TYPE (@5);
+	  tree mask_type = TREE_TYPE (@0); }
+   (if (cond_vectorized_internal_fn_supported_p (as_internal_fn (cond_op),
+						 op_type, mask_type)
 	&& element_precision (type) == element_precision (op_type))
     (view_convert (cond_op (bit_not @0) @2 @3 @4
 		  (view_convert:op_type @1)))))))
diff --git a/gcc/testsuite/gcc.target/i386/pr102080.c b/gcc/testsuite/gcc.target/i386/pr102080.c
new file mode 100644
index 00000000000..4c5ee32ee63
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr102080.c
@@ -0,0 +1,19 @@
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+#include<immintrin.h>
+typedef float __m256 __attribute__((__vector_size__(32)));
+__m256 _mm256_blendv_ps___Y, _mm256_blendv_ps___M, _mm256_mul_ps___A,
+  _mm256_mul_ps___B, IfThenElse___trans_tmp_9;
+
+void
+__attribute__ ((target("avx")))
+IfThenElse (__m256 no) {
+  IfThenElse___trans_tmp_9 = _mm256_blendv_ps (no, _mm256_blendv_ps___Y, _mm256_blendv_ps___M);
+}
+void
+__attribute__ ((target("avx512vl")))
+EncodedFromDisplay() {
+  __m256 __trans_tmp_11 = _mm256_mul_ps___A * _mm256_mul_ps___B;
+  IfThenElse(__trans_tmp_11);
+}
-- 
2.18.1


  reply	other threads:[~2021-08-31 10:18 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-27  6:52 liuhongt
2021-08-30 12:24 ` Richard Biener
2021-08-31 10:24   ` Hongtao Liu [this message]
2021-08-31 11:56     ` Richard Biener
2021-09-01  6:33       ` Hongtao Liu
2021-09-01 11:14         ` Richard Biener
2021-09-01 12:52           ` Richard Sandiford
2021-09-01 13:33             ` Richard Biener
2021-09-02  6:42             ` Hongtao Liu
2021-09-02 17:54               ` Richard Sandiford
2021-09-06  6:54                 ` Richard Biener
2021-09-06  9:01                   ` Hongtao Liu
2021-09-16  6:27                     ` [PATCH] Check mask type when doing cond_op related gimple simplification liuhongt
2021-09-16  8:27                       ` Richard Biener

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAMZc-bxR35bTV_SdjGe8=Vb6BUZ5TuLOmjwuGfF9kRcjqoB3LA@mail.gmail.com' \
    --to=crazylht@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=hongtao.liu@intel.com \
    --cc=richard.guenther@gmail.com \
    --cc=richard.sandiford@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).