diff mbox

[PR,tree-optimization/69328] Fix vectorization of boolean vector comparision in COND_EXPR

Message ID 20160119104637.GB15775@msticlxl57.ims.intel.com
State New
Headers show

Commit Message

Ilya Enkovich Jan. 19, 2016, 10:46 a.m. UTC
Hi,

Currently vectorizer incorrectly handles a case when COND_EXPR
has boolean vector comparison.  Firstly masked COND_EXPR is
determined incorrectly.  Also we don't check vector types of
compared values are compatible.  This patch fixes these problems.
Bootstrapped and regtested for x86_64-pc-linux-gnu.  OK for trunk?

Thanks,
Ilya
--
gcc/

2016-01-19  Ilya Enkovich  <enkovich.gnu@gmail.com>
	    Richard Biener  <rguenther@suse.de>

	PR tree-optimization/69328
	* tree-vect-stmts.c (vect_is_simple_cond): Check compared
	vectors have same number of elements.
	(vectorizable_condition): Fix masked version recognition.


gcc/testsuite/

2016-01-19  Ilya Enkovich  <enkovich.gnu@gmail.com>

	PR tree-optimization/69328
	* gcc.dg/pr69328.c: New test.

Comments

Richard Biener Jan. 20, 2016, 12:27 p.m. UTC | #1
On Tue, Jan 19, 2016 at 11:46 AM, Ilya Enkovich <enkovich.gnu@gmail.com> wrote:
> Hi,
>
> Currently vectorizer incorrectly handles a case when COND_EXPR
> has boolean vector comparison.  Firstly masked COND_EXPR is
> determined incorrectly.  Also we don't check vector types of
> compared values are compatible.  This patch fixes these problems.
> Bootstrapped and regtested for x86_64-pc-linux-gnu.  OK for trunk?

Ok.

Thanks,
Richard.

> Thanks,
> Ilya
> --
> gcc/
>
> 2016-01-19  Ilya Enkovich  <enkovich.gnu@gmail.com>
>             Richard Biener  <rguenther@suse.de>
>
>         PR tree-optimization/69328
>         * tree-vect-stmts.c (vect_is_simple_cond): Check compared
>         vectors have same number of elements.
>         (vectorizable_condition): Fix masked version recognition.
>
>
> gcc/testsuite/
>
> 2016-01-19  Ilya Enkovich  <enkovich.gnu@gmail.com>
>
>         PR tree-optimization/69328
>         * gcc.dg/pr69328.c: New test.
>
>
> diff --git a/gcc/testsuite/gcc.dg/pr69328.c b/gcc/testsuite/gcc.dg/pr69328.c
> new file mode 100644
> index 0000000..a495596
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/pr69328.c
> @@ -0,0 +1,16 @@
> +/* { dg-do compile } */
> +/* { dg-options "-O3" } */
> +
> +int a, b;
> +void fn1() {
> +  int c;
> +  char *d;
> +  for (; a; ++a) {
> +    int e, f;
> +    e = d[a];
> +    if (!e && f || !f && e)
> +      ++c;
> +  }
> +  if (c)
> +    b = .499;
> +}
> diff --git a/gcc/tree-vect-stmts.c b/gcc/tree-vect-stmts.c
> index 635c797..9d4d286 100644
> --- a/gcc/tree-vect-stmts.c
> +++ b/gcc/tree-vect-stmts.c
> @@ -7441,6 +7441,10 @@ vect_is_simple_cond (tree cond, vec_info *vinfo, tree *comp_vectype)
>            && TREE_CODE (rhs) != FIXED_CST)
>      return false;
>
> +  if (vectype1 && vectype2
> +      && TYPE_VECTOR_SUBPARTS (vectype1) != TYPE_VECTOR_SUBPARTS (vectype2))
> +    return false;
> +
>    *comp_vectype = vectype1 ? vectype1 : vectype2;
>    return true;
>  }
> @@ -7544,13 +7548,9 @@ vectorizable_condition (gimple *stmt, gimple_stmt_iterator *gsi,
>    if (!vect_is_simple_use (else_clause, stmt_info->vinfo, &def_stmt, &dt))
>      return false;
>
> -  if (VECTOR_BOOLEAN_TYPE_P (comp_vectype))
> -    {
> -      vec_cmp_type = comp_vectype;
> -      masked = true;
> -    }
> -  else
> -    vec_cmp_type = build_same_sized_truth_vector_type (comp_vectype);
> +  masked = !COMPARISON_CLASS_P (cond_expr);
> +  vec_cmp_type = build_same_sized_truth_vector_type (comp_vectype);
> +
>    if (vec_cmp_type == NULL_TREE)
>      return false;
>
diff mbox

Patch

diff --git a/gcc/testsuite/gcc.dg/pr69328.c b/gcc/testsuite/gcc.dg/pr69328.c
new file mode 100644
index 0000000..a495596
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr69328.c
@@ -0,0 +1,16 @@ 
+/* { dg-do compile } */
+/* { dg-options "-O3" } */
+
+int a, b;
+void fn1() {
+  int c;
+  char *d;
+  for (; a; ++a) {
+    int e, f;
+    e = d[a];
+    if (!e && f || !f && e)
+      ++c;
+  }
+  if (c)
+    b = .499;
+}
diff --git a/gcc/tree-vect-stmts.c b/gcc/tree-vect-stmts.c
index 635c797..9d4d286 100644
--- a/gcc/tree-vect-stmts.c
+++ b/gcc/tree-vect-stmts.c
@@ -7441,6 +7441,10 @@  vect_is_simple_cond (tree cond, vec_info *vinfo, tree *comp_vectype)
 	   && TREE_CODE (rhs) != FIXED_CST)
     return false;
 
+  if (vectype1 && vectype2
+      && TYPE_VECTOR_SUBPARTS (vectype1) != TYPE_VECTOR_SUBPARTS (vectype2))
+    return false;
+
   *comp_vectype = vectype1 ? vectype1 : vectype2;
   return true;
 }
@@ -7544,13 +7548,9 @@  vectorizable_condition (gimple *stmt, gimple_stmt_iterator *gsi,
   if (!vect_is_simple_use (else_clause, stmt_info->vinfo, &def_stmt, &dt))
     return false;
 
-  if (VECTOR_BOOLEAN_TYPE_P (comp_vectype))
-    {
-      vec_cmp_type = comp_vectype;
-      masked = true;
-    }
-  else
-    vec_cmp_type = build_same_sized_truth_vector_type (comp_vectype);
+  masked = !COMPARISON_CLASS_P (cond_expr);
+  vec_cmp_type = build_same_sized_truth_vector_type (comp_vectype);
+
   if (vec_cmp_type == NULL_TREE)
     return false;