+2020-05-12 Richard Sandiford <richard.sandiford@arm.com>
+
+ 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.
+
2020-05-12 Jakub Jelinek <jakub@redhat.com>
* omp-offload.h (omp_discover_implicit_declare_target): Declare.
}
(if (ins)
(bit_insert { op0; } { ins; }
- { bitsize_int (at * tree_to_uhwi (TYPE_SIZE (TREE_TYPE (type)))); })
+ { bitsize_int (at * vector_element_bits (type)); })
(if (changed)
(vec_perm { op0; } { op1; } { op2; }))))))))))
tree *offset_vectype_out)
{
unsigned int memory_bits = tree_to_uhwi (TYPE_SIZE (memory_type));
- unsigned int element_bits = tree_to_uhwi (TYPE_SIZE (TREE_TYPE (vectype)));
+ unsigned int element_bits = vector_element_bits (vectype);
if (element_bits != memory_bits)
/* For now the vector elements must be the same width as the
memory elements. */
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));
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
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))
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));
: gimple_get_lhs (stmt);
lhs_type = TREE_TYPE (lhs);
- bitsize = (VECTOR_BOOLEAN_TYPE_P (vectype)
- ? bitsize_int (TYPE_PRECISION (TREE_TYPE (vectype)))
- : TYPE_SIZE (TREE_TYPE (vectype)));
+ bitsize = vector_element_bits_tree (vectype);
vec_bitsize = TYPE_SIZE (vectype);
/* Get the vectorized lhs of STMT and the lane to use (counted in bits). */
|| dt == vect_constant_def))
{
tree wide_scalar_type = build_nonstandard_integer_type
- (tree_to_uhwi (TYPE_SIZE (TREE_TYPE (vectype1))),
- TYPE_UNSIGNED (rhs1_type));
+ (vector_element_bits (vectype1), TYPE_UNSIGNED (rhs1_type));
tree vectype3 = get_vectype_for_scalar_type (vinfo,
wide_scalar_type);
if (expand_vec_cond_expr_p (vectype1, vectype3, TREE_CODE (rhs1)))
&& tree_int_cst_lt (TYPE_SIZE (scalar_type),
TYPE_SIZE (TREE_TYPE (vectype))))
scalar_type = build_nonstandard_integer_type
- (tree_to_uhwi (TYPE_SIZE (TREE_TYPE (vectype))),
- TYPE_UNSIGNED (scalar_type));
+ (vector_element_bits (vectype), TYPE_UNSIGNED (scalar_type));
*comp_vectype = get_vectype_for_scalar_type (vinfo, scalar_type,
slp_node);
}
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). */
extern machine_mode element_mode (const_tree);
extern machine_mode vector_type_mode (const_tree);
+extern unsigned int vector_element_bits (const_tree);
+extern tree vector_element_bits_tree (const_tree);
/* The "canonical" type for this type node, which is used by frontends to
compare the type for equality with another type. If two types are