public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Fix ICE for masked store of boolean value
@ 2015-11-12 15:49 Ilya Enkovich
  2015-11-12 22:40 ` Jeff Law
  0 siblings, 1 reply; 2+ messages in thread
From: Ilya Enkovich @ 2015-11-12 15:49 UTC (permalink / raw)
  To: gcc-patches

Hi,

We may get ICE in vectorizer in case stored value get vectype not compatible with a storage.  This may happen for bool values.  This patch fixes ICE.  Bootstrapped and tested on x86_64-unknown-linux-gnu.  OK for trunk?

Thanks,
Ilya
--
gcc/

2015-11-12  Ilya Enkovich  <enkovich.gnu@gmail.com>

	* tree-vect-stmts.c (vectorizable_mask_load_store): Check
	types of stored value and storage are compatible.

gcc/testsuite/

2015-11-12  Ilya Enkovich  <enkovich.gnu@gmail.com>

	* g++.dg/vect/simd-mask-store-bool.cc: New test.


diff --git a/gcc/testsuite/g++.dg/vect/simd-mask-store-bool.cc b/gcc/testsuite/g++.dg/vect/simd-mask-store-bool.cc
new file mode 100644
index 0000000..c5f0458
--- /dev/null
+++ b/gcc/testsuite/g++.dg/vect/simd-mask-store-bool.cc
@@ -0,0 +1,18 @@
+/* { dg-do compile } */
+/* { dg-require-effective-target vect_condition } */
+/* { dg-additional-options "-mavx512bw" { target { i?86-*-* x86_64-*-* } } } */
+
+#define N 1024
+
+int a[N], b[N], c[N];
+bool d[N];
+
+void
+test (void)
+{
+  int i;
+#pragma omp simd safelen(64)
+  for (i = 0; i < N; i++)
+    if (a[i] > 0)
+      d[i] = b[i] > c[i];
+}
diff --git a/gcc/tree-vect-stmts.c b/gcc/tree-vect-stmts.c
index cfe30e0..7870b29 100644
--- a/gcc/tree-vect-stmts.c
+++ b/gcc/tree-vect-stmts.c
@@ -1688,6 +1688,7 @@ vectorizable_mask_load_store (gimple *stmt, gimple_stmt_iterator *gsi,
   bool nested_in_vect_loop = nested_in_vect_loop_p (loop, stmt);
   struct data_reference *dr = STMT_VINFO_DATA_REF (stmt_info);
   tree vectype = STMT_VINFO_VECTYPE (stmt_info);
+  tree rhs_vectype = NULL_TREE;
   tree mask_vectype;
   tree elem_type;
   gimple *new_stmt;
@@ -1757,6 +1758,13 @@ vectorizable_mask_load_store (gimple *stmt, gimple_stmt_iterator *gsi,
   if (!mask_vectype)
     return false;
 
+  if (is_store)
+    {
+      tree rhs = gimple_call_arg (stmt, 3);
+      if (!vect_is_simple_use (rhs, loop_vinfo, &def_stmt, &dt, &rhs_vectype))
+	return false;
+    }
+
   if (STMT_VINFO_GATHER_SCATTER_P (stmt_info))
     {
       gimple *def_stmt;
@@ -1790,16 +1798,11 @@ vectorizable_mask_load_store (gimple *stmt, gimple_stmt_iterator *gsi,
   else if (!VECTOR_MODE_P (TYPE_MODE (vectype))
 	   || !can_vec_mask_load_store_p (TYPE_MODE (vectype),
 					  TYPE_MODE (mask_vectype),
-					  !is_store))
+					  !is_store)
+	   || (rhs_vectype
+	       && !useless_type_conversion_p (vectype, rhs_vectype)))
     return false;
 
-  if (is_store)
-    {
-      tree rhs = gimple_call_arg (stmt, 3);
-      if (!vect_is_simple_use (rhs, loop_vinfo, &def_stmt, &dt))
-	return false;
-    }
-
   if (!vec_stmt) /* transformation not required.  */
     {
       STMT_VINFO_TYPE (stmt_info) = call_vec_info_type;

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

* Re: [PATCH] Fix ICE for masked store of boolean value
  2015-11-12 15:49 [PATCH] Fix ICE for masked store of boolean value Ilya Enkovich
@ 2015-11-12 22:40 ` Jeff Law
  0 siblings, 0 replies; 2+ messages in thread
From: Jeff Law @ 2015-11-12 22:40 UTC (permalink / raw)
  To: Ilya Enkovich, gcc-patches

On 11/12/2015 08:48 AM, Ilya Enkovich wrote:
> Hi,
>
> We may get ICE in vectorizer in case stored value get vectype not compatible with a storage.  This may happen for bool values.  This patch fixes ICE.  Bootstrapped and tested on x86_64-unknown-linux-gnu.  OK for trunk?
>
> Thanks,
> Ilya
> --
> gcc/
>
> 2015-11-12  Ilya Enkovich  <enkovich.gnu@gmail.com>
>
> 	* tree-vect-stmts.c (vectorizable_mask_load_store): Check
> 	types of stored value and storage are compatible.
>
> gcc/testsuite/
>
> 2015-11-12  Ilya Enkovich  <enkovich.gnu@gmail.com>
>
> 	* g++.dg/vect/simd-mask-store-bool.cc: New test.
OK.
jeff

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

end of thread, other threads:[~2015-11-12 22:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-12 15:49 [PATCH] Fix ICE for masked store of boolean value Ilya Enkovich
2015-11-12 22:40 ` Jeff Law

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