The GET_MODE_NUNITS patch made vect_grouped_store_supported and vect_grouped_load_supported check for a constant number of elements, so vect_permute_store_chain and vect_permute_load_chain can assert for that. This patch adds commentary to that effect; the actual asserts will be added by a later, more mechanical, patch.
The patch also reorganises the function so that the asserts are linked specifically to code that builds permute vectors element-by-element. This allows a later patch to add support for some variable-length permutes. 2017-10-23 Richard Sandiford <richard.sandif...@linaro.org> Alan Hayward <alan.hayw...@arm.com> David Sherwood <david.sherw...@arm.com> gcc/ * tree-vect-data-refs.c (vect_permute_store_chain): Reorganize so that both the length == 3 and length != 3 cases set up their own permute vectors. Add comments explaining why we know the number of elements is constant. (vect_permute_load_chain): Likewise. Index: gcc/tree-vect-data-refs.c =================================================================== --- gcc/tree-vect-data-refs.c 2017-10-23 17:25:48.623491897 +0100 +++ gcc/tree-vect-data-refs.c 2017-10-23 17:25:50.361429427 +0100 @@ -4734,11 +4734,7 @@ vect_permute_store_chain (vec<tree> dr_c tree perm_mask_low, perm_mask_high; tree data_ref; tree perm3_mask_low, perm3_mask_high; - unsigned int i, n, log_length = exact_log2 (length); - unsigned int j, nelt = TYPE_VECTOR_SUBPARTS (vectype); - - auto_vec_perm_indices sel (nelt); - sel.quick_grow (nelt); + unsigned int i, j, n, log_length = exact_log2 (length); result_chain->quick_grow (length); memcpy (result_chain->address (), dr_chain.address (), @@ -4746,8 +4742,12 @@ vect_permute_store_chain (vec<tree> dr_c if (length == 3) { + /* vect_grouped_store_supported ensures that this is constant. */ + unsigned int nelt = TYPE_VECTOR_SUBPARTS (vectype); unsigned int j0 = 0, j1 = 0, j2 = 0; + auto_vec_perm_indices sel (nelt); + sel.quick_grow (nelt); for (j = 0; j < 3; j++) { int nelt0 = ((3 - j) * nelt) % 3; @@ -4806,6 +4806,10 @@ vect_permute_store_chain (vec<tree> dr_c /* If length is not equal to 3 then only power of 2 is supported. */ gcc_assert (pow2p_hwi (length)); + /* vect_grouped_store_supported ensures that this is constant. */ + unsigned int nelt = TYPE_VECTOR_SUBPARTS (vectype); + auto_vec_perm_indices sel (nelt); + sel.quick_grow (nelt); for (i = 0, n = nelt / 2; i < n; i++) { sel[i * 2] = i; @@ -5321,10 +5325,6 @@ vect_permute_load_chain (vec<tree> dr_ch gimple *perm_stmt; tree vectype = STMT_VINFO_VECTYPE (vinfo_for_stmt (stmt)); unsigned int i, j, log_length = exact_log2 (length); - unsigned nelt = TYPE_VECTOR_SUBPARTS (vectype); - - auto_vec_perm_indices sel (nelt); - sel.quick_grow (nelt); result_chain->quick_grow (length); memcpy (result_chain->address (), dr_chain.address (), @@ -5332,8 +5332,12 @@ vect_permute_load_chain (vec<tree> dr_ch if (length == 3) { + /* vect_grouped_load_supported ensures that this is constant. */ + unsigned nelt = TYPE_VECTOR_SUBPARTS (vectype); unsigned int k; + auto_vec_perm_indices sel (nelt); + sel.quick_grow (nelt); for (k = 0; k < 3; k++) { for (i = 0; i < nelt; i++) @@ -5379,6 +5383,10 @@ vect_permute_load_chain (vec<tree> dr_ch /* If length is not equal to 3 then only power of 2 is supported. */ gcc_assert (pow2p_hwi (length)); + /* vect_grouped_load_supported ensures that this is constant. */ + unsigned nelt = TYPE_VECTOR_SUBPARTS (vectype); + auto_vec_perm_indices sel (nelt); + sel.quick_grow (nelt); for (i = 0; i < nelt; ++i) sel[i] = i * 2; perm_mask_even = vect_gen_perm_mask_checked (vectype, sel);