diff mbox series

tree-optimization/101756 - avoid vectorizing boolean MAX reductions

Message ID 86pror2n-q58o-n3qs-s9q3-79524p924oo9@fhfr.qr
State New
Headers show
Series tree-optimization/101756 - avoid vectorizing boolean MAX reductions | expand

Commit Message

Richard Biener Aug. 4, 2021, 10:33 a.m. UTC
The following avoids vectorizing MIN/MAX reductions on bools which,
when ending up as vector(2) <signed-boolean:64> would need to be
adjusted because of the sign change.  The fix instead avoids any
reduction vectorization where the result isn't compatible
to the original scalar type since we don't compensate for that
either.

Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.

2021-08-04  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/101756
	* tree-vect-slp.c (vectorizable_bb_reduc_epilogue): Make sure
	the result of the reduction epilogue is compatible to the original
	scalar result.

	* gcc.dg/vect/bb-slp-pr101756.c: New testcase.
---
 gcc/testsuite/gcc.dg/vect/bb-slp-pr101756.c | 15 +++++++++++++++
 gcc/tree-vect-slp.c                         |  8 +++++---
 2 files changed, 20 insertions(+), 3 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/vect/bb-slp-pr101756.c

Comments

Christophe Lyon Aug. 5, 2021, 9:36 a.m. UTC | #1
On Wed, Aug 4, 2021 at 12:33 PM Richard Biener <rguenther@suse.de> wrote:

> The following avoids vectorizing MIN/MAX reductions on bools which,
> when ending up as vector(2) <signed-boolean:64> would need to be
> adjusted because of the sign change.  The fix instead avoids any
> reduction vectorization where the result isn't compatible
> to the original scalar type since we don't compensate for that
> either.
>
> Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.
>
> 2021-08-04  Richard Biener  <rguenther@suse.de>
>
>         PR tree-optimization/101756
>         * tree-vect-slp.c (vectorizable_bb_reduc_epilogue): Make sure
>         the result of the reduction epilogue is compatible to the original
>         scalar result.
>
>         * gcc.dg/vect/bb-slp-pr101756.c: New testcase.
>

Hi,

The new testcase fails on aarch64 because:
 FAIL: gcc.dg/vect/bb-slp-pr101756.c (test for excess errors)
Excess errors:
/gcc/testsuite/gcc.dg/vect/bb-slp-pr101756.c:4:1: warning: GCC does not
currently support mixed size types for 'simd' functions

Can you check?

Thanks

Christophe




> ---
>  gcc/testsuite/gcc.dg/vect/bb-slp-pr101756.c | 15 +++++++++++++++
>  gcc/tree-vect-slp.c                         |  8 +++++---
>  2 files changed, 20 insertions(+), 3 deletions(-)
>  create mode 100644 gcc/testsuite/gcc.dg/vect/bb-slp-pr101756.c
>
> diff --git a/gcc/testsuite/gcc.dg/vect/bb-slp-pr101756.c
> b/gcc/testsuite/gcc.dg/vect/bb-slp-pr101756.c
> new file mode 100644
> index 00000000000..9420e77f64e
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/vect/bb-slp-pr101756.c
> @@ -0,0 +1,15 @@
> +/* { dg-do compile } */
> +
> +__attribute__ ((simd)) int
> +tq (long int ea, int of, int kk)
> +{
> +  int bc;
> +
> +  for (bc = 0; bc < 2; ++bc)
> +    {
> +      ++ea;
> +      of |= !!kk < !!ea;
> +    }
> +
> +  return of;
> +}
> diff --git a/gcc/tree-vect-slp.c b/gcc/tree-vect-slp.c
> index a554c24e0fb..d169bed8e94 100644
> --- a/gcc/tree-vect-slp.c
> +++ b/gcc/tree-vect-slp.c
> @@ -4847,15 +4847,17 @@ static bool
>  vectorizable_bb_reduc_epilogue (slp_instance instance,
>                                 stmt_vector_for_cost *cost_vec)
>  {
> -  enum tree_code reduc_code
> -    = gimple_assign_rhs_code (instance->root_stmts[0]->stmt);
> +  gassign *stmt = as_a <gassign *> (instance->root_stmts[0]->stmt);
> +  enum tree_code reduc_code = gimple_assign_rhs_code (stmt);
>    if (reduc_code == MINUS_EXPR)
>      reduc_code = PLUS_EXPR;
>    internal_fn reduc_fn;
>    tree vectype = SLP_TREE_VECTYPE (SLP_INSTANCE_TREE (instance));
>    if (!reduction_fn_for_scalar_code (reduc_code, &reduc_fn)
>        || reduc_fn == IFN_LAST
> -      || !direct_internal_fn_supported_p (reduc_fn, vectype,
> OPTIMIZE_FOR_BOTH))
> +      || !direct_internal_fn_supported_p (reduc_fn, vectype,
> OPTIMIZE_FOR_BOTH)
> +      || !useless_type_conversion_p (TREE_TYPE (gimple_assign_lhs (stmt)),
> +                                    TREE_TYPE (vectype)))
>      return false;
>
>    /* There's no way to cost a horizontal vector reduction via REDUC_FN so
> --
> 2.31.1
>
Richard Biener Aug. 5, 2021, 9:42 a.m. UTC | #2
On Thu, 5 Aug 2021, Christophe Lyon wrote:

> On Wed, Aug 4, 2021 at 12:33 PM Richard Biener <rguenther@suse.de> wrote:
> 
> > The following avoids vectorizing MIN/MAX reductions on bools which,
> > when ending up as vector(2) <signed-boolean:64> would need to be
> > adjusted because of the sign change.  The fix instead avoids any
> > reduction vectorization where the result isn't compatible
> > to the original scalar type since we don't compensate for that
> > either.
> >
> > Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.
> >
> > 2021-08-04  Richard Biener  <rguenther@suse.de>
> >
> >         PR tree-optimization/101756
> >         * tree-vect-slp.c (vectorizable_bb_reduc_epilogue): Make sure
> >         the result of the reduction epilogue is compatible to the original
> >         scalar result.
> >
> >         * gcc.dg/vect/bb-slp-pr101756.c: New testcase.
> >
> 
> Hi,
> 
> The new testcase fails on aarch64 because:
>  FAIL: gcc.dg/vect/bb-slp-pr101756.c (test for excess errors)
> Excess errors:
> /gcc/testsuite/gcc.dg/vect/bb-slp-pr101756.c:4:1: warning: GCC does not
> currently support mixed size types for 'simd' functions
> 
> Can you check?

I have pushed

From 425fce297da1696b4b5178e533d823f13fb250a5 Mon Sep 17 00:00:00 2001
From: Richard Biener <rguenther@suse.de>
Date: Thu, 5 Aug 2021 11:39:50 +0200
Subject: [PATCH] Adjust gcc.dg/vect/bb-slp-pr101756.c
To: gcc-patches@gcc.gnu.org

This adjusts the testcase for excess diagnostics emitted by some
targets because of the attribute simd usage like

warning: GCC does not currently support mixed size types for 'simd' functions

on aarch64.

2021-08-05  Richard Biener  <rguenther@suse.de>

	* gcc.dg/vect/bb-slp-pr101756.c: Add -w.
---
 gcc/testsuite/gcc.dg/vect/bb-slp-pr101756.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/gcc/testsuite/gcc.dg/vect/bb-slp-pr101756.c b/gcc/testsuite/gcc.dg/vect/bb-slp-pr101756.c
index 9420e77f64e..de7f1806926 100644
--- a/gcc/testsuite/gcc.dg/vect/bb-slp-pr101756.c
+++ b/gcc/testsuite/gcc.dg/vect/bb-slp-pr101756.c
@@ -1,4 +1,6 @@
 /* { dg-do compile } */
+/* SIMD support can emit additional diagnostics.  */
+/* { dg-additional-options "-w" } */
 
 __attribute__ ((simd)) int
 tq (long int ea, int of, int kk)
diff mbox series

Patch

diff --git a/gcc/testsuite/gcc.dg/vect/bb-slp-pr101756.c b/gcc/testsuite/gcc.dg/vect/bb-slp-pr101756.c
new file mode 100644
index 00000000000..9420e77f64e
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/bb-slp-pr101756.c
@@ -0,0 +1,15 @@ 
+/* { dg-do compile } */
+
+__attribute__ ((simd)) int
+tq (long int ea, int of, int kk)
+{
+  int bc;
+
+  for (bc = 0; bc < 2; ++bc)
+    {
+      ++ea;
+      of |= !!kk < !!ea;
+    }
+
+  return of;
+}
diff --git a/gcc/tree-vect-slp.c b/gcc/tree-vect-slp.c
index a554c24e0fb..d169bed8e94 100644
--- a/gcc/tree-vect-slp.c
+++ b/gcc/tree-vect-slp.c
@@ -4847,15 +4847,17 @@  static bool
 vectorizable_bb_reduc_epilogue (slp_instance instance,
 				stmt_vector_for_cost *cost_vec)
 {
-  enum tree_code reduc_code
-    = gimple_assign_rhs_code (instance->root_stmts[0]->stmt);
+  gassign *stmt = as_a <gassign *> (instance->root_stmts[0]->stmt);
+  enum tree_code reduc_code = gimple_assign_rhs_code (stmt);
   if (reduc_code == MINUS_EXPR)
     reduc_code = PLUS_EXPR;
   internal_fn reduc_fn;
   tree vectype = SLP_TREE_VECTYPE (SLP_INSTANCE_TREE (instance));
   if (!reduction_fn_for_scalar_code (reduc_code, &reduc_fn)
       || reduc_fn == IFN_LAST
-      || !direct_internal_fn_supported_p (reduc_fn, vectype, OPTIMIZE_FOR_BOTH))
+      || !direct_internal_fn_supported_p (reduc_fn, vectype, OPTIMIZE_FOR_BOTH)
+      || !useless_type_conversion_p (TREE_TYPE (gimple_assign_lhs (stmt)),
+				     TREE_TYPE (vectype)))
     return false;
 
   /* There's no way to cost a horizontal vector reduction via REDUC_FN so