aboutsummaryrefslogtreecommitdiff
path: root/gcc/tree.c
diff options
context:
space:
mode:
authorRichard Sandiford <richard.sandiford@arm.com>2020-05-12 09:01:10 +0100
committerRichard Sandiford <richard.sandiford@arm.com>2020-05-12 09:01:10 +0100
commitd17a896da1e898928d337596d029f0ece0039d55 (patch)
tree3907710b0485fb8de89e9de33bb6d452c88a60d1 /gcc/tree.c
parentdc703151d4f4560e647649506d5b4ceb0ee11e90 (diff)
downloadgcc-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.c')
-rw-r--r--gcc/tree.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/gcc/tree.c b/gcc/tree.c
index 5b7d3fd..1aabffe 100644
--- a/gcc/tree.c
+++ b/gcc/tree.c
@@ -13806,6 +13806,30 @@ vector_type_mode (const_tree t)
return mode;
}
+/* Return the size in bits of each element of vector type TYPE. */
+
+unsigned int
+vector_element_bits (const_tree type)
+{
+ gcc_checking_assert (VECTOR_TYPE_P (type));
+ if (VECTOR_BOOLEAN_TYPE_P (type))
+ return vector_element_size (tree_to_poly_uint64 (TYPE_SIZE (type)),
+ TYPE_VECTOR_SUBPARTS (type));
+ return tree_to_uhwi (TYPE_SIZE (TREE_TYPE (type)));
+}
+
+/* Calculate the size in bits of each element of vector type TYPE
+ and return the result as a tree of type bitsizetype. */
+
+tree
+vector_element_bits_tree (const_tree type)
+{
+ gcc_checking_assert (VECTOR_TYPE_P (type));
+ if (VECTOR_BOOLEAN_TYPE_P (type))
+ return bitsize_int (vector_element_bits (type));
+ return TYPE_SIZE (TREE_TYPE (type));
+}
+
/* Verify that basic properties of T match TV and thus T can be a variant of
TV. TV should be the more specified variant (i.e. the main variant). */