diff mbox series

[PATH,1/8] vect: Add a function to check lane-reducing stmt

Message ID LV2PR01MB78399AAAC2A71C16DE385732F7CC2@LV2PR01MB7839.prod.exchangelabs.com
State New
Headers show
Series [PATH,1/8] vect: Add a function to check lane-reducing stmt | expand

Commit Message

Feng Xue OS June 16, 2024, 7:20 a.m. UTC
The series of patches are meant to support multiple lane-reducing reduction statements. Since the original ones conflicted with the new single-lane slp node patches, I have reworked most of the patches, and split them as small as possible, which may make code review easier.

In the 1st one, I add a utility function to check if a statement is lane-reducing operation,
which could simplify some existing code.

Thanks,
Feng

---
gcc/
	* tree-vectorizer.h (lane_reducing_stmt_p): New function.
	* tree-vect-slp.cc (vect_analyze_slp): Use new function
	lane_reducing_stmt_p to check statement.
---
 gcc/tree-vect-slp.cc  |  4 +---
 gcc/tree-vectorizer.h | 12 ++++++++++++
 2 files changed, 13 insertions(+), 3 deletions(-)

Comments

Richard Biener June 19, 2024, 12:34 p.m. UTC | #1
On Sun, Jun 16, 2024 at 9:21 AM Feng Xue OS <fxue@os.amperecomputing.com> wrote:
>
> The series of patches are meant to support multiple lane-reducing reduction statements. Since the original ones conflicted with the new single-lane slp node patches, I have reworked most of the patches, and split them as small as possible, which may make code review easier.

Thanks for that - as always please feel free to push approved parts of
the series if dependences allow.

> In the 1st one, I add a utility function to check if a statement is lane-reducing operation,
> which could simplify some existing code.

OK.

Thanks,
Richard.

> Thanks,
> Feng
>
> ---
> gcc/
>         * tree-vectorizer.h (lane_reducing_stmt_p): New function.
>         * tree-vect-slp.cc (vect_analyze_slp): Use new function
>         lane_reducing_stmt_p to check statement.
> ---
>  gcc/tree-vect-slp.cc  |  4 +---
>  gcc/tree-vectorizer.h | 12 ++++++++++++
>  2 files changed, 13 insertions(+), 3 deletions(-)
>
> diff --git a/gcc/tree-vect-slp.cc b/gcc/tree-vect-slp.cc
> index 7e3d0107b4e..b4ea2e18f00 100644
> --- a/gcc/tree-vect-slp.cc
> +++ b/gcc/tree-vect-slp.cc
> @@ -3919,7 +3919,6 @@ vect_analyze_slp (vec_info *vinfo, unsigned max_tree_size)
>           scalar_stmts.create (loop_vinfo->reductions.length ());
>           for (auto next_info : loop_vinfo->reductions)
>             {
> -             gassign *g;
>               next_info = vect_stmt_to_vectorize (next_info);
>               if ((STMT_VINFO_RELEVANT_P (next_info)
>                    || STMT_VINFO_LIVE_P (next_info))
> @@ -3931,8 +3930,7 @@ vect_analyze_slp (vec_info *vinfo, unsigned max_tree_size)
>                 {
>                   /* Do not discover SLP reductions combining lane-reducing
>                      ops, that will fail later.  */
> -                 if (!(g = dyn_cast <gassign *> (STMT_VINFO_STMT (next_info)))
> -                     || !lane_reducing_op_p (gimple_assign_rhs_code (g)))
> +                 if (!lane_reducing_stmt_p (STMT_VINFO_STMT (next_info)))
>                     scalar_stmts.quick_push (next_info);
>                   else
>                     {
> diff --git a/gcc/tree-vectorizer.h b/gcc/tree-vectorizer.h
> index 6bb0f5c3a56..60224f4e284 100644
> --- a/gcc/tree-vectorizer.h
> +++ b/gcc/tree-vectorizer.h
> @@ -2169,12 +2169,24 @@ vect_apply_runtime_profitability_check_p (loop_vec_info loop_vinfo)
>           && th >= vect_vf_for_cost (loop_vinfo));
>  }
>
> +/* Return true if CODE is a lane-reducing opcode.  */
> +
>  inline bool
>  lane_reducing_op_p (code_helper code)
>  {
>    return code == DOT_PROD_EXPR || code == WIDEN_SUM_EXPR || code == SAD_EXPR;
>  }
>
> +/* Return true if STMT is a lane-reducing statement.  */
> +
> +inline bool
> +lane_reducing_stmt_p (gimple *stmt)
> +{
> +  if (auto *assign = dyn_cast <gassign *> (stmt))
> +    return lane_reducing_op_p (gimple_assign_rhs_code (assign));
> +  return false;
> +}
> +
>  /* Source location + hotness information. */
>  extern dump_user_location_t vect_location;
>
> --
> 2.17.1
diff mbox series

Patch

From 0a90550b4ed3addfb2a36c40085bfa9b4bb05b7c Mon Sep 17 00:00:00 2001
From: Feng Xue <fxue@os.amperecomputing.com>
Date: Sat, 15 Jun 2024 23:17:10 +0800
Subject: [PATCH 1/8] vect: Add a function to check lane-reducing stmt

Add a utility function to check if a statement is lane-reducing operation,
which could simplify some existing code.

2024-06-16 Feng Xue <fxue@os.amperecomputing.com>

gcc/
	* tree-vectorizer.h (lane_reducing_stmt_p): New function.
	* tree-vect-slp.cc (vect_analyze_slp): Use new function
	lane_reducing_stmt_p to check statement.
---
 gcc/tree-vect-slp.cc  |  4 +---
 gcc/tree-vectorizer.h | 12 ++++++++++++
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/gcc/tree-vect-slp.cc b/gcc/tree-vect-slp.cc
index 7e3d0107b4e..b4ea2e18f00 100644
--- a/gcc/tree-vect-slp.cc
+++ b/gcc/tree-vect-slp.cc
@@ -3919,7 +3919,6 @@  vect_analyze_slp (vec_info *vinfo, unsigned max_tree_size)
 	  scalar_stmts.create (loop_vinfo->reductions.length ());
 	  for (auto next_info : loop_vinfo->reductions)
 	    {
-	      gassign *g;
 	      next_info = vect_stmt_to_vectorize (next_info);
 	      if ((STMT_VINFO_RELEVANT_P (next_info)
 		   || STMT_VINFO_LIVE_P (next_info))
@@ -3931,8 +3930,7 @@  vect_analyze_slp (vec_info *vinfo, unsigned max_tree_size)
 		{
 		  /* Do not discover SLP reductions combining lane-reducing
 		     ops, that will fail later.  */
-		  if (!(g = dyn_cast <gassign *> (STMT_VINFO_STMT (next_info)))
-		      || !lane_reducing_op_p (gimple_assign_rhs_code (g)))
+		  if (!lane_reducing_stmt_p (STMT_VINFO_STMT (next_info)))
 		    scalar_stmts.quick_push (next_info);
 		  else
 		    {
diff --git a/gcc/tree-vectorizer.h b/gcc/tree-vectorizer.h
index 6bb0f5c3a56..60224f4e284 100644
--- a/gcc/tree-vectorizer.h
+++ b/gcc/tree-vectorizer.h
@@ -2169,12 +2169,24 @@  vect_apply_runtime_profitability_check_p (loop_vec_info loop_vinfo)
 	  && th >= vect_vf_for_cost (loop_vinfo));
 }
 
+/* Return true if CODE is a lane-reducing opcode.  */
+
 inline bool
 lane_reducing_op_p (code_helper code)
 {
   return code == DOT_PROD_EXPR || code == WIDEN_SUM_EXPR || code == SAD_EXPR;
 }
 
+/* Return true if STMT is a lane-reducing statement.  */
+
+inline bool
+lane_reducing_stmt_p (gimple *stmt)
+{
+  if (auto *assign = dyn_cast <gassign *> (stmt))
+    return lane_reducing_op_p (gimple_assign_rhs_code (assign));
+  return false;
+}
+
 /* Source location + hotness information. */
 extern dump_user_location_t vect_location;
 
-- 
2.17.1