public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH]middle-end: Handle hybrid SLP induction vectorization with early breaks.
@ 2023-12-19 10:12 Tamar Christina
  2023-12-19 12:36 ` Richard Biener
  0 siblings, 1 reply; 2+ messages in thread
From: Tamar Christina @ 2023-12-19 10:12 UTC (permalink / raw)
  To: gcc-patches; +Cc: nd, rguenther, jlaw

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

Hi All,

While we don't support SLP for early break vectorization, we
can land in the situation where the induction was vectorized
through hybrid SLP.  This means when vectorizing the early
break live operation we need to get the results of the SLP
operation.


Bootstrapped Regtested on aarch64-none-linux-gnu,
x86_64-pc-linux-gnu and no issues.

Ok for master?

Thanks,
Tamar

gcc/ChangeLog:

	* tree-vect-loop.cc (vectorizable_live_operation): Handle SLP.

gcc/testsuite/ChangeLog:

	* gcc.dg/vect/vect-early-break_82.c: New test.

--- inline copy of patch -- 
diff --git a/gcc/testsuite/gcc.dg/vect/vect-early-break_82.c b/gcc/testsuite/gcc.dg/vect/vect-early-break_82.c
new file mode 100644
index 0000000000000000000000000000000000000000..f2a6d640f9c0c381cc2af09bd824e272bcfee0b8
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/vect-early-break_82.c
@@ -0,0 +1,27 @@
+/* { dg-do compile } */
+/* { dg-require-effective-target vect_early_break } */
+/* { dg-require-effective-target vect_int } */
+
+/* { dg-additional-options "-Ofast" } */
+
+/* { dg-final { scan-tree-dump "LOOP VECTORIZED" "vect" } } */
+
+#include <complex.h>
+
+#define N 1024
+complex double vect_a[N];
+complex double vect_b[N];
+  
+complex double test4(complex double x, complex double t)
+{
+ complex double ret = 0;
+ for (int i = 0; i < N; i++)
+ {
+   vect_a[i] = t + i;
+   if (vect_a[i] == x)
+     return i;
+   vect_a[i] += x * vect_a[i];
+   
+ }
+ return ret;
+}
diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc
index 85b81d30c5ab869cb1f7323caabd9fe4648bdc50..0993d184afe068784474ac225768d9f38d76c040 100644
--- a/gcc/tree-vect-loop.cc
+++ b/gcc/tree-vect-loop.cc
@@ -10856,8 +10856,8 @@ vectorizable_live_operation (vec_info *vinfo, stmt_vec_info stmt_info,
   bitsize = vector_element_bits_tree (vectype);
 
   /* Get the vectorized lhs of STMT and the lane to use (counted in bits).  */
-  tree vec_lhs, bitstart;
-  gimple *vec_stmt;
+  tree vec_lhs, vec_lhs0, bitstart;
+  gimple *vec_stmt, *vec_stmt0;
   if (slp_node)
     {
       gcc_assert (!loop_vinfo
@@ -10868,6 +10868,10 @@ vectorizable_live_operation (vec_info *vinfo, stmt_vec_info stmt_info,
       vec_lhs = SLP_TREE_VEC_DEFS (slp_node)[vec_entry];
       vec_stmt = SSA_NAME_DEF_STMT (vec_lhs);
 
+      /* In case we need to early break vectorize also get the first stmt.  */
+      vec_lhs0 = SLP_TREE_VEC_DEFS (slp_node)[0];
+      vec_stmt0 = SSA_NAME_DEF_STMT (vec_lhs0);
+
       /* Get entry to use.  */
       bitstart = bitsize_int (vec_index);
       bitstart = int_const_binop (MULT_EXPR, bitsize, bitstart);
@@ -10878,6 +10882,10 @@ vectorizable_live_operation (vec_info *vinfo, stmt_vec_info stmt_info,
       vec_stmt = STMT_VINFO_VEC_STMTS (stmt_info).last ();
       vec_lhs = gimple_get_lhs (vec_stmt);
 
+      /* In case we need to early break vectorize also get the first stmt.  */
+      vec_stmt0 = STMT_VINFO_VEC_STMTS (stmt_info)[0];
+      vec_lhs0 = gimple_get_lhs (vec_stmt0);
+
       /* Get the last lane in the vector.  */
       bitstart = int_const_binop (MULT_EXPR, bitsize, bitsize_int (nunits - 1));
     }
@@ -10917,7 +10925,6 @@ vectorizable_live_operation (vec_info *vinfo, stmt_vec_info stmt_info,
 		 so use ->src.  For main exit the merge block is the
 		 destination.  */
 	      basic_block dest = main_exit_edge ? main_e->dest : e->src;
-	      gimple *tmp_vec_stmt = vec_stmt;
 	      tree tmp_vec_lhs = vec_lhs;
 	      tree tmp_bitstart = bitstart;
 
@@ -10928,8 +10935,7 @@ vectorizable_live_operation (vec_info *vinfo, stmt_vec_info stmt_info,
 	      if (restart_loop
 		  && STMT_VINFO_DEF_TYPE (stmt_info) == vect_induction_def)
 		{
-		  tmp_vec_stmt = STMT_VINFO_VEC_STMTS (stmt_info)[0];
-		  tmp_vec_lhs = gimple_get_lhs (tmp_vec_stmt);
+		  tmp_vec_lhs = vec_lhs0;
 		  tmp_bitstart = build_zero_cst (TREE_TYPE (bitstart));
 		}
 




-- 

[-- Attachment #2: rb18097.patch --]
[-- Type: text/plain, Size: 3294 bytes --]

diff --git a/gcc/testsuite/gcc.dg/vect/vect-early-break_82.c b/gcc/testsuite/gcc.dg/vect/vect-early-break_82.c
new file mode 100644
index 0000000000000000000000000000000000000000..f2a6d640f9c0c381cc2af09bd824e272bcfee0b8
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/vect-early-break_82.c
@@ -0,0 +1,27 @@
+/* { dg-do compile } */
+/* { dg-require-effective-target vect_early_break } */
+/* { dg-require-effective-target vect_int } */
+
+/* { dg-additional-options "-Ofast" } */
+
+/* { dg-final { scan-tree-dump "LOOP VECTORIZED" "vect" } } */
+
+#include <complex.h>
+
+#define N 1024
+complex double vect_a[N];
+complex double vect_b[N];
+  
+complex double test4(complex double x, complex double t)
+{
+ complex double ret = 0;
+ for (int i = 0; i < N; i++)
+ {
+   vect_a[i] = t + i;
+   if (vect_a[i] == x)
+     return i;
+   vect_a[i] += x * vect_a[i];
+   
+ }
+ return ret;
+}
diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc
index 85b81d30c5ab869cb1f7323caabd9fe4648bdc50..0993d184afe068784474ac225768d9f38d76c040 100644
--- a/gcc/tree-vect-loop.cc
+++ b/gcc/tree-vect-loop.cc
@@ -10856,8 +10856,8 @@ vectorizable_live_operation (vec_info *vinfo, stmt_vec_info stmt_info,
   bitsize = vector_element_bits_tree (vectype);
 
   /* Get the vectorized lhs of STMT and the lane to use (counted in bits).  */
-  tree vec_lhs, bitstart;
-  gimple *vec_stmt;
+  tree vec_lhs, vec_lhs0, bitstart;
+  gimple *vec_stmt, *vec_stmt0;
   if (slp_node)
     {
       gcc_assert (!loop_vinfo
@@ -10868,6 +10868,10 @@ vectorizable_live_operation (vec_info *vinfo, stmt_vec_info stmt_info,
       vec_lhs = SLP_TREE_VEC_DEFS (slp_node)[vec_entry];
       vec_stmt = SSA_NAME_DEF_STMT (vec_lhs);
 
+      /* In case we need to early break vectorize also get the first stmt.  */
+      vec_lhs0 = SLP_TREE_VEC_DEFS (slp_node)[0];
+      vec_stmt0 = SSA_NAME_DEF_STMT (vec_lhs0);
+
       /* Get entry to use.  */
       bitstart = bitsize_int (vec_index);
       bitstart = int_const_binop (MULT_EXPR, bitsize, bitstart);
@@ -10878,6 +10882,10 @@ vectorizable_live_operation (vec_info *vinfo, stmt_vec_info stmt_info,
       vec_stmt = STMT_VINFO_VEC_STMTS (stmt_info).last ();
       vec_lhs = gimple_get_lhs (vec_stmt);
 
+      /* In case we need to early break vectorize also get the first stmt.  */
+      vec_stmt0 = STMT_VINFO_VEC_STMTS (stmt_info)[0];
+      vec_lhs0 = gimple_get_lhs (vec_stmt0);
+
       /* Get the last lane in the vector.  */
       bitstart = int_const_binop (MULT_EXPR, bitsize, bitsize_int (nunits - 1));
     }
@@ -10917,7 +10925,6 @@ vectorizable_live_operation (vec_info *vinfo, stmt_vec_info stmt_info,
 		 so use ->src.  For main exit the merge block is the
 		 destination.  */
 	      basic_block dest = main_exit_edge ? main_e->dest : e->src;
-	      gimple *tmp_vec_stmt = vec_stmt;
 	      tree tmp_vec_lhs = vec_lhs;
 	      tree tmp_bitstart = bitstart;
 
@@ -10928,8 +10935,7 @@ vectorizable_live_operation (vec_info *vinfo, stmt_vec_info stmt_info,
 	      if (restart_loop
 		  && STMT_VINFO_DEF_TYPE (stmt_info) == vect_induction_def)
 		{
-		  tmp_vec_stmt = STMT_VINFO_VEC_STMTS (stmt_info)[0];
-		  tmp_vec_lhs = gimple_get_lhs (tmp_vec_stmt);
+		  tmp_vec_lhs = vec_lhs0;
 		  tmp_bitstart = build_zero_cst (TREE_TYPE (bitstart));
 		}
 




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

* Re: [PATCH]middle-end: Handle hybrid SLP induction vectorization with early breaks.
  2023-12-19 10:12 [PATCH]middle-end: Handle hybrid SLP induction vectorization with early breaks Tamar Christina
@ 2023-12-19 12:36 ` Richard Biener
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2023-12-19 12:36 UTC (permalink / raw)
  To: Tamar Christina; +Cc: gcc-patches, nd, jlaw

On Tue, 19 Dec 2023, Tamar Christina wrote:

> Hi All,
> 
> While we don't support SLP for early break vectorization, we
> can land in the situation where the induction was vectorized
> through hybrid SLP.  This means when vectorizing the early
> break live operation we need to get the results of the SLP
> operation.
> 
> 
> Bootstrapped Regtested on aarch64-none-linux-gnu,
> x86_64-pc-linux-gnu and no issues.
> 
> Ok for master?

OK.

> Thanks,
> Tamar
> 
> gcc/ChangeLog:
> 
> 	* tree-vect-loop.cc (vectorizable_live_operation): Handle SLP.
> 
> gcc/testsuite/ChangeLog:
> 
> 	* gcc.dg/vect/vect-early-break_82.c: New test.
> 
> --- inline copy of patch -- 
> diff --git a/gcc/testsuite/gcc.dg/vect/vect-early-break_82.c b/gcc/testsuite/gcc.dg/vect/vect-early-break_82.c
> new file mode 100644
> index 0000000000000000000000000000000000000000..f2a6d640f9c0c381cc2af09bd824e272bcfee0b8
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/vect/vect-early-break_82.c
> @@ -0,0 +1,27 @@
> +/* { dg-do compile } */
> +/* { dg-require-effective-target vect_early_break } */
> +/* { dg-require-effective-target vect_int } */
> +
> +/* { dg-additional-options "-Ofast" } */
> +
> +/* { dg-final { scan-tree-dump "LOOP VECTORIZED" "vect" } } */
> +
> +#include <complex.h>
> +
> +#define N 1024
> +complex double vect_a[N];
> +complex double vect_b[N];
> +  
> +complex double test4(complex double x, complex double t)
> +{
> + complex double ret = 0;
> + for (int i = 0; i < N; i++)
> + {
> +   vect_a[i] = t + i;
> +   if (vect_a[i] == x)
> +     return i;
> +   vect_a[i] += x * vect_a[i];
> +   
> + }
> + return ret;
> +}
> diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc
> index 85b81d30c5ab869cb1f7323caabd9fe4648bdc50..0993d184afe068784474ac225768d9f38d76c040 100644
> --- a/gcc/tree-vect-loop.cc
> +++ b/gcc/tree-vect-loop.cc
> @@ -10856,8 +10856,8 @@ vectorizable_live_operation (vec_info *vinfo, stmt_vec_info stmt_info,
>    bitsize = vector_element_bits_tree (vectype);
>  
>    /* Get the vectorized lhs of STMT and the lane to use (counted in bits).  */
> -  tree vec_lhs, bitstart;
> -  gimple *vec_stmt;
> +  tree vec_lhs, vec_lhs0, bitstart;
> +  gimple *vec_stmt, *vec_stmt0;
>    if (slp_node)
>      {
>        gcc_assert (!loop_vinfo
> @@ -10868,6 +10868,10 @@ vectorizable_live_operation (vec_info *vinfo, stmt_vec_info stmt_info,
>        vec_lhs = SLP_TREE_VEC_DEFS (slp_node)[vec_entry];
>        vec_stmt = SSA_NAME_DEF_STMT (vec_lhs);
>  
> +      /* In case we need to early break vectorize also get the first stmt.  */
> +      vec_lhs0 = SLP_TREE_VEC_DEFS (slp_node)[0];
> +      vec_stmt0 = SSA_NAME_DEF_STMT (vec_lhs0);
> +
>        /* Get entry to use.  */
>        bitstart = bitsize_int (vec_index);
>        bitstart = int_const_binop (MULT_EXPR, bitsize, bitstart);
> @@ -10878,6 +10882,10 @@ vectorizable_live_operation (vec_info *vinfo, stmt_vec_info stmt_info,
>        vec_stmt = STMT_VINFO_VEC_STMTS (stmt_info).last ();
>        vec_lhs = gimple_get_lhs (vec_stmt);
>  
> +      /* In case we need to early break vectorize also get the first stmt.  */
> +      vec_stmt0 = STMT_VINFO_VEC_STMTS (stmt_info)[0];
> +      vec_lhs0 = gimple_get_lhs (vec_stmt0);
> +
>        /* Get the last lane in the vector.  */
>        bitstart = int_const_binop (MULT_EXPR, bitsize, bitsize_int (nunits - 1));
>      }
> @@ -10917,7 +10925,6 @@ vectorizable_live_operation (vec_info *vinfo, stmt_vec_info stmt_info,
>  		 so use ->src.  For main exit the merge block is the
>  		 destination.  */
>  	      basic_block dest = main_exit_edge ? main_e->dest : e->src;
> -	      gimple *tmp_vec_stmt = vec_stmt;
>  	      tree tmp_vec_lhs = vec_lhs;
>  	      tree tmp_bitstart = bitstart;
>  
> @@ -10928,8 +10935,7 @@ vectorizable_live_operation (vec_info *vinfo, stmt_vec_info stmt_info,
>  	      if (restart_loop
>  		  && STMT_VINFO_DEF_TYPE (stmt_info) == vect_induction_def)
>  		{
> -		  tmp_vec_stmt = STMT_VINFO_VEC_STMTS (stmt_info)[0];
> -		  tmp_vec_lhs = gimple_get_lhs (tmp_vec_stmt);
> +		  tmp_vec_lhs = vec_lhs0;
>  		  tmp_bitstart = build_zero_cst (TREE_TYPE (bitstart));
>  		}
>  
> 
> 
> 
> 
> 

-- 
Richard Biener <rguenther@suse.de>
SUSE Software Solutions Germany GmbH,
Frankenstrasse 146, 90461 Nuernberg, Germany;
GF: Ivo Totev, Andrew McDonald, Werner Knoblich; (HRB 36809, AG Nuernberg)

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

end of thread, other threads:[~2023-12-19 12:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-19 10:12 [PATCH]middle-end: Handle hybrid SLP induction vectorization with early breaks Tamar Christina
2023-12-19 12:36 ` Richard Biener

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