Commit 736d0f28 by Richard Sandiford Committed by Richard Sandiford

Add a vec_perm_indices_to_tree helper function

This patch adds a function for creating a VECTOR_CST from a
vec_perm_indices, operating directly on the encoding.

2018-01-02  Richard Sandiford  <richard.sandiford@linaro.org>

gcc/
	* vec-perm-indices.h (vec_perm_indices_to_tree): Declare.
	* vec-perm-indices.c (vec_perm_indices_to_tree): New function.
	* tree-ssa-forwprop.c (simplify_vector_constructor): Use it.
	* tree-vect-slp.c (vect_transform_slp_perm_load): Likewise.
	* tree-vect-stmts.c (vectorizable_bswap): Likewise.
	(vect_gen_perm_mask_any): Likewise.

From-SVN: r256096
parent e3342de4
2018-01-02 Richard Sandiford <richard.sandiford@linaro.org> 2018-01-02 Richard Sandiford <richard.sandiford@linaro.org>
* vec-perm-indices.h (vec_perm_indices_to_tree): Declare.
* vec-perm-indices.c (vec_perm_indices_to_tree): New function.
* tree-ssa-forwprop.c (simplify_vector_constructor): Use it.
* tree-vect-slp.c (vect_transform_slp_perm_load): Likewise.
* tree-vect-stmts.c (vectorizable_bswap): Likewise.
(vect_gen_perm_mask_any): Likewise.
2018-01-02 Richard Sandiford <richard.sandiford@linaro.org>
* int-vector-builder.h: New file. * int-vector-builder.h: New file.
* vec-perm-indices.h: Include int-vector-builder.h. * vec-perm-indices.h: Include int-vector-builder.h.
(vec_perm_indices): Redefine as an int_vector_builder. (vec_perm_indices): Redefine as an int_vector_builder.
...@@ -2119,10 +2119,7 @@ simplify_vector_constructor (gimple_stmt_iterator *gsi) ...@@ -2119,10 +2119,7 @@ simplify_vector_constructor (gimple_stmt_iterator *gsi)
|| GET_MODE_SIZE (TYPE_MODE (mask_type)) || GET_MODE_SIZE (TYPE_MODE (mask_type))
!= GET_MODE_SIZE (TYPE_MODE (type))) != GET_MODE_SIZE (TYPE_MODE (type)))
return false; return false;
tree_vector_builder mask_elts (mask_type, nelts, 1); op2 = vec_perm_indices_to_tree (mask_type, indices);
for (i = 0; i < nelts; i++)
mask_elts.quick_push (build_int_cst (TREE_TYPE (mask_type), sel[i]));
op2 = mask_elts.build ();
if (conv_code == ERROR_MARK) if (conv_code == ERROR_MARK)
gimple_assign_set_rhs_with_ops (gsi, VEC_PERM_EXPR, orig, orig, op2); gimple_assign_set_rhs_with_ops (gsi, VEC_PERM_EXPR, orig, orig, op2);
else else
......
...@@ -3675,13 +3675,7 @@ vect_transform_slp_perm_load (slp_tree node, vec<tree> dr_chain, ...@@ -3675,13 +3675,7 @@ vect_transform_slp_perm_load (slp_tree node, vec<tree> dr_chain,
tree mask_vec = NULL_TREE; tree mask_vec = NULL_TREE;
if (! noop_p) if (! noop_p)
{ mask_vec = vec_perm_indices_to_tree (mask_type, indices);
tree_vector_builder mask_elts (mask_type, nunits, 1);
for (int l = 0; l < nunits; ++l)
mask_elts.quick_push (build_int_cst (mask_element_type,
mask[l]));
mask_vec = mask_elts.build ();
}
if (second_vec_index == -1) if (second_vec_index == -1)
second_vec_index = first_vec_index; second_vec_index = first_vec_index;
......
...@@ -2529,10 +2529,7 @@ vectorizable_bswap (gimple *stmt, gimple_stmt_iterator *gsi, ...@@ -2529,10 +2529,7 @@ vectorizable_bswap (gimple *stmt, gimple_stmt_iterator *gsi,
return true; return true;
} }
tree_vector_builder telts (char_vectype, num_bytes, 1); tree bswap_vconst = vec_perm_indices_to_tree (char_vectype, indices);
for (unsigned i = 0; i < num_bytes; ++i)
telts.quick_push (build_int_cst (char_type_node, elts[i]));
tree bswap_vconst = telts.build ();
/* Transform. */ /* Transform. */
vec<tree> vec_oprnds = vNULL; vec<tree> vec_oprnds = vNULL;
...@@ -6538,17 +6535,10 @@ vect_gen_perm_mask_any (tree vectype, const vec_perm_indices &sel) ...@@ -6538,17 +6535,10 @@ vect_gen_perm_mask_any (tree vectype, const vec_perm_indices &sel)
{ {
tree mask_elt_type, mask_type; tree mask_elt_type, mask_type;
unsigned int nunits = sel.length ();
gcc_checking_assert (nunits == TYPE_VECTOR_SUBPARTS (vectype));
mask_elt_type = lang_hooks.types.type_for_mode mask_elt_type = lang_hooks.types.type_for_mode
(int_mode_for_mode (TYPE_MODE (TREE_TYPE (vectype))).require (), 1); (int_mode_for_mode (TYPE_MODE (TREE_TYPE (vectype))).require (), 1);
mask_type = get_vectype_for_scalar_type (mask_elt_type); mask_type = get_vectype_for_scalar_type (mask_elt_type);
return vec_perm_indices_to_tree (mask_type, sel);
tree_vector_builder mask_elts (mask_type, nunits, 1);
for (unsigned int i = 0; i < nunits; ++i)
mask_elts.quick_push (build_int_cst (mask_elt_type, sel[i]));
return mask_elts.build ();
} }
/* Checked version of vect_gen_perm_mask_any. Asserts can_vec_perm_const_p, /* Checked version of vect_gen_perm_mask_any. Asserts can_vec_perm_const_p,
......
...@@ -152,6 +152,20 @@ tree_to_vec_perm_builder (vec_perm_builder *builder, tree cst) ...@@ -152,6 +152,20 @@ tree_to_vec_perm_builder (vec_perm_builder *builder, tree cst)
return true; return true;
} }
/* Return a VECTOR_CST of type TYPE for the permutation vector in INDICES. */
tree
vec_perm_indices_to_tree (tree type, const vec_perm_indices &indices)
{
gcc_assert (TYPE_VECTOR_SUBPARTS (type) == indices.length ());
tree_vector_builder sel (type, indices.encoding ().npatterns (),
indices.encoding ().nelts_per_pattern ());
unsigned int encoded_nelts = sel.encoded_nelts ();
for (unsigned int i = 0; i < encoded_nelts; i++)
sel.quick_push (build_int_cst (TREE_TYPE (type), indices[i]));
return sel.build ();
}
/* Return a CONST_VECTOR of mode MODE that contains the elements of /* Return a CONST_VECTOR of mode MODE that contains the elements of
INDICES. */ INDICES. */
......
...@@ -88,6 +88,7 @@ private: ...@@ -88,6 +88,7 @@ private:
}; };
bool tree_to_vec_perm_builder (vec_perm_builder *, tree); bool tree_to_vec_perm_builder (vec_perm_builder *, tree);
tree vec_perm_indices_to_tree (tree, const vec_perm_indices &);
rtx vec_perm_indices_to_rtx (machine_mode, const vec_perm_indices &); rtx vec_perm_indices_to_rtx (machine_mode, const vec_perm_indices &);
inline inline
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment