From: Richard Sandiford Date: Tue, 2 Jan 2018 18:27:05 +0000 (+0000) Subject: Use explicit encodings for simple permutes X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=d980067b1e9394b2b8482b3fc888ac5e8e3ebe59;p=gcc.git Use explicit encodings for simple permutes This patch makes users of vec_perm_builders use the compressed encoding where possible. This means that they work with variable-length vectors. 2018-01-02 Richard Sandiford gcc/ * optabs.c (expand_vec_perm_var): Use an explicit encoding for the broadcast of the low byte. (expand_mult_highpart): Use an explicit encoding for the permutes. * optabs-query.c (can_mult_highpart_p): Likewise. * tree-vect-loop.c (calc_vec_perm_mask_for_shift): Likewise. * tree-vect-stmts.c (perm_mask_for_reverse): Likewise. (vectorizable_bswap): Likewise. * tree-vect-data-refs.c (vect_grouped_store_supported): Use an explicit encoding for the power-of-2 permutes. (vect_permute_store_chain): Likewise. (vect_grouped_load_supported): Likewise. (vect_permute_load_chain): Likewise. From-SVN: r256097 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 7fc70c00cfd..c5b62cd3628 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,18 @@ +2018-01-02 Richard Sandiford + + * optabs.c (expand_vec_perm_var): Use an explicit encoding for + the broadcast of the low byte. + (expand_mult_highpart): Use an explicit encoding for the permutes. + * optabs-query.c (can_mult_highpart_p): Likewise. + * tree-vect-loop.c (calc_vec_perm_mask_for_shift): Likewise. + * tree-vect-stmts.c (perm_mask_for_reverse): Likewise. + (vectorizable_bswap): Likewise. + * tree-vect-data-refs.c (vect_grouped_store_supported): Use an + explicit encoding for the power-of-2 permutes. + (vect_permute_store_chain): Likewise. + (vect_grouped_load_supported): Likewise. + (vect_permute_load_chain): Likewise. + 2018-01-02 Richard Sandiford * vec-perm-indices.h (vec_perm_indices_to_tree): Declare. diff --git a/gcc/optabs-query.c b/gcc/optabs-query.c index de0ad1094c5..c715cb662ed 100644 --- a/gcc/optabs-query.c +++ b/gcc/optabs-query.c @@ -516,8 +516,9 @@ can_mult_highpart_p (machine_mode mode, bool uns_p) op = uns_p ? vec_widen_umult_odd_optab : vec_widen_smult_odd_optab; if (optab_handler (op, mode) != CODE_FOR_nothing) { - vec_perm_builder sel (nunits, nunits, 1); - for (i = 0; i < nunits; ++i) + /* The encoding has 2 interleaved stepped patterns. */ + vec_perm_builder sel (nunits, 2, 3); + for (i = 0; i < 6; ++i) sel.quick_push (!BYTES_BIG_ENDIAN + (i & ~1) + ((i & 1) ? nunits : 0)); @@ -533,8 +534,9 @@ can_mult_highpart_p (machine_mode mode, bool uns_p) op = uns_p ? vec_widen_umult_lo_optab : vec_widen_smult_lo_optab; if (optab_handler (op, mode) != CODE_FOR_nothing) { - vec_perm_builder sel (nunits, nunits, 1); - for (i = 0; i < nunits; ++i) + /* The encoding has a single stepped pattern. */ + vec_perm_builder sel (nunits, 1, 3); + for (int i = 0; i < 3; ++i) sel.quick_push (2 * i + (BYTES_BIG_ENDIAN ? 0 : 1)); vec_perm_indices indices (sel, 2, nunits); if (can_vec_perm_const_p (mode, indices)) diff --git a/gcc/optabs.c b/gcc/optabs.c index db13a25b15a..e9ce42fb9ee 100644 --- a/gcc/optabs.c +++ b/gcc/optabs.c @@ -5646,15 +5646,14 @@ expand_vec_perm_var (machine_mode mode, rtx v0, rtx v1, rtx sel, rtx target) NULL, 0, OPTAB_DIRECT); gcc_assert (sel != NULL); - /* Broadcast the low byte each element into each of its bytes. */ - vec_perm_builder const_sel (w, w, 1); - for (i = 0; i < w; ++i) - { - int this_e = i / u * u; - if (BYTES_BIG_ENDIAN) - this_e += u - 1; - const_sel.quick_push (this_e); - } + /* Broadcast the low byte each element into each of its bytes. + The encoding has U interleaved stepped patterns, one for each + byte of an element. */ + vec_perm_builder const_sel (w, u, 3); + unsigned int low_byte_in_u = BYTES_BIG_ENDIAN ? u - 1 : 0; + for (i = 0; i < 3; ++i) + for (unsigned int j = 0; j < u; ++j) + const_sel.quick_push (i * u + low_byte_in_u); sel = gen_lowpart (qimode, sel); sel = expand_vec_perm_const (qimode, sel, sel, const_sel, qimode, NULL); gcc_assert (sel != NULL); @@ -5895,16 +5894,20 @@ expand_mult_highpart (machine_mode mode, rtx op0, rtx op1, expand_insn (optab_handler (tab2, mode), 3, eops); m2 = gen_lowpart (mode, eops[0].value); - vec_perm_builder sel (nunits, nunits, 1); + vec_perm_builder sel; if (method == 2) { - for (i = 0; i < nunits; ++i) + /* The encoding has 2 interleaved stepped patterns. */ + sel.new_vector (nunits, 2, 3); + for (i = 0; i < 6; ++i) sel.quick_push (!BYTES_BIG_ENDIAN + (i & ~1) + ((i & 1) ? nunits : 0)); } else { - for (i = 0; i < nunits; ++i) + /* The encoding has a single interleaved stepped pattern. */ + sel.new_vector (nunits, 1, 3); + for (i = 0; i < 3; ++i) sel.quick_push (2 * i + (BYTES_BIG_ENDIAN ? 0 : 1)); } diff --git a/gcc/tree-vect-data-refs.c b/gcc/tree-vect-data-refs.c index 48673d11c1f..594e06a0a61 100644 --- a/gcc/tree-vect-data-refs.c +++ b/gcc/tree-vect-data-refs.c @@ -4579,14 +4579,13 @@ vect_grouped_store_supported (tree vectype, unsigned HOST_WIDE_INT count) if (VECTOR_MODE_P (mode)) { unsigned int i, nelt = GET_MODE_NUNITS (mode); - vec_perm_builder sel (nelt, nelt, 1); - sel.quick_grow (nelt); - if (count == 3) { unsigned int j0 = 0, j1 = 0, j2 = 0; unsigned int i, j; + vec_perm_builder sel (nelt, nelt, 1); + sel.quick_grow (nelt); vec_perm_indices indices; for (j = 0; j < 3; j++) { @@ -4636,7 +4635,10 @@ vect_grouped_store_supported (tree vectype, unsigned HOST_WIDE_INT count) /* If length is not equal to 3 then only power of 2 is supported. */ gcc_assert (pow2p_hwi (count)); - for (i = 0; i < nelt / 2; i++) + /* The encoding has 2 interleaved stepped patterns. */ + vec_perm_builder sel (nelt, 2, 3); + sel.quick_grow (6); + for (i = 0; i < 3; i++) { sel[i * 2] = i; sel[i * 2 + 1] = i + nelt; @@ -4644,7 +4646,7 @@ vect_grouped_store_supported (tree vectype, unsigned HOST_WIDE_INT count) vec_perm_indices indices (sel, 2, nelt); if (can_vec_perm_const_p (mode, indices)) { - for (i = 0; i < nelt; i++) + for (i = 0; i < 6; i++) sel[i] += nelt / 2; indices.new_vector (sel, 2, nelt); if (can_vec_perm_const_p (mode, indices)) @@ -4749,9 +4751,6 @@ vect_permute_store_chain (vec dr_chain, unsigned int i, n, log_length = exact_log2 (length); unsigned int j, nelt = TYPE_VECTOR_SUBPARTS (vectype); - vec_perm_builder sel (nelt, nelt, 1); - sel.quick_grow (nelt); - result_chain->quick_grow (length); memcpy (result_chain->address (), dr_chain.address (), length * sizeof (tree)); @@ -4760,6 +4759,8 @@ vect_permute_store_chain (vec dr_chain, { unsigned int j0 = 0, j1 = 0, j2 = 0; + vec_perm_builder sel (nelt, nelt, 1); + sel.quick_grow (nelt); vec_perm_indices indices; for (j = 0; j < 3; j++) { @@ -4821,7 +4822,10 @@ vect_permute_store_chain (vec dr_chain, /* If length is not equal to 3 then only power of 2 is supported. */ gcc_assert (pow2p_hwi (length)); - for (i = 0, n = nelt / 2; i < n; i++) + /* The encoding has 2 interleaved stepped patterns. */ + vec_perm_builder sel (nelt, 2, 3); + sel.quick_grow (6); + for (i = 0; i < 3; i++) { sel[i * 2] = i; sel[i * 2 + 1] = i + nelt; @@ -4829,7 +4833,7 @@ vect_permute_store_chain (vec dr_chain, vec_perm_indices indices (sel, 2, nelt); perm_mask_high = vect_gen_perm_mask_checked (vectype, indices); - for (i = 0; i < nelt; i++) + for (i = 0; i < 6; i++) sel[i] += nelt / 2; indices.new_vector (sel, 2, nelt); perm_mask_low = vect_gen_perm_mask_checked (vectype, indices); @@ -5177,11 +5181,11 @@ vect_grouped_load_supported (tree vectype, bool single_element_p, if (VECTOR_MODE_P (mode)) { unsigned int i, j, nelt = GET_MODE_NUNITS (mode); - vec_perm_builder sel (nelt, nelt, 1); - sel.quick_grow (nelt); if (count == 3) { + vec_perm_builder sel (nelt, nelt, 1); + sel.quick_grow (nelt); vec_perm_indices indices; unsigned int k; for (k = 0; k < 3; k++) @@ -5222,12 +5226,15 @@ vect_grouped_load_supported (tree vectype, bool single_element_p, /* If length is not equal to 3 then only power of 2 is supported. */ gcc_assert (pow2p_hwi (count)); - for (i = 0; i < nelt; i++) + /* The encoding has a single stepped pattern. */ + vec_perm_builder sel (nelt, 1, 3); + sel.quick_grow (3); + for (i = 0; i < 3; i++) sel[i] = i * 2; vec_perm_indices indices (sel, 2, nelt); if (can_vec_perm_const_p (mode, indices)) { - for (i = 0; i < nelt; i++) + for (i = 0; i < 3; i++) sel[i] = i * 2 + 1; indices.new_vector (sel, 2, nelt); if (can_vec_perm_const_p (mode, indices)) @@ -5345,9 +5352,6 @@ vect_permute_load_chain (vec dr_chain, unsigned int i, j, log_length = exact_log2 (length); unsigned nelt = TYPE_VECTOR_SUBPARTS (vectype); - vec_perm_builder sel (nelt, nelt, 1); - sel.quick_grow (nelt); - result_chain->quick_grow (length); memcpy (result_chain->address (), dr_chain.address (), length * sizeof (tree)); @@ -5356,6 +5360,8 @@ vect_permute_load_chain (vec dr_chain, { unsigned int k; + vec_perm_builder sel (nelt, nelt, 1); + sel.quick_grow (nelt); vec_perm_indices indices; for (k = 0; k < 3; k++) { @@ -5403,12 +5409,15 @@ vect_permute_load_chain (vec dr_chain, /* If length is not equal to 3 then only power of 2 is supported. */ gcc_assert (pow2p_hwi (length)); - for (i = 0; i < nelt; ++i) + /* The encoding has a single stepped pattern. */ + vec_perm_builder sel (nelt, 1, 3); + sel.quick_grow (3); + for (i = 0; i < 3; ++i) sel[i] = i * 2; vec_perm_indices indices (sel, 2, nelt); perm_mask_even = vect_gen_perm_mask_checked (vectype, indices); - for (i = 0; i < nelt; ++i) + for (i = 0; i < 3; ++i) sel[i] = i * 2 + 1; indices.new_vector (sel, 2, nelt); perm_mask_odd = vect_gen_perm_mask_checked (vectype, indices); diff --git a/gcc/tree-vect-loop.c b/gcc/tree-vect-loop.c index fa33c7dfc94..31a396b8790 100644 --- a/gcc/tree-vect-loop.c +++ b/gcc/tree-vect-loop.c @@ -3715,8 +3715,10 @@ static void calc_vec_perm_mask_for_shift (unsigned int offset, unsigned int nelt, vec_perm_builder *sel) { - sel->new_vector (nelt, nelt, 1); - for (unsigned int i = 0; i < nelt; i++) + /* The encoding is a single stepped pattern. Any wrap-around is handled + by vec_perm_indices. */ + sel->new_vector (nelt, 1, 3); + for (unsigned int i = 0; i < 3; i++) sel->quick_push (i + offset); } diff --git a/gcc/tree-vect-stmts.c b/gcc/tree-vect-stmts.c index 8f26320f018..0f77567c9d9 100644 --- a/gcc/tree-vect-stmts.c +++ b/gcc/tree-vect-stmts.c @@ -1717,8 +1717,9 @@ perm_mask_for_reverse (tree vectype) nunits = TYPE_VECTOR_SUBPARTS (vectype); - vec_perm_builder sel (nunits, nunits, 1); - for (i = 0; i < nunits; ++i) + /* The encoding has a single stepped pattern. */ + vec_perm_builder sel (nunits, 1, 3); + for (i = 0; i < 3; ++i) sel.quick_push (nunits - 1 - i); vec_perm_indices indices (sel, 1, nunits); @@ -2504,8 +2505,9 @@ vectorizable_bswap (gimple *stmt, gimple_stmt_iterator *gsi, unsigned int num_bytes = TYPE_VECTOR_SUBPARTS (char_vectype); unsigned word_bytes = num_bytes / nunits; - vec_perm_builder elts (num_bytes, num_bytes, 1); - for (unsigned i = 0; i < nunits; ++i) + /* The encoding uses one stepped pattern for each byte in the word. */ + vec_perm_builder elts (num_bytes, word_bytes, 3); + for (unsigned i = 0; i < 3; ++i) for (unsigned j = 0; j < word_bytes; ++j) elts.quick_push ((i + 1) * word_bytes - j - 1);