public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH 3/6] vect: Set STMT_VINFO_REDUC_DEF for non-live stmt in loop reduction
@ 2024-05-30 14:51 Feng Xue OS
  2024-06-14  3:51 ` Feng Xue OS
  0 siblings, 1 reply; 2+ messages in thread
From: Feng Xue OS @ 2024-05-30 14:51 UTC (permalink / raw)
  To: Richard Biener; +Cc: Tamar Christina, gcc-patches

Normally, vectorizable checking on statement in a loop reduction chain does
not use the reduction PHI information. But some special statements might
need it in vectorizable analysis, especially, for multiple lane-reducing
operations support later.

Thanks,
Feng
---
gcc/
	* tree-vect-loop.cc (vectorizable_reduction): Set STMT_VINFO_REDUC_DEF
	for non-live stmt.
	* tree-vect-stmts.cc (vectorizable_condition): Treat the condition
    	statement that is pointed by stmt_vec_info of reduction PHI as the
    	real "for_reduction" statement.
---
 gcc/tree-vect-loop.cc  |  5 +++--
 gcc/tree-vect-stmts.cc | 11 ++++++++++-
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc
index aa5f21ccd1a..51627c27f8a 100644
--- a/gcc/tree-vect-loop.cc
+++ b/gcc/tree-vect-loop.cc
@@ -7632,14 +7632,15 @@ vectorizable_reduction (loop_vec_info loop_vinfo,
 	 all lanes here - even though we only will vectorize from
 	 the SLP node with live lane zero the other live lanes also
 	 need to be identified as part of a reduction to be able
-	 to skip code generation for them.  */
+	 to skip code generation for them.  For lane-reducing operation
+	 vectorizable analysis needs the reduction PHI information.  */
       if (slp_for_stmt_info)
 	{
 	  for (auto s : SLP_TREE_SCALAR_STMTS (slp_for_stmt_info))
 	    if (STMT_VINFO_LIVE_P (s))
 	      STMT_VINFO_REDUC_DEF (vect_orig_stmt (s)) = phi_info;
 	}
-      else if (STMT_VINFO_LIVE_P (vdef))
+      else
 	STMT_VINFO_REDUC_DEF (def) = phi_info;
       gimple_match_op op;
       if (!gimple_extract_op (vdef->stmt, &op))
diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc
index 935d80f0e1b..2e0be763abb 100644
--- a/gcc/tree-vect-stmts.cc
+++ b/gcc/tree-vect-stmts.cc
@@ -12094,11 +12094,20 @@ vectorizable_condition (vec_info *vinfo,
   vect_reduction_type reduction_type = TREE_CODE_REDUCTION;
   bool for_reduction
     = STMT_VINFO_REDUC_DEF (vect_orig_stmt (stmt_info)) != NULL;
+  if (for_reduction)
+    {
+      reduc_info = info_for_reduction (vinfo, stmt_info);
+      if (STMT_VINFO_REDUC_DEF (reduc_info) != vect_orig_stmt (stmt_info))
+	{
+	  for_reduction = false;
+	  reduc_info = NULL;
+	}
+    }
+
   if (for_reduction)
     {
       if (slp_node)
 	return false;
-      reduc_info = info_for_reduction (vinfo, stmt_info);
       reduction_type = STMT_VINFO_REDUC_TYPE (reduc_info);
       reduc_index = STMT_VINFO_REDUC_IDX (stmt_info);
       gcc_assert (reduction_type != EXTRACT_LAST_REDUCTION
-- 
2.17.1

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

* Re: [PATCH 3/6] vect: Set STMT_VINFO_REDUC_DEF for non-live stmt in loop  reduction
  2024-05-30 14:51 [PATCH 3/6] vect: Set STMT_VINFO_REDUC_DEF for non-live stmt in loop reduction Feng Xue OS
@ 2024-06-14  3:51 ` Feng Xue OS
  0 siblings, 0 replies; 2+ messages in thread
From: Feng Xue OS @ 2024-06-14  3:51 UTC (permalink / raw)
  To: Richard Biener; +Cc: Tamar Christina, gcc-patches

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

Updated the patch.

Thanks,
Feng
--

gcc/
        * tree-vect-loop.cc (vectorizable_reduction): Set STMT_VINFO_REDUC_DEF
        for non-live stmt.
        * tree-vect-stmts.cc (vectorizable_condition): Treat the condition
        statement that is pointed by stmt_vec_info of reduction PHI as the
        real "for_reduction" statement.
---
 gcc/tree-vect-loop.cc  |  7 +++++--
 gcc/tree-vect-stmts.cc | 11 ++++++++++-
 2 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc
index bbd5d261907..35c50eb72cb 100644
--- a/gcc/tree-vect-loop.cc
+++ b/gcc/tree-vect-loop.cc
@@ -7665,8 +7665,11 @@ vectorizable_reduction (loop_vec_info loop_vinfo,
            if (STMT_VINFO_LIVE_P (s))
              STMT_VINFO_REDUC_DEF (vect_orig_stmt (s)) = phi_info;
        }
-      else if (STMT_VINFO_LIVE_P (vdef))
-       STMT_VINFO_REDUC_DEF (def) = phi_info;
+
+      /* For lane-reducing operation vectorizable analysis needs the
+        reduction PHI information */
+      STMT_VINFO_REDUC_DEF (def) = phi_info;
+
       gimple_match_op op;
       if (!gimple_extract_op (vdef->stmt, &op))
        {
diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc
index e32d44050e5..dbdb59054e0 100644
--- a/gcc/tree-vect-stmts.cc
+++ b/gcc/tree-vect-stmts.cc
@@ -12137,11 +12137,20 @@ vectorizable_condition (vec_info *vinfo,
   vect_reduction_type reduction_type = TREE_CODE_REDUCTION;
   bool for_reduction
     = STMT_VINFO_REDUC_DEF (vect_orig_stmt (stmt_info)) != NULL;
+  if (for_reduction)
+    {
+      reduc_info = info_for_reduction (vinfo, stmt_info);
+      if (STMT_VINFO_REDUC_DEF (reduc_info) != vect_orig_stmt (stmt_info))
+       {
+         for_reduction = false;
+         reduc_info = NULL;
+       }
+    }
+
   if (for_reduction)
     {
       if (slp_node && SLP_TREE_LANES (slp_node) > 1)
        return false;
-      reduc_info = info_for_reduction (vinfo, stmt_info);
       reduction_type = STMT_VINFO_REDUC_TYPE (reduc_info);
       reduc_index = STMT_VINFO_REDUC_IDX (stmt_info);
       gcc_assert (reduction_type != EXTRACT_LAST_REDUCTION
--
2.17.1

________________________________________
From: Feng Xue OS <fxue@os.amperecomputing.com>
Sent: Thursday, May 30, 2024 10:51 PM
To: Richard Biener
Cc: Tamar Christina; gcc-patches@gcc.gnu.org
Subject: [PATCH 3/6] vect: Set STMT_VINFO_REDUC_DEF for non-live stmt in loop  reduction

Normally, vectorizable checking on statement in a loop reduction chain does
not use the reduction PHI information. But some special statements might
need it in vectorizable analysis, especially, for multiple lane-reducing
operations support later.

Thanks,
Feng
---
gcc/
        * tree-vect-loop.cc (vectorizable_reduction): Set STMT_VINFO_REDUC_DEF
        for non-live stmt.
        * tree-vect-stmts.cc (vectorizable_condition): Treat the condition
        statement that is pointed by stmt_vec_info of reduction PHI as the
        real "for_reduction" statement.
---
 gcc/tree-vect-loop.cc  |  5 +++--
 gcc/tree-vect-stmts.cc | 11 ++++++++++-
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc
index aa5f21ccd1a..51627c27f8a 100644
--- a/gcc/tree-vect-loop.cc
+++ b/gcc/tree-vect-loop.cc
@@ -7632,14 +7632,15 @@ vectorizable_reduction (loop_vec_info loop_vinfo,
         all lanes here - even though we only will vectorize from
         the SLP node with live lane zero the other live lanes also
         need to be identified as part of a reduction to be able
-        to skip code generation for them.  */
+        to skip code generation for them.  For lane-reducing operation
+        vectorizable analysis needs the reduction PHI information.  */
       if (slp_for_stmt_info)
        {
          for (auto s : SLP_TREE_SCALAR_STMTS (slp_for_stmt_info))
            if (STMT_VINFO_LIVE_P (s))
              STMT_VINFO_REDUC_DEF (vect_orig_stmt (s)) = phi_info;
        }
-      else if (STMT_VINFO_LIVE_P (vdef))
+      else
        STMT_VINFO_REDUC_DEF (def) = phi_info;
       gimple_match_op op;
       if (!gimple_extract_op (vdef->stmt, &op))
diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc
index 935d80f0e1b..2e0be763abb 100644
--- a/gcc/tree-vect-stmts.cc
+++ b/gcc/tree-vect-stmts.cc
@@ -12094,11 +12094,20 @@ vectorizable_condition (vec_info *vinfo,
   vect_reduction_type reduction_type = TREE_CODE_REDUCTION;
   bool for_reduction
     = STMT_VINFO_REDUC_DEF (vect_orig_stmt (stmt_info)) != NULL;
+  if (for_reduction)
+    {
+      reduc_info = info_for_reduction (vinfo, stmt_info);
+      if (STMT_VINFO_REDUC_DEF (reduc_info) != vect_orig_stmt (stmt_info))
+       {
+         for_reduction = false;
+         reduc_info = NULL;
+       }
+    }
+
   if (for_reduction)
     {
       if (slp_node)
        return false;
-      reduc_info = info_for_reduction (vinfo, stmt_info);
       reduction_type = STMT_VINFO_REDUC_TYPE (reduc_info);
       reduc_index = STMT_VINFO_REDUC_IDX (stmt_info);
       gcc_assert (reduction_type != EXTRACT_LAST_REDUCTION
--
2.17.1

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-vect-Set-STMT_VINFO_REDUC_DEF-for-non-live-stmt-in-l.patch --]
[-- Type: text/x-patch; name="0001-vect-Set-STMT_VINFO_REDUC_DEF-for-non-live-stmt-in-l.patch", Size: 2541 bytes --]

From 2270584f95637e88cf05a9c3f8bfc77c37eab979 Mon Sep 17 00:00:00 2001
From: Feng Xue <fxue@os.amperecomputing.com>
Date: Wed, 29 May 2024 14:41:34 +0800
Subject: [PATCH 1/3] vect: Set STMT_VINFO_REDUC_DEF for non-live stmt in loop
 reduction

Normally, vectorizable checking on statement in a loop reduction chain does
not use the reduction PHI information. But some special statements might
need it in vectorizable analysis, especially, for multiple lane-reducing
operations support later.

2024-05-29 Feng Xue <fxue@os.amperecomputing.com>

gcc/
	* tree-vect-loop.cc (vectorizable_reduction): Set STMT_VINFO_REDUC_DEF
	for non-live stmt.
	* tree-vect-stmts.cc (vectorizable_condition): Treat the condition
    	statement that is pointed by stmt_vec_info of reduction PHI as the
    	real "for_reduction" statement.
---
 gcc/tree-vect-loop.cc  |  7 +++++--
 gcc/tree-vect-stmts.cc | 11 ++++++++++-
 2 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc
index bbd5d261907..35c50eb72cb 100644
--- a/gcc/tree-vect-loop.cc
+++ b/gcc/tree-vect-loop.cc
@@ -7665,8 +7665,11 @@ vectorizable_reduction (loop_vec_info loop_vinfo,
 	    if (STMT_VINFO_LIVE_P (s))
 	      STMT_VINFO_REDUC_DEF (vect_orig_stmt (s)) = phi_info;
 	}
-      else if (STMT_VINFO_LIVE_P (vdef))
-	STMT_VINFO_REDUC_DEF (def) = phi_info;
+
+      /* For lane-reducing operation vectorizable analysis needs the
+	 reduction PHI information */
+      STMT_VINFO_REDUC_DEF (def) = phi_info;
+
       gimple_match_op op;
       if (!gimple_extract_op (vdef->stmt, &op))
 	{
diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc
index e32d44050e5..dbdb59054e0 100644
--- a/gcc/tree-vect-stmts.cc
+++ b/gcc/tree-vect-stmts.cc
@@ -12137,11 +12137,20 @@ vectorizable_condition (vec_info *vinfo,
   vect_reduction_type reduction_type = TREE_CODE_REDUCTION;
   bool for_reduction
     = STMT_VINFO_REDUC_DEF (vect_orig_stmt (stmt_info)) != NULL;
+  if (for_reduction)
+    {
+      reduc_info = info_for_reduction (vinfo, stmt_info);
+      if (STMT_VINFO_REDUC_DEF (reduc_info) != vect_orig_stmt (stmt_info))
+	{
+	  for_reduction = false;
+	  reduc_info = NULL;
+	}
+    }
+
   if (for_reduction)
     {
       if (slp_node && SLP_TREE_LANES (slp_node) > 1)
 	return false;
-      reduc_info = info_for_reduction (vinfo, stmt_info);
       reduction_type = STMT_VINFO_REDUC_TYPE (reduc_info);
       reduc_index = STMT_VINFO_REDUC_IDX (stmt_info);
       gcc_assert (reduction_type != EXTRACT_LAST_REDUCTION
-- 
2.17.1


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

end of thread, other threads:[~2024-06-14  3:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-30 14:51 [PATCH 3/6] vect: Set STMT_VINFO_REDUC_DEF for non-live stmt in loop reduction Feng Xue OS
2024-06-14  3:51 ` Feng Xue OS

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