[gcc(refs/users/marxin/heads/slp-ebb-v2)] Handle non-empty basic blocks.
Martin Liska
marxin@gcc.gnu.org
Mon Oct 5 12:18:18 GMT 2020
https://gcc.gnu.org/g:802fefb4dbab5c558e4ab671e6f0a9b29e7875bb
commit 802fefb4dbab5c558e4ab671e6f0a9b29e7875bb
Author: Martin Liska <mliska@suse.cz>
Date: Thu Sep 24 15:15:00 2020 +0200
Handle non-empty basic blocks.
Diff:
---
gcc/tree-vect-slp.c | 35 +++++++++++++++++++++--------------
gcc/tree-vectorizer.c | 6 +++---
gcc/tree-vectorizer.h | 25 +++++++++++++++----------
3 files changed, 39 insertions(+), 27 deletions(-)
diff --git a/gcc/tree-vect-slp.c b/gcc/tree-vect-slp.c
index 2cea4cf89fa..9cd76a46ff3 100644
--- a/gcc/tree-vect-slp.c
+++ b/gcc/tree-vect-slp.c
@@ -2729,10 +2729,10 @@ vect_detect_hybrid_slp (loop_vec_info loop_vinfo)
/* Initialize a bb_vec_info struct for the statements in BBS basic blocks. */
-_bb_vec_info::_bb_vec_info (vec<basic_block> _bbs,
- vec_info_shared *shared)
+_bb_vec_info::_bb_vec_info (vec<basic_block> _bbs, vec<basic_block>
+ _nonempty_bbs, vec_info_shared *shared)
: vec_info (vec_info::bb, init_cost (NULL), shared),
- bbs (_bbs)
+ bbs (_bbs), nonempty_bbs (_nonempty_bbs)
{
for (gimple *stmt : this->region_stmts ())
{
@@ -3598,7 +3598,7 @@ vect_slp_analyze_bb_1 (bb_vec_info bb_vinfo, int n_stmts, bool &fatal,
The region has N_STMTS statements and has the datarefs given by DATAREFS. */
static bool
-vect_slp_region (vec<basic_block> bbs,
+vect_slp_region (vec<basic_block> bbs, vec<basic_block> nonempty_bbs,
vec<data_reference_p> datarefs,
vec<int> *dataref_groups,
unsigned int n_stmts)
@@ -3618,7 +3618,7 @@ vect_slp_region (vec<basic_block> bbs,
{
bool vectorized = false;
bool fatal = false;
- bb_vinfo = new _bb_vec_info (bbs, &shared);
+ bb_vinfo = new _bb_vec_info (bbs, nonempty_bbs, &shared);
bool first_time_p = shared.datarefs.is_empty ();
BB_VINFO_DATAREFS (bb_vinfo) = datarefs;
@@ -3751,6 +3751,18 @@ vect_slp_bbs (vec<basic_block> bbs)
vec<int> dataref_groups = vNULL;
int insns = 0;
int current_group = 0;
+ auto_vec<basic_block> nonempty_bbs;
+
+ for (unsigned i = 0; i < bbs.length (); i++)
+ {
+ basic_block bb = bbs[i];
+ gimple_stmt_iterator gsi = gsi_start_nondebug_after_labels_bb (bb);
+ if (!gsi_end_p (gsi))
+ nonempty_bbs.safe_push (bb);
+ }
+
+ if (nonempty_bbs.is_empty ())
+ return false;
for (unsigned i = 0; i < bbs.length (); i++)
{
@@ -3781,7 +3793,7 @@ vect_slp_bbs (vec<basic_block> bbs)
}
}
- return vect_slp_region (bbs, datarefs, &dataref_groups, insns);
+ return vect_slp_region (bbs, nonempty_bbs, datarefs, &dataref_groups, insns);
}
/* Main entry for the BB vectorizer. Analyze and transform BB, returns
@@ -3811,18 +3823,13 @@ vect_slp_function ()
{
basic_block bb = BASIC_BLOCK_FOR_FN (cfun, rpo[i]);
gphi_iterator phi = gsi_start_phis (bb);
- gimple_stmt_iterator gsi = gsi_start_nondebug_after_labels_bb (bb);
if (gsi_end_p (phi))
- {
- if (!gsi_end_p (gsi))
- ebb.safe_push (bb);
- }
+ ebb.safe_push (bb);
else if (!ebb.is_empty ())
{
r |= vect_slp_bbs (ebb);
ebb.truncate (0);
- if (!gsi_end_p (gsi))
- ebb.quick_push (bb);
+ ebb.quick_push (bb);
}
}
@@ -4709,7 +4716,7 @@ vect_schedule_slp_instance (vec_info *vinfo,
we do not insert before the region boundary. */
if (SLP_TREE_SCALAR_OPS (child).is_empty ()
&& !vinfo->lookup_def (SLP_TREE_VEC_DEFS (child)[0]))
- last_stmt = gsi_stmt (as_a <bb_vec_info> (vinfo)->region_begin ());
+ last_stmt = gsi_stmt (as_a <bb_vec_info> (vinfo)->region_begin (false));
else
{
unsigned j;
diff --git a/gcc/tree-vectorizer.c b/gcc/tree-vectorizer.c
index 658bd19bbc9..e218bdcab58 100644
--- a/gcc/tree-vectorizer.c
+++ b/gcc/tree-vectorizer.c
@@ -607,8 +607,8 @@ vec_info::remove_stmt (stmt_vec_info stmt_info)
gimple_stmt_iterator si = gsi_for_stmt (stmt_info->stmt);
gimple_stmt_iterator psi = si;
if (bb_vec_info bb_vinfo = dyn_cast <bb_vec_info> (this))
- if (gsi_stmt (bb_vinfo->region_begin ()) == stmt_info->stmt)
- psi = bb_vinfo->region_begin ();
+ if (gsi_stmt (bb_vinfo->region_begin (false)) == stmt_info->stmt)
+ psi = bb_vinfo->region_begin (false);
gsi_remove (&psi, true);
release_defs (stmt_info->stmt);
free_stmt_vec_info (stmt_info);
@@ -653,7 +653,7 @@ vec_info::insert_seq_on_entry (stmt_vec_info context, gimple_seq seq)
else
{
bb_vec_info bb_vinfo = as_a <bb_vec_info> (this);
- gimple_stmt_iterator gsi_region_begin = bb_vinfo->region_begin ();
+ gimple_stmt_iterator gsi_region_begin = bb_vinfo->region_begin (false);
gsi_insert_seq_before (&gsi_region_begin, seq, GSI_SAME_STMT);
}
}
diff --git a/gcc/tree-vectorizer.h b/gcc/tree-vectorizer.h
index 9c54bab2916..49d7470c296 100644
--- a/gcc/tree-vectorizer.h
+++ b/gcc/tree-vectorizer.h
@@ -905,19 +905,22 @@ public:
int bb_index;
};
- _bb_vec_info (vec<basic_block> bbs, vec_info_shared *);
+ _bb_vec_info (vec<basic_block> bbs, vec<basic_block> nonempty_bbs,
+ vec_info_shared *);
~_bb_vec_info ();
// TODO
- gimple_stmt_iterator region_begin ()
+ gimple_stmt_iterator region_begin (bool non_empty_bb)
{
- return gsi_start_nondebug_after_labels_bb (bbs[0]);
+ vec<basic_block> &v = non_empty_bb ? nonempty_bbs : bbs;
+ return gsi_start_nondebug_after_labels_bb (v[0]);
}
// TODO
- gimple_stmt_iterator region_end ()
+ gimple_stmt_iterator region_end (bool non_empty_bb)
{
- gimple_stmt_iterator gsi = gsi_last_bb (bbs[bbs.length () - 1]);
+ vec<basic_block> &v = non_empty_bb ? nonempty_bbs : bbs;
+ gimple_stmt_iterator gsi = gsi_last_bb (v[v.length () - 1]);
if (!gsi_end_p (gsi))
gsi_next (&gsi);
return gsi;
@@ -928,8 +931,8 @@ public:
iterator_range<const_iterator>
region_stmts ()
{
- return iterator_range<const_iterator> (const_iterator (region_begin (), bbs),
- const_iterator (region_end (), bbs));
+ return iterator_range<const_iterator> (const_iterator (region_begin (true), nonempty_bbs),
+ const_iterator (region_end (true), nonempty_bbs));
}
/* Returns iterator_range for range-based loop in a reverse order. */
@@ -937,17 +940,19 @@ public:
iterator_range<const_reverse_iterator>
reverse_region_stmts ()
{
- const_reverse_iterator begin (region_end (), bbs);
+ const_reverse_iterator begin (region_end (true), nonempty_bbs);
if (*begin == NULL)
- begin = const_reverse_iterator (gsi_last_bb (gsi_bb (region_end ())), bbs);
+ begin = const_reverse_iterator (gsi_last_bb (gsi_bb (region_end (true))),
+ nonempty_bbs);
else
++begin;
- const_reverse_iterator end (region_begin (), bbs);
+ const_reverse_iterator end (region_begin (true), nonempty_bbs);
return iterator_range<const_reverse_iterator> (begin, ++end);
}
vec<basic_block> bbs;
+ vec<basic_block> nonempty_bbs;
} *bb_vec_info;
#define BB_VINFO_BB(B) (B)->bb
More information about the Gcc-cvs
mailing list