diff options
author | Richard Sandiford <richard.sandiford@arm.com> | 2020-05-12 09:01:10 +0100 |
---|---|---|
committer | Richard Sandiford <richard.sandiford@arm.com> | 2020-05-12 09:01:10 +0100 |
commit | d17a896da1e898928d337596d029f0ece0039d55 (patch) | |
tree | 3907710b0485fb8de89e9de33bb6d452c88a60d1 /gcc/tree-vect-generic.c | |
parent | dc703151d4f4560e647649506d5b4ceb0ee11e90 (diff) | |
download | gcc-d17a896da1e898928d337596d029f0ece0039d55.zip gcc-d17a896da1e898928d337596d029f0ece0039d55.tar.gz gcc-d17a896da1e898928d337596d029f0ece0039d55.tar.bz2 |
tree: Add vector_element_bits(_tree) [PR94980 1/3]
A lot of code that wants to know the number of bits in a vector
element gets that information from the element's TYPE_SIZE,
which is always equal to TYPE_SIZE_UNIT * BITS_PER_UNIT.
This doesn't work for SVE and AVX512-style packed boolean vectors,
where several elements can occupy a single byte.
This patch introduces a new pair of helpers for getting the true
(possibly sub-byte) size. I made a token attempt to convert obvious
element size calculations, but I'm sure I missed some.
2020-05-12 Richard Sandiford <richard.sandiford@arm.com>
gcc/
PR tree-optimization/94980
* tree.h (vector_element_bits, vector_element_bits_tree): Declare.
* tree.c (vector_element_bits, vector_element_bits_tree): New.
* match.pd: Use the new functions instead of determining the
vector element size directly from TYPE_SIZE(_UNIT).
* tree-vect-data-refs.c (vect_gather_scatter_fn_p): Likewise.
* tree-vect-patterns.c (vect_recog_mask_conversion_pattern): Likewise.
* tree-vect-stmts.c (vect_is_simple_cond): Likewise.
* tree-vect-generic.c (expand_vector_piecewise): Likewise.
(expand_vector_conversion): Likewise.
(expand_vector_addition): Likewise for a TYPE_SIZE_UNIT used as
a divisor. Convert the dividend to bits to compensate.
* tree-vect-loop.c (vectorizable_live_operation): Call
vector_element_bits instead of open-coding it.
Diffstat (limited to 'gcc/tree-vect-generic.c')
-rw-r--r-- | gcc/tree-vect-generic.c | 19 |
1 files changed, 7 insertions, 12 deletions
diff --git a/gcc/tree-vect-generic.c b/gcc/tree-vect-generic.c index 8b00f32..126e906 100644 --- a/gcc/tree-vect-generic.c +++ b/gcc/tree-vect-generic.c @@ -276,8 +276,7 @@ expand_vector_piecewise (gimple_stmt_iterator *gsi, elem_op_func f, tree part_width = TYPE_SIZE (inner_type); tree index = bitsize_int (0); int nunits = nunits_for_known_piecewise_op (type); - int delta = tree_to_uhwi (part_width) - / tree_to_uhwi (TYPE_SIZE (TREE_TYPE (type))); + int delta = tree_to_uhwi (part_width) / vector_element_bits (type); int i; location_t loc = gimple_location (gsi_stmt (*gsi)); @@ -357,8 +356,7 @@ expand_vector_addition (gimple_stmt_iterator *gsi, elem_op_func f, elem_op_func f_parallel, tree type, tree a, tree b, enum tree_code code) { - int parts_per_word = UNITS_PER_WORD - / tree_to_uhwi (TYPE_SIZE_UNIT (TREE_TYPE (type))); + int parts_per_word = BITS_PER_WORD / vector_element_bits (type); if (INTEGRAL_TYPE_P (TREE_TYPE (type)) && parts_per_word >= 4 @@ -1727,19 +1725,17 @@ expand_vector_conversion (gimple_stmt_iterator *gsi) optab optab1 = unknown_optab; gcc_checking_assert (VECTOR_TYPE_P (ret_type) && VECTOR_TYPE_P (arg_type)); - gcc_checking_assert (tree_fits_uhwi_p (TYPE_SIZE (TREE_TYPE (ret_type)))); - gcc_checking_assert (tree_fits_uhwi_p (TYPE_SIZE (TREE_TYPE (arg_type)))); if (INTEGRAL_TYPE_P (TREE_TYPE (ret_type)) && SCALAR_FLOAT_TYPE_P (TREE_TYPE (arg_type))) code = FIX_TRUNC_EXPR; else if (INTEGRAL_TYPE_P (TREE_TYPE (arg_type)) && SCALAR_FLOAT_TYPE_P (TREE_TYPE (ret_type))) code = FLOAT_EXPR; - if (tree_to_uhwi (TYPE_SIZE (TREE_TYPE (ret_type))) - < tree_to_uhwi (TYPE_SIZE (TREE_TYPE (arg_type)))) + unsigned int ret_elt_bits = vector_element_bits (ret_type); + unsigned int arg_elt_bits = vector_element_bits (arg_type); + if (ret_elt_bits < arg_elt_bits) modifier = NARROW; - else if (tree_to_uhwi (TYPE_SIZE (TREE_TYPE (ret_type))) - > tree_to_uhwi (TYPE_SIZE (TREE_TYPE (arg_type)))) + else if (ret_elt_bits > arg_elt_bits) modifier = WIDEN; if (modifier == NONE && (code == FIX_TRUNC_EXPR || code == FLOAT_EXPR)) @@ -1902,8 +1898,7 @@ expand_vector_conversion (gimple_stmt_iterator *gsi) tree part_width = TYPE_SIZE (compute_type); tree index = bitsize_int (0); int nunits = nunits_for_known_piecewise_op (arg_type); - int delta = tree_to_uhwi (part_width) - / tree_to_uhwi (TYPE_SIZE (TREE_TYPE (arg_type))); + int delta = tree_to_uhwi (part_width) / arg_elt_bits; int i; location_t loc = gimple_location (gsi_stmt (*gsi)); |