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 <[email protected]>
Sent: Thursday, May 30, 2024 10:51 PM
To: Richard Biener
Cc: Tamar Christina; [email protected]
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
From 2270584f95637e88cf05a9c3f8bfc77c37eab979 Mon Sep 17 00:00:00 2001
From: Feng Xue <[email protected]>
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 <[email protected]>
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