aboutsummaryrefslogtreecommitdiff
path: root/gcc/tree-vect-loop.c
diff options
context:
space:
mode:
authorRichard Sandiford <richard.sandiford@linaro.org>2017-09-14 15:46:08 +0000
committerRichard Sandiford <rsandifo@gcc.gnu.org>2017-09-14 15:46:08 +0000
commit794e31808f1554d51f0f0357c3a74a6365f0a274 (patch)
treed491aa520d3a8de4b35dbdde63439716c15b6f8d /gcc/tree-vect-loop.c
parent9e822269364f5268b2bdc82530fd6c871f47b1bc (diff)
downloadgcc-794e31808f1554d51f0f0357c3a74a6365f0a274.zip
gcc-794e31808f1554d51f0f0357c3a74a6365f0a274.tar.gz
gcc-794e31808f1554d51f0f0357c3a74a6365f0a274.tar.bz2
Use vec<> in build_vector
This patch makes build_vector take the elements as a vec<> rather than a tree *. This is useful for SVE because it bundles the number of elements with the elements themselves, and enforces the fact that the number is constant. Also, I think things like the folds can be used with any generic GNU vector, not just those that match machine vectors, so the arguments to XALLOCAVEC had no clear limit. 2017-09-14 Richard Sandiford <richard.sandiford@linaro.org> Alan Hayward <alan.hayward@arm.com> David Sherwood <david.sherwood@arm.com> gcc/ * tree.h (build_vector): Take a vec<tree> instead of a tree *. * tree.c (build_vector): Likewise. (build_vector_from_ctor): Update accordingly. (build_vector_from_val): Likewise. * gimple-fold.c (gimple_fold_stmt_to_constant_1): Likewise. * tree-ssa-forwprop.c (simplify_vector_constructor): Likewise. * tree-vect-generic.c (add_rshift): Likewise. (expand_vector_divmod): Likewise. (optimize_vector_constructor): Likewise. * tree-vect-slp.c (vect_get_constant_vectors): Likewise. (vect_transform_slp_perm_load): Likewise. (vect_schedule_slp_instance): Likewise. * tree-vect-stmts.c (vectorizable_bswap): Likewise. (vectorizable_call): Likewise. (vect_gen_perm_mask_any): Likewise. Add elements in order. * expmed.c (make_tree): Likewise. * fold-const.c (fold_negate_expr_1): Use auto_vec<tree> when building a vector passed to build_vector. (fold_convert_const): Likewise. (exact_inverse): Likewise. (fold_ternary_loc): Likewise. (fold_relational_const): Likewise. (const_binop): Likewise. Use VECTOR_CST_ELT directly when operating on VECTOR_CSTs, rather than going through vec_cst_ctor_to_array. (const_unop): Likewise. Store the reduction accumulator in a variable rather than an array. (vec_cst_ctor_to_array): Take the number of elements as a parameter. (fold_vec_perm): Update calls accordingly. Use auto_vec<tree> for the new vector, rather than constructing it after the input arrays. (native_interpret_vector): Use auto_vec<tree> when building a vector passed to build_vector. Add elements in order. * tree-vect-loop.c (get_initial_defs_for_reduction): Use auto_vec<tree> when building a vector passed to build_vector. (vect_create_epilog_for_reduction): Likewise. (vectorizable_induction): Likewise. (get_initial_def_for_reduction): Likewise. Fix indentation of case statements. * config/sparc/sparc.c (sparc_handle_vis_mul8x16): Change n_elts to a vec<tree> *. (sparc_fold_builtin): Use auto_vec<tree> when building a vector passed to build_vector. Co-Authored-By: Alan Hayward <alan.hayward@arm.com> Co-Authored-By: David Sherwood <david.sherwood@arm.com> From-SVN: r252760
Diffstat (limited to 'gcc/tree-vect-loop.c')
-rw-r--r--gcc/tree-vect-loop.c64
1 files changed, 34 insertions, 30 deletions
diff --git a/gcc/tree-vect-loop.c b/gcc/tree-vect-loop.c
index 5a1d9ff..3b4a71e 100644
--- a/gcc/tree-vect-loop.c
+++ b/gcc/tree-vect-loop.c
@@ -3969,7 +3969,6 @@ get_initial_def_for_reduction (gimple *stmt, tree init_val,
enum tree_code code = gimple_assign_rhs_code (stmt);
tree def_for_init;
tree init_def;
- tree *elts;
int i;
bool nested_in_vect_loop = false;
REAL_VALUE_TYPE real_init_val = dconst0;
@@ -4015,15 +4014,16 @@ get_initial_def_for_reduction (gimple *stmt, tree init_val,
switch (code)
{
- case WIDEN_SUM_EXPR:
- case DOT_PROD_EXPR:
- case SAD_EXPR:
- case PLUS_EXPR:
- case MINUS_EXPR:
- case BIT_IOR_EXPR:
- case BIT_XOR_EXPR:
- case MULT_EXPR:
- case BIT_AND_EXPR:
+ case WIDEN_SUM_EXPR:
+ case DOT_PROD_EXPR:
+ case SAD_EXPR:
+ case PLUS_EXPR:
+ case MINUS_EXPR:
+ case BIT_IOR_EXPR:
+ case BIT_XOR_EXPR:
+ case MULT_EXPR:
+ case BIT_AND_EXPR:
+ {
/* ADJUSMENT_DEF is NULL when called from
vect_create_epilog_for_reduction to vectorize double reduction. */
if (adjustment_def)
@@ -4044,17 +4044,19 @@ get_initial_def_for_reduction (gimple *stmt, tree init_val,
def_for_init = build_int_cst (scalar_type, int_init_val);
/* Create a vector of '0' or '1' except the first element. */
- elts = XALLOCAVEC (tree, nunits);
+ auto_vec<tree, 32> elts (nunits);
+ elts.quick_grow (nunits);
for (i = nunits - 2; i >= 0; --i)
elts[i + 1] = def_for_init;
/* Option1: the first element is '0' or '1' as well. */
- if (adjustment_def)
- {
+ if (adjustment_def)
+ {
elts[0] = def_for_init;
- init_def = build_vector (vectype, elts);
- break;
- }
+
+ init_def = build_vector (vectype, elts);
+ break;
+ }
/* Option2: the first element is INIT_VAL. */
elts[0] = init_val;
@@ -4069,12 +4071,13 @@ get_initial_def_for_reduction (gimple *stmt, tree init_val,
CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, elts[i]);
init_def = build_constructor (vectype, v);
}
+ }
+ break;
- break;
-
- case MIN_EXPR:
- case MAX_EXPR:
- case COND_EXPR:
+ case MIN_EXPR:
+ case MAX_EXPR:
+ case COND_EXPR:
+ {
if (adjustment_def)
{
*adjustment_def = NULL_TREE;
@@ -4088,10 +4091,11 @@ get_initial_def_for_reduction (gimple *stmt, tree init_val,
if (! gimple_seq_empty_p (stmts))
gsi_insert_seq_on_edge_immediate (loop_preheader_edge (loop), stmts);
init_def = build_vector_from_val (vectype, init_val);
- break;
+ }
+ break;
- default:
- gcc_unreachable ();
+ default:
+ gcc_unreachable ();
}
return init_def;
@@ -4111,7 +4115,6 @@ get_initial_defs_for_reduction (slp_tree slp_node,
stmt_vec_info stmt_vinfo = vinfo_for_stmt (stmt);
unsigned nunits;
tree vec_cst;
- tree *elts;
unsigned j, number_of_places_left_in_vector;
tree vector_type, scalar_type;
tree vop;
@@ -4195,7 +4198,8 @@ get_initial_defs_for_reduction (slp_tree slp_node,
number_of_places_left_in_vector = nunits;
constant_p = true;
- elts = XALLOCAVEC (tree, nunits);
+ auto_vec<tree, 32> elts (nunits);
+ elts.quick_grow (nunits);
for (j = 0; j < number_of_copies; j++)
{
for (i = group_size - 1; stmts.iterate (i, &stmt); i--)
@@ -4533,9 +4537,9 @@ vect_create_epilog_for_reduction (vec<tree> vect_defs, gimple *stmt,
vector size (STEP). */
/* Create a {1,2,3,...} vector. */
- tree *vtemp = XALLOCAVEC (tree, nunits_out);
+ auto_vec<tree, 32> vtemp (nunits_out);
for (k = 0; k < nunits_out; ++k)
- vtemp[k] = build_int_cst (cr_index_scalar_type, k + 1);
+ vtemp.quick_push (build_int_cst (cr_index_scalar_type, k + 1));
tree series_vect = build_vector (cr_index_vector_type, vtemp);
/* Create a vector of the step value. */
@@ -6731,7 +6735,7 @@ vectorizable_induction (gimple *phi,
unsigned ivn;
for (ivn = 0; ivn < nivs; ++ivn)
{
- tree *elts = XALLOCAVEC (tree, nunits);
+ auto_vec<tree, 32> elts (nunits);
bool constant_p = true;
for (unsigned eltn = 0; eltn < nunits; ++eltn)
{
@@ -6749,7 +6753,7 @@ vectorizable_induction (gimple *phi,
}
if (! CONSTANT_CLASS_P (elt))
constant_p = false;
- elts[eltn] = elt;
+ elts.quick_push (elt);
}
if (constant_p)
new_vec = build_vector (vectype, elts);