diff mbox

[PR69421] Check vector types of COND_EXPR operands are compatible when vectorizing it

Message ID 20160125101649.GD15775@msticlxl57.ims.intel.com
State New
Headers show

Commit Message

Ilya Enkovich Jan. 25, 2016, 10:16 a.m. UTC
Hi,

This patch covers one more case when boolean operands get different
vectypes and we don't detect it.

Bootstrapped and regtested on x86_64-pc-linux-gnu.  OK for trunk?

Thanks,
Ilya
--
gcc/

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

	PR target/69421
	* tree-vect-stmts.c (vectorizable_condition): Check vectype
	of operands is compatible with a statement vectype.

gcc/testsuite/

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

	PR target/69421
	* gcc.dg/pr69421.c: New test.

Comments

Richard Biener Jan. 25, 2016, 12:45 p.m. UTC | #1
On Mon, Jan 25, 2016 at 11:16 AM, Ilya Enkovich <enkovich.gnu@gmail.com> wrote:
> Hi,
>
> This patch covers one more case when boolean operands get different
> vectypes and we don't detect it.
>
> Bootstrapped and regtested on x86_64-pc-linux-gnu.  OK for trunk?

Ok.

Richard.

> Thanks,
> Ilya
> --
> gcc/
>
> 2016-01-25  Ilya Enkovich  <enkovich.gnu@gmail.com>
>
>         PR target/69421
>         * tree-vect-stmts.c (vectorizable_condition): Check vectype
>         of operands is compatible with a statement vectype.
>
> gcc/testsuite/
>
> 2016-01-25  Ilya Enkovich  <enkovich.gnu@gmail.com>
>
>         PR target/69421
>         * gcc.dg/pr69421.c: New test.
>
>
> diff --git a/gcc/testsuite/gcc.dg/pr69421.c b/gcc/testsuite/gcc.dg/pr69421.c
> new file mode 100644
> index 0000000..252e22c
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/pr69421.c
> @@ -0,0 +1,16 @@
> +/* { dg-do compile } */
> +/* { dg-options "-O3" } */
> +
> +struct A { double a; };
> +double a;
> +
> +void
> +foo (_Bool *x)
> +{
> +  long i;
> +  for (i = 0; i < 64; i++)
> +    {
> +      struct A c;
> +      x[i] = c.a || a;
> +    }
> +}
> diff --git a/gcc/tree-vect-stmts.c b/gcc/tree-vect-stmts.c
> index 1d2246d..ed2ce07 100644
> --- a/gcc/tree-vect-stmts.c
> +++ b/gcc/tree-vect-stmts.c
> @@ -7528,6 +7528,7 @@ vectorizable_condition (gimple *stmt, gimple_stmt_iterator *gsi,
>
>    tree vectype = STMT_VINFO_VECTYPE (stmt_info);
>    int nunits = TYPE_VECTOR_SUBPARTS (vectype);
> +  tree vectype1 = NULL_TREE, vectype2 = NULL_TREE;
>
>    if (slp_node || PURE_SLP_STMT (stmt_info))
>      ncopies = 1;
> @@ -7547,9 +7548,17 @@ vectorizable_condition (gimple *stmt, gimple_stmt_iterator *gsi,
>      return false;
>
>    gimple *def_stmt;
> -  if (!vect_is_simple_use (then_clause, stmt_info->vinfo, &def_stmt, &dt))
> +  if (!vect_is_simple_use (then_clause, stmt_info->vinfo, &def_stmt, &dt,
> +                          &vectype1))
> +    return false;
> +  if (!vect_is_simple_use (else_clause, stmt_info->vinfo, &def_stmt, &dt,
> +                          &vectype2))
>      return false;
> -  if (!vect_is_simple_use (else_clause, stmt_info->vinfo, &def_stmt, &dt))
> +
> +  if (vectype1 && !useless_type_conversion_p (vectype, vectype1))
> +    return false;
> +
> +  if (vectype2 && !useless_type_conversion_p (vectype, vectype2))
>      return false;
>
>    masked = !COMPARISON_CLASS_P (cond_expr);
diff mbox

Patch

diff --git a/gcc/testsuite/gcc.dg/pr69421.c b/gcc/testsuite/gcc.dg/pr69421.c
new file mode 100644
index 0000000..252e22c
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr69421.c
@@ -0,0 +1,16 @@ 
+/* { dg-do compile } */
+/* { dg-options "-O3" } */
+
+struct A { double a; };
+double a;
+
+void
+foo (_Bool *x)
+{
+  long i;
+  for (i = 0; i < 64; i++)
+    {
+      struct A c;
+      x[i] = c.a || a;
+    }
+}
diff --git a/gcc/tree-vect-stmts.c b/gcc/tree-vect-stmts.c
index 1d2246d..ed2ce07 100644
--- a/gcc/tree-vect-stmts.c
+++ b/gcc/tree-vect-stmts.c
@@ -7528,6 +7528,7 @@  vectorizable_condition (gimple *stmt, gimple_stmt_iterator *gsi,
 
   tree vectype = STMT_VINFO_VECTYPE (stmt_info);
   int nunits = TYPE_VECTOR_SUBPARTS (vectype);
+  tree vectype1 = NULL_TREE, vectype2 = NULL_TREE;
 
   if (slp_node || PURE_SLP_STMT (stmt_info))
     ncopies = 1;
@@ -7547,9 +7548,17 @@  vectorizable_condition (gimple *stmt, gimple_stmt_iterator *gsi,
     return false;
 
   gimple *def_stmt;
-  if (!vect_is_simple_use (then_clause, stmt_info->vinfo, &def_stmt, &dt))
+  if (!vect_is_simple_use (then_clause, stmt_info->vinfo, &def_stmt, &dt,
+			   &vectype1))
+    return false;
+  if (!vect_is_simple_use (else_clause, stmt_info->vinfo, &def_stmt, &dt,
+			   &vectype2))
     return false;
-  if (!vect_is_simple_use (else_clause, stmt_info->vinfo, &def_stmt, &dt))
+
+  if (vectype1 && !useless_type_conversion_p (vectype, vectype1))
+    return false;
+
+  if (vectype2 && !useless_type_conversion_p (vectype, vectype2))
     return false;
 
   masked = !COMPARISON_CLASS_P (cond_expr);