Re: Remove build_{same_sized_,}truth_vector_type
On Wed, Oct 23, 2019 at 1:13 PM Richard Sandiford wrote: > > build_same_sized_truth_vector_type was confusingly named, since for > SVE and AVX512 the returned vector isn't the same byte size (although > it does have the same number of elements). What it really returns > is the "truth" vector type for a given data vector type. > > The more general truth_type_for provides the same thing when passed > a vector and IMO has a more descriptive name, so this patch replaces > all uses of build_same_sized_truth_vector_type with that. It does > the same for a call to build_truth_vector_type, leaving truth_type_for > itself as the only remaining caller. > > It's then more natural to pass build_truth_vector_type the original > vector type rather than its size and nunits, especially since the > given size isn't the size of the returned vector. This in turn allows > a future patch to simplify the interface of get_mask_mode. Doing this > also fixes a bug in which truth_type_for would pass a size of zero for > BLKmode vector types. > > Tested individually on aarch64-linux-gnu and as a series on > x86_64-linux-gnu. OK to install? OK. Thanks, Richard. > Richard > > > 2019-10-23 Richard Sandiford > > gcc/ > * tree.h (build_truth_vector_type): Delete. > (build_same_sized_truth_vector_type): Likewise. > * tree.c (build_truth_vector_type): Rename to... > (build_truth_vector_type_for): ...this. Make static and take > a vector type as argument. > (truth_type_for): Update accordingly. > (build_same_sized_truth_vector_type): Delete. > * tree-vect-generic.c (expand_vector_divmod): Use truth_type_for > instead of build_same_sized_truth_vector_type. > * tree-vect-loop.c (vect_create_epilog_for_reduction): Likewise. > (vect_record_loop_mask, vect_get_loop_mask): Likewise. > * tree-vect-patterns.c (build_mask_conversion): Likeise. > * tree-vect-slp.c (vect_get_constant_vectors): Likewise. > * tree-vect-stmts.c (vect_get_vec_def_for_operand): Likewise. > (vect_build_gather_load_calls, vectorizable_call): Likewise. > (scan_store_can_perm_p, vectorizable_scan_store): Likewise. > (vectorizable_store, vectorizable_condition): Likewise. > (get_mask_type_for_scalar_type, get_same_sized_vectype): Likewise. > (vect_get_mask_type_for_stmt): Use truth_type_for instead of > build_truth_vector_type. > * config/rs6000/rs6000-call.c (fold_build_vec_cmp): Use truth_type_for > instead of build_same_sized_truth_vector_type. > > gcc/c/ > * c-typeck.c (build_conditional_expr): Use truth_type_for instead > of build_same_sized_truth_vector_type. > (build_vec_cmp): Likewise. > > gcc/cp/ > * call.c (build_conditional_expr_1): Use truth_type_for instead > of build_same_sized_truth_vector_type. > * typeck.c (build_vec_cmp): Likewise. > > gcc/d/ > * d-codegen.cc (build_boolop): Use truth_type_for instead of > build_same_sized_truth_vector_type. > > Index: gcc/tree.h > === > --- gcc/tree.h 2019-10-23 12:07:54.505663970 +0100 > +++ gcc/tree.h 2019-10-23 12:10:58.116366179 +0100 > @@ -4438,8 +4438,6 @@ extern tree build_reference_type (tree); > extern tree build_vector_type_for_mode (tree, machine_mode); > extern tree build_vector_type (tree, poly_int64); > extern tree build_truth_vector_type_for_mode (poly_uint64, machine_mode); > -extern tree build_truth_vector_type (poly_uint64, poly_uint64); > -extern tree build_same_sized_truth_vector_type (tree vectype); > extern tree build_opaque_vector_type (tree, poly_int64); > extern tree build_index_type (tree); > extern tree build_array_type (tree, tree, bool = false); > Index: gcc/tree.c > === > --- gcc/tree.c 2019-10-23 12:07:54.501663998 +0100 > +++ gcc/tree.c 2019-10-23 12:10:58.116366179 +0100 > @@ -11127,11 +11127,16 @@ build_truth_vector_type_for_mode (poly_u >return make_vector_type (bool_type, nunits, mask_mode); > } > > -/* Build truth vector with specified length and number of units. */ > +/* Build a vector type that holds one boolean result for each element of > + vector type VECTYPE. The public interface for this operation is > + truth_type_for. */ > > -tree > -build_truth_vector_type (poly_uint64 nunits, poly_uint64 vector_size) > +static tree > +build_truth_vector_type_for (tree vectype) > { > + poly_uint64 nunits = TYPE_VECTOR_SUBPARTS (vectype); > + poly_uint64 vector_size = tree_to_poly_uint64 (TYPE_SIZE_UNIT (vectype)); > + >machine_mode mask_mode; >if (targetm.vectorize.get_mask_mode (nunits, >vector_size).exists (_mode)) > @@ -11144,22 +11149,6 @@ build_truth_vector_type (poly_uint64 nun >return make_vector_type (bool_type, nunits, BLKmode); > } > >
Remove build_{same_sized_,}truth_vector_type
build_same_sized_truth_vector_type was confusingly named, since for SVE and AVX512 the returned vector isn't the same byte size (although it does have the same number of elements). What it really returns is the "truth" vector type for a given data vector type. The more general truth_type_for provides the same thing when passed a vector and IMO has a more descriptive name, so this patch replaces all uses of build_same_sized_truth_vector_type with that. It does the same for a call to build_truth_vector_type, leaving truth_type_for itself as the only remaining caller. It's then more natural to pass build_truth_vector_type the original vector type rather than its size and nunits, especially since the given size isn't the size of the returned vector. This in turn allows a future patch to simplify the interface of get_mask_mode. Doing this also fixes a bug in which truth_type_for would pass a size of zero for BLKmode vector types. Tested individually on aarch64-linux-gnu and as a series on x86_64-linux-gnu. OK to install? Richard 2019-10-23 Richard Sandiford gcc/ * tree.h (build_truth_vector_type): Delete. (build_same_sized_truth_vector_type): Likewise. * tree.c (build_truth_vector_type): Rename to... (build_truth_vector_type_for): ...this. Make static and take a vector type as argument. (truth_type_for): Update accordingly. (build_same_sized_truth_vector_type): Delete. * tree-vect-generic.c (expand_vector_divmod): Use truth_type_for instead of build_same_sized_truth_vector_type. * tree-vect-loop.c (vect_create_epilog_for_reduction): Likewise. (vect_record_loop_mask, vect_get_loop_mask): Likewise. * tree-vect-patterns.c (build_mask_conversion): Likeise. * tree-vect-slp.c (vect_get_constant_vectors): Likewise. * tree-vect-stmts.c (vect_get_vec_def_for_operand): Likewise. (vect_build_gather_load_calls, vectorizable_call): Likewise. (scan_store_can_perm_p, vectorizable_scan_store): Likewise. (vectorizable_store, vectorizable_condition): Likewise. (get_mask_type_for_scalar_type, get_same_sized_vectype): Likewise. (vect_get_mask_type_for_stmt): Use truth_type_for instead of build_truth_vector_type. * config/rs6000/rs6000-call.c (fold_build_vec_cmp): Use truth_type_for instead of build_same_sized_truth_vector_type. gcc/c/ * c-typeck.c (build_conditional_expr): Use truth_type_for instead of build_same_sized_truth_vector_type. (build_vec_cmp): Likewise. gcc/cp/ * call.c (build_conditional_expr_1): Use truth_type_for instead of build_same_sized_truth_vector_type. * typeck.c (build_vec_cmp): Likewise. gcc/d/ * d-codegen.cc (build_boolop): Use truth_type_for instead of build_same_sized_truth_vector_type. Index: gcc/tree.h === --- gcc/tree.h 2019-10-23 12:07:54.505663970 +0100 +++ gcc/tree.h 2019-10-23 12:10:58.116366179 +0100 @@ -4438,8 +4438,6 @@ extern tree build_reference_type (tree); extern tree build_vector_type_for_mode (tree, machine_mode); extern tree build_vector_type (tree, poly_int64); extern tree build_truth_vector_type_for_mode (poly_uint64, machine_mode); -extern tree build_truth_vector_type (poly_uint64, poly_uint64); -extern tree build_same_sized_truth_vector_type (tree vectype); extern tree build_opaque_vector_type (tree, poly_int64); extern tree build_index_type (tree); extern tree build_array_type (tree, tree, bool = false); Index: gcc/tree.c === --- gcc/tree.c 2019-10-23 12:07:54.501663998 +0100 +++ gcc/tree.c 2019-10-23 12:10:58.116366179 +0100 @@ -11127,11 +11127,16 @@ build_truth_vector_type_for_mode (poly_u return make_vector_type (bool_type, nunits, mask_mode); } -/* Build truth vector with specified length and number of units. */ +/* Build a vector type that holds one boolean result for each element of + vector type VECTYPE. The public interface for this operation is + truth_type_for. */ -tree -build_truth_vector_type (poly_uint64 nunits, poly_uint64 vector_size) +static tree +build_truth_vector_type_for (tree vectype) { + poly_uint64 nunits = TYPE_VECTOR_SUBPARTS (vectype); + poly_uint64 vector_size = tree_to_poly_uint64 (TYPE_SIZE_UNIT (vectype)); + machine_mode mask_mode; if (targetm.vectorize.get_mask_mode (nunits, vector_size).exists (_mode)) @@ -11144,22 +11149,6 @@ build_truth_vector_type (poly_uint64 nun return make_vector_type (bool_type, nunits, BLKmode); } -/* Returns a vector type corresponding to a comparison of VECTYPE. */ - -tree -build_same_sized_truth_vector_type (tree vectype) -{ - if (VECTOR_BOOLEAN_TYPE_P (vectype)) -return vectype; - - poly_uint64 size = GET_MODE_SIZE (TYPE_MODE (vectype)); - - if (known_eq