From: Robin Dapp <[email protected]>
In order to prepare for RVV codegen, this patch adds an enum that
determines the early-break "strategy". While SVE, neon, and
s390 use a mask-based approach, RVV prefers a scalar index-based one.
(From what I can see, s390 could also use that).
The patch doesn't cause any functional change.
gcc/ChangeLog:
* tree-vect-loop.cc (_loop_vec_info::_loop_vec_info):
Initialize.
* tree-vect-stmts.cc (vectorizable_early_exit): Set kind.
* tree-vectorizer.h (enum vect_early_break_kind): New.
(LOOP_VINFO_EARLY_BRK_KIND): New.
---
gcc/tree-vect-loop.cc | 2 ++
gcc/tree-vect-stmts.cc | 8 ++++++--
gcc/tree-vectorizer.h | 9 +++++++++
3 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc
index ce2ce2b8e17..fa013719ffb 100644
--- a/gcc/tree-vect-loop.cc
+++ b/gcc/tree-vect-loop.cc
@@ -796,6 +796,7 @@ _loop_vec_info::_loop_vec_info (class loop *loop_in,
vec_info_shared *shared,
vec_epilogue_loop_main_exit (NULL),
scalar_loop_main_exit (NULL),
early_break_needs_epilogue (false),
+ early_break_kind (vect_early_break_kind_none),
early_break_dependencies (NULL),
early_break_niters_var (NULL)
{
@@ -2808,6 +2809,7 @@ again:
LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo)
= saved_can_use_partial_vectors_p;
LOOP_VINFO_MUST_USE_PARTIAL_VECTORS_P (loop_vinfo) = false;
+ LOOP_VINFO_EARLY_BRK_KIND (loop_vinfo) = vect_early_break_kind_none;
LOOP_VINFO_USING_PARTIAL_VECTORS_P (loop_vinfo) = false;
LOOP_VINFO_USING_SELECT_VL_P (loop_vinfo) = false;
LOOP_VINFO_USING_DECREMENTING_IV_P (loop_vinfo) = false;
diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc
index 36fc15fbb6a..fd14ec66fa7 100644
--- a/gcc/tree-vect-stmts.cc
+++ b/gcc/tree-vect-stmts.cc
@@ -12933,8 +12933,10 @@ vectorizable_early_exit (loop_vec_info loop_vinfo,
stmt_vec_info stmt_info,
/* Analyze only. */
if (cost_vec)
{
- if (!addhn_supported_p
- && !supports_vector_compare_and_branch (loop_vinfo, mode))
+ if (addhn_supported_p
+ || supports_vector_compare_and_branch (loop_vinfo, mode))
+ LOOP_VINFO_EARLY_BRK_KIND (loop_vinfo) = vect_early_break_kind_mask;
+ else
{
if (dump_enabled_p ())
dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
@@ -13165,6 +13167,8 @@ vectorizable_early_exit (loop_vec_info loop_vinfo,
stmt_vec_info stmt_info,
new_temp = cmp_op;
}
+ gcc_checking_assert (LOOP_VINFO_EARLY_BRK_KIND (loop_vinfo)
+ == vect_early_break_kind_mask);
tree cst = build_zero_cst (vectype_out);
gimple_cond_set_condition (cond_stmt, NE_EXPR, new_temp, cst);
update_stmt (orig_stmt);
diff --git a/gcc/tree-vectorizer.h b/gcc/tree-vectorizer.h
index d59d580046c..13fc0d1431a 100644
--- a/gcc/tree-vectorizer.h
+++ b/gcc/tree-vectorizer.h
@@ -514,6 +514,11 @@ enum vect_partial_vector_style {
vect_partial_vectors_len
};
+enum vect_early_break_kind {
+ vect_early_break_kind_none,
+ vect_early_break_kind_mask
+};
+
/* Key for map that records association between
scalar conditions and corresponding loop mask, and
is populated by vect_record_loop_mask. */
@@ -1274,6 +1279,9 @@ public:
have a scalar epilogue. */
bool early_break_needs_epilogue;
+ /* The early break codegen strategy (index or mask based). */
+ vect_early_break_kind early_break_kind;
+
/* Used to store the list of stores needing to be moved if doing early
break vectorization as they would violate the scalar loop semantics if
vectorized in their current location. These are stored in order that they
@@ -1368,6 +1376,7 @@ public:
#define LOOP_VINFO_HAS_LIVE_STMT_P(L) (L)->has_live_stmts
#define LOOP_VINFO_EARLY_BREAKS(L) (L)->early_breaks
#define LOOP_VINFO_EARLY_BRK_NEEDS_EPILOG(L) (L)->early_break_needs_epilogue
+#define LOOP_VINFO_EARLY_BRK_KIND(L) (L)->early_break_kind
#define LOOP_VINFO_EARLY_BRK_STORES(L) (L)->early_break_stores
#define LOOP_VINFO_EARLY_BREAKS_VECT_PEELED(L) \
((single_pred ((L)->loop->latch) != (L)->vec_loop_main_exit->src) \
--
2.56.0