aboutsummaryrefslogtreecommitdiff
path: root/gcc/fold-const.c
diff options
context:
space:
mode:
authorRichard Sandiford <richard.sandiford@linaro.org>2017-09-14 16:04:32 +0000
committerRichard Sandiford <rsandifo@gcc.gnu.org>2017-09-14 16:04:32 +0000
commit908a1a166dccefa24ae8b3606f4ce1da944eecb0 (patch)
tree15660ec76cab5cc22a0052c6cf11bdbe96bc2fd7 /gcc/fold-const.c
parent794e31808f1554d51f0f0357c3a74a6365f0a274 (diff)
downloadgcc-908a1a166dccefa24ae8b3606f4ce1da944eecb0.zip
gcc-908a1a166dccefa24ae8b3606f4ce1da944eecb0.tar.gz
gcc-908a1a166dccefa24ae8b3606f4ce1da944eecb0.tar.bz2
Use vec<> for constant permute masks
This patch makes can_vec_perm_p & co. take a vec<>, wrapped in new typedefs vec_perm_indices and auto_vec_perm_indices. There are two reasons for doing this for SVE: (1) it means that the number of elements is bundled with the elements themselves, and is obviously constant. (2) it makes it easier to change the "unsigned char" element type to something wider. Changing the target hook is left as follow-on work. 2017-09-14 Richard Sandiford <richard.sandiford@linaro.org> Alan Hayward <alan.hayward@arm.com> David Sherwood <david.sherwood@arm.com> gcc/ * target.h (vec_perm_indices): New typedef. (auto_vec_perm_indices): Likewise. * optabs-query.h: Include target.h (can_vec_perm_p): Take a vec_perm_indices *. * optabs-query.c (can_vec_perm_p): Likewise. (can_mult_highpart_p): Update accordingly. Use auto_vec_perm_indices. * tree-ssa-forwprop.c (simplify_vector_constructor): Likewise. * tree-vect-generic.c (lower_vec_perm): Likewise. * tree-vect-data-refs.c (vect_grouped_store_supported): Likewise. (vect_grouped_load_supported): Likewise. (vect_shift_permute_load_chain): Likewise. (vect_permute_store_chain): Use auto_vec_perm_indices. (vect_permute_load_chain): Likewise. * fold-const.c (fold_vec_perm): Take vec_perm_indices. (fold_ternary_loc): Update accordingly. Use auto_vec_perm_indices. Update uses of can_vec_perm_p. * tree-vect-loop.c (calc_vec_perm_mask_for_shift): Replace the mode with a number of elements. Take a vec_perm_indices *. (vect_create_epilog_for_reduction): Update accordingly. Use auto_vec_perm_indices. (have_whole_vector_shift): Likewise. Update call to can_vec_perm_p. * tree-vect-slp.c (vect_build_slp_tree_1): Likewise. (vect_transform_slp_perm_load): Likewise. (vect_schedule_slp_instance): Use auto_vec_perm_indices. * tree-vectorizer.h (vect_gen_perm_mask_any): Take a vec_perm_indices. (vect_gen_perm_mask_checked): Likewise. * tree-vect-stmts.c (vect_gen_perm_mask_any): Take a vec_perm_indices. (vect_gen_perm_mask_checked): Likewise. (vectorizable_mask_load_store): Use auto_vec_perm_indices. (vectorizable_store): Likewise. (vectorizable_load): Likewise. (perm_mask_for_reverse): Likewise. Update call to can_vec_perm_p. (vectorizable_bswap): Likewise. Co-Authored-By: Alan Hayward <alan.hayward@arm.com> Co-Authored-By: David Sherwood <david.sherwood@arm.com> From-SVN: r252761
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r--gcc/fold-const.c33
1 files changed, 19 insertions, 14 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 013081d..fa9d1bb 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -8786,12 +8786,14 @@ vec_cst_ctor_to_array (tree arg, unsigned int nelts, tree *elts)
NULL_TREE otherwise. */
static tree
-fold_vec_perm (tree type, tree arg0, tree arg1, const unsigned char *sel)
+fold_vec_perm (tree type, tree arg0, tree arg1, vec_perm_indices sel)
{
- unsigned int nelts = TYPE_VECTOR_SUBPARTS (type), i;
+ unsigned int i;
bool need_ctor = false;
- gcc_assert (TYPE_VECTOR_SUBPARTS (TREE_TYPE (arg0)) == nelts
+ unsigned int nelts = sel.length ();
+ gcc_assert (TYPE_VECTOR_SUBPARTS (type) == nelts
+ && TYPE_VECTOR_SUBPARTS (TREE_TYPE (arg0)) == nelts
&& TYPE_VECTOR_SUBPARTS (TREE_TYPE (arg1)) == nelts);
if (TREE_TYPE (TREE_TYPE (arg0)) != TREE_TYPE (type)
|| TREE_TYPE (TREE_TYPE (arg1)) != TREE_TYPE (type))
@@ -11312,15 +11314,15 @@ fold_ternary_loc (location_t loc, enum tree_code code, tree type,
|| TREE_CODE (arg2) == CONSTRUCTOR))
{
unsigned int nelts = VECTOR_CST_NELTS (arg0), i;
- unsigned char *sel = XALLOCAVEC (unsigned char, nelts);
gcc_assert (nelts == TYPE_VECTOR_SUBPARTS (type));
+ auto_vec_perm_indices sel (nelts);
for (i = 0; i < nelts; i++)
{
tree val = VECTOR_CST_ELT (arg0, i);
if (integer_all_onesp (val))
- sel[i] = i;
+ sel.quick_push (i);
else if (integer_zerop (val))
- sel[i] = nelts + i;
+ sel.quick_push (nelts + i);
else /* Currently unreachable. */
return NULL_TREE;
}
@@ -11643,8 +11645,6 @@ fold_ternary_loc (location_t loc, enum tree_code code, tree type,
if (TREE_CODE (arg2) == VECTOR_CST)
{
unsigned int nelts = VECTOR_CST_NELTS (arg2), i, mask, mask2;
- unsigned char *sel = XALLOCAVEC (unsigned char, 2 * nelts);
- unsigned char *sel2 = sel + nelts;
bool need_mask_canon = false;
bool need_mask_canon2 = false;
bool all_in_vec0 = true;
@@ -11656,6 +11656,8 @@ fold_ternary_loc (location_t loc, enum tree_code code, tree type,
mask2 = 2 * nelts - 1;
mask = single_arg ? (nelts - 1) : mask2;
gcc_assert (nelts == TYPE_VECTOR_SUBPARTS (type));
+ auto_vec_perm_indices sel (nelts);
+ auto_vec_perm_indices sel2 (nelts);
for (i = 0; i < nelts; i++)
{
tree val = VECTOR_CST_ELT (arg2, i);
@@ -11667,16 +11669,19 @@ fold_ternary_loc (location_t loc, enum tree_code code, tree type,
wide_int t = val;
need_mask_canon |= wi::gtu_p (t, mask);
need_mask_canon2 |= wi::gtu_p (t, mask2);
- sel[i] = t.to_uhwi () & mask;
- sel2[i] = t.to_uhwi () & mask2;
+ unsigned int elt = t.to_uhwi () & mask;
+ unsigned int elt2 = t.to_uhwi () & mask2;
- if (sel[i] < nelts)
+ if (elt < nelts)
all_in_vec1 = false;
else
all_in_vec0 = false;
- if ((sel[i] & (nelts-1)) != i)
+ if ((elt & (nelts - 1)) != i)
maybe_identity = false;
+
+ sel.quick_push (elt);
+ sel2.quick_push (elt2);
}
if (maybe_identity)
@@ -11714,8 +11719,8 @@ fold_ternary_loc (location_t loc, enum tree_code code, tree type,
argument permutation while still allowing an equivalent
2-argument version. */
if (need_mask_canon && arg2 == op2
- && !can_vec_perm_p (TYPE_MODE (type), false, sel)
- && can_vec_perm_p (TYPE_MODE (type), false, sel2))
+ && !can_vec_perm_p (TYPE_MODE (type), false, &sel)
+ && can_vec_perm_p (TYPE_MODE (type), false, &sel2))
{
need_mask_canon = need_mask_canon2;
sel = sel2;