[PATCH] Simplify vect_get_vec_defs API
Richard Biener <[email protected]> Wed, 5 Aug 2026 14:47:35 +0200 (CEST)
| Newsgroups | gmane.comp.gcc.patches |
|---|---|
| Message-ID | <[email protected]> |
The folowing simplifies vect_get_vec_defs to take a bool instead of
a tree argument to indicate whether to fill the vector definitions
vector for an operand. This is a tiny step to avoid accessing
scalar operands determined by vect_is_simple_use. It also cleans
up code a bit.
Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.
* tree-vectorizer.h (vect_get_vec_defs): Adjust to take
bool instead of tree arguments.
* tree-vect-stmts.cc (vect_get_vec_defs): Likewise.
(vectorizable_bswap): Simplify.
(vectorizable_conversion): Likewise.
(vectorizable_assignment): Likewise.
(vectorizable_shift): Likewise.
(vectorizable_operation): Likewise.
(vectorizable_condition): Likewise.
(vectorizable_comparison_1): Likewise.
* tree-vect-loop.cc (vect_transform_lc_phi): Likewise.
---
gcc/tree-vect-loop.cc | 3 +--
gcc/tree-vect-stmts.cc | 52 ++++++++++++++++--------------------------
gcc/tree-vectorizer.h | 8 +++----
3 files changed, 25 insertions(+), 38 deletions(-)
diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc
index a336df81bc7..a1e60a31ecb 100644
--- a/gcc/tree-vect-loop.cc
+++ b/gcc/tree-vect-loop.cc
@@ -8557,8 +8557,7 @@ vect_transform_lc_phi (loop_vec_info loop_vinfo,
edge e = single_pred_edge (bb);
tree vec_dest = vect_create_destination_var (scalar_dest, vectype);
auto_vec<tree> vec_oprnds;
- vect_get_vec_defs (loop_vinfo, slp_node,
- gimple_phi_arg_def (stmt_info->stmt, 0), &vec_oprnds);
+ vect_get_vec_defs (loop_vinfo, slp_node, true, &vec_oprnds);
for (unsigned i = 0; i < vec_oprnds.length (); i++)
{
/* Create the vectorized LC PHI node. */
diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc
index 372995a91d1..0627dfaefac 100644
--- a/gcc/tree-vect-stmts.cc
+++ b/gcc/tree-vect-stmts.cc
@@ -1243,10 +1243,10 @@ vect_init_vector (vec_info *vinfo, stmt_vec_info stmt_info, tree val, tree type,
void
vect_get_vec_defs (vec_info *, slp_tree slp_node,
- tree op0, vec<tree> *vec_oprnds0,
- tree op1, vec<tree> *vec_oprnds1,
- tree op2, vec<tree> *vec_oprnds2,
- tree op3, vec<tree> *vec_oprnds3)
+ bool op0, vec<tree> *vec_oprnds0,
+ bool op1, vec<tree> *vec_oprnds1,
+ bool op2, vec<tree> *vec_oprnds2,
+ bool op3, vec<tree> *vec_oprnds3)
{
if (op0)
vect_get_slp_defs (SLP_TREE_CHILDREN (slp_node)[0], vec_oprnds0);
@@ -3288,11 +3288,7 @@ vectorizable_bswap (vec_info *vinfo,
slp_tree *slp_op,
tree vectype_in, stmt_vector_for_cost *cost_vec)
{
- tree op, vectype;
- gcall *stmt = as_a <gcall *> (stmt_info->stmt);
-
- op = gimple_call_arg (stmt, 0);
- vectype = SLP_TREE_VECTYPE (slp_node);
+ tree vectype = SLP_TREE_VECTYPE (slp_node);
poly_uint64 nunits = TYPE_VECTOR_SUBPARTS (vectype);
if (TYPE_SIZE (vectype_in) != TYPE_SIZE (vectype))
@@ -3348,7 +3344,7 @@ vectorizable_bswap (vec_info *vinfo,
/* Transform. */
vec<tree> vec_oprnds = vNULL;
- vect_get_vec_defs (vinfo, slp_node, op, &vec_oprnds);
+ vect_get_vec_defs (vinfo, slp_node, true, &vec_oprnds);
/* Arguments are ready. create the new vector stmt. */
unsigned i;
tree vop;
@@ -5775,7 +5771,7 @@ vectorizable_conversion (vec_info *vinfo,
switch (modifier)
{
case NONE:
- vect_get_vec_defs (vinfo, slp_node, op0, &vec_oprnds0);
+ vect_get_vec_defs (vinfo, slp_node, true, &vec_oprnds0);
/* vec_dest is intermediate type operand when multi_step_cvt. */
if (multi_step_cvt)
{
@@ -5810,9 +5806,8 @@ vectorizable_conversion (vec_info *vinfo,
of elements that we can fit in a vectype (nunits), we have to
generate more than one vector stmt - i.e - we need to "unroll"
the vector stmt by a factor VF/nunits. */
- vect_get_vec_defs (vinfo, slp_node, op0, &vec_oprnds0,
- code == WIDEN_LSHIFT_EXPR ? NULL_TREE : op1,
- &vec_oprnds1);
+ vect_get_vec_defs (vinfo, slp_node, true, &vec_oprnds0,
+ code != WIDEN_LSHIFT_EXPR && slp_op1, &vec_oprnds1);
if (code == WIDEN_LSHIFT_EXPR)
{
int oprnds_size = vec_oprnds0.length ();
@@ -5863,7 +5858,7 @@ vectorizable_conversion (vec_info *vinfo,
of elements that we can fit in a vectype (nunits), we have to
generate more than one vector stmt - i.e - we need to "unroll"
the vector stmt by a factor VF/nunits. */
- vect_get_vec_defs (vinfo, slp_node, op0, &vec_oprnds0);
+ vect_get_vec_defs (vinfo, slp_node, true, &vec_oprnds0);
/* Arguments are ready. Create the new vector stmts. */
if (cvt_type && modifier == NARROW_DST)
FOR_EACH_VEC_ELT (vec_oprnds0, i, vop0)
@@ -6068,7 +6063,7 @@ vectorizable_assignment (vec_info *vinfo,
vec_dest = vect_create_destination_var (scalar_dest, vectype);
/* Handle use. */
- vect_get_vec_defs (vinfo, slp_node, op, &vec_oprnds);
+ vect_get_vec_defs (vinfo, slp_node, true, &vec_oprnds);
/* Arguments are ready. create the new vector stmt. */
FOR_EACH_VEC_ELT (vec_oprnds, i, vop)
@@ -6472,8 +6467,7 @@ vectorizable_shift (vec_info *vinfo,
(a special case for certain kind of vector shifts); otherwise,
operand 1 should be of a vector type (the usual case). */
vect_get_vec_defs (vinfo, slp_node,
- op0, &vec_oprnds0,
- vec_oprnd1 ? NULL_TREE : op1, &vec_oprnds1);
+ true, &vec_oprnds0, !vec_oprnd1, &vec_oprnds1);
/* Arguments are ready. Create the new vector stmt. */
FOR_EACH_VEC_ELT (vec_oprnds0, i, vop0)
@@ -6900,8 +6894,8 @@ vectorizable_operation (vec_info *vinfo,
else
vec_dest = vect_create_destination_var (scalar_dest, vectype_out);
- vect_get_vec_defs (vinfo, slp_node,
- op0, &vec_oprnds0, op1, &vec_oprnds1, op2, &vec_oprnds2);
+ vect_get_vec_defs (vinfo, slp_node, true, &vec_oprnds0,
+ slp_op1, &vec_oprnds1, slp_op2, &vec_oprnds2);
/* Arguments are ready. Create the new vector stmt. */
FOR_EACH_VEC_ELT (vec_oprnds0, i, vop0)
{
@@ -12448,18 +12442,12 @@ vectorizable_condition (vec_info *vinfo,
/* Handle cond expr. */
if (masked)
- vect_get_vec_defs (vinfo, slp_node,
- cond_expr, &vec_oprnds0,
- then_clause, &vec_oprnds2,
- reduction_type != EXTRACT_LAST_REDUCTION
- ? else_clause : NULL, &vec_oprnds3);
+ vect_get_vec_defs (vinfo, slp_node, true, &vec_oprnds0, true, &vec_oprnds2,
+ reduction_type != EXTRACT_LAST_REDUCTION, &vec_oprnds3);
else
- vect_get_vec_defs (vinfo, slp_node,
- cond_expr0, &vec_oprnds0,
- cond_expr1, &vec_oprnds1,
- then_clause, &vec_oprnds2,
- reduction_type != EXTRACT_LAST_REDUCTION
- ? else_clause : NULL, &vec_oprnds3);
+ vect_get_vec_defs (vinfo, slp_node, true, &vec_oprnds0, true, &vec_oprnds1,
+ true, &vec_oprnds2,
+ reduction_type != EXTRACT_LAST_REDUCTION, &vec_oprnds3);
if (reduction_type == EXTRACT_LAST_REDUCTION)
vec_else_clause = else_clause;
@@ -12813,7 +12801,7 @@ vectorizable_comparison_1 (vec_info *vinfo, tree vectype,
if (lhs)
mask = vect_create_destination_var (lhs, mask_type);
- vect_get_vec_defs (vinfo, slp_node, rhs1, &vec_oprnds0, rhs2, &vec_oprnds1);
+ vect_get_vec_defs (vinfo, slp_node, true, &vec_oprnds0, true, &vec_oprnds1);
if (swap_p)
std::swap (vec_oprnds0, vec_oprnds1);
diff --git a/gcc/tree-vectorizer.h b/gcc/tree-vectorizer.h
index 62e3e629c48..fd43eaae668 100644
--- a/gcc/tree-vectorizer.h
+++ b/gcc/tree-vectorizer.h
@@ -2593,10 +2593,10 @@ extern void vect_finish_stmt_generation (vec_info *, stmt_vec_info, gimple *,
extern opt_result vect_mark_stmts_to_be_vectorized (loop_vec_info, bool *);
extern tree vect_get_store_rhs (stmt_vec_info);
void vect_get_vec_defs (vec_info *, slp_tree,
- tree, vec<tree> *,
- tree = NULL, vec<tree> * = NULL,
- tree = NULL, vec<tree> * = NULL,
- tree = NULL, vec<tree> * = NULL);
+ bool, vec<tree> *,
+ bool = false, vec<tree> * = NULL,
+ bool = false, vec<tree> * = NULL,
+ bool = false, vec<tree> * = NULL);
extern tree vect_init_vector (vec_info *, stmt_vec_info, tree, tree,
gimple_stmt_iterator *);
extern tree vect_get_slp_vect_def (slp_tree, unsigned);
--
2.51.0