Re: Replace mode_for_int_vector with related_int_vector_mode
On Wed, Oct 23, 2019 at 1:06 PM Richard Sandiford wrote: > > mode_for_int_vector, like mode_for_vector, can sometimes return > an integer mode or an unsupported vector mode. But no callers > are interested in that case, and only want supported vector modes. > This patch therefore replaces mode_for_int_vector with > related_int_vector_mode, which gives the target a chance to pick > its preferred vector mode for the given element mode and size. > > 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/ > * machmode.h (mode_for_int_vector): Delete. > (related_int_vector_mode): Declare. > * stor-layout.c (mode_for_int_vector): Delete. > (related_int_vector_mode): New function. > * optabs.c (expand_vec_perm_1): Use related_int_vector_mode > instead of mode_for_int_vector. > (expand_vec_perm_const): Likewise. > * config/aarch64/aarch64.c (aarch64_emit_approx_sqrt): Likewise. > (aarch64_evpc_sve_tbl): Likewise. > * config/s390/s390.c (s390_expand_vec_compare_cc): Likewise. > (s390_expand_vcond): Likewise. > > Index: gcc/machmode.h > === > --- gcc/machmode.h 2019-10-23 11:33:01.564510281 +0100 > +++ gcc/machmode.h 2019-10-23 12:01:36.968336613 +0100 > @@ -879,22 +879,9 @@ smallest_int_mode_for_size (poly_uint64 > extern opt_scalar_int_mode int_mode_for_mode (machine_mode); > extern opt_machine_mode bitwise_mode_for_mode (machine_mode); > extern opt_machine_mode mode_for_vector (scalar_mode, poly_uint64); > -extern opt_machine_mode mode_for_int_vector (unsigned int, poly_uint64); > extern opt_machine_mode related_vector_mode (machine_mode, scalar_mode, > poly_uint64 = 0); > - > -/* Return the integer vector equivalent of MODE, if one exists. In other > - words, return the mode for an integer vector that has the same number > - of bits as MODE and the same number of elements as MODE, with the > - latter being 1 if MODE is scalar. The returned mode can be either > - an integer mode or a vector mode. */ > - > -inline opt_machine_mode > -mode_for_int_vector (machine_mode mode) > -{ > - return mode_for_int_vector (GET_MODE_UNIT_BITSIZE (mode), > - GET_MODE_NUNITS (mode)); > -} > +extern opt_machine_mode related_int_vector_mode (machine_mode); > > /* A class for iterating through possible bitfield modes. */ > class bit_field_mode_iterator > Index: gcc/stor-layout.c > === > --- gcc/stor-layout.c 2019-10-23 11:33:01.564510281 +0100 > +++ gcc/stor-layout.c 2019-10-23 12:01:36.972336585 +0100 > @@ -515,21 +515,6 @@ mode_for_vector (scalar_mode innermode, >return opt_machine_mode (); > } > > -/* Return the mode for a vector that has NUNITS integer elements of > - INT_BITS bits each, if such a mode exists. The mode can be either > - an integer mode or a vector mode. */ > - > -opt_machine_mode > -mode_for_int_vector (unsigned int int_bits, poly_uint64 nunits) > -{ > - scalar_int_mode int_mode; > - machine_mode vec_mode; > - if (int_mode_for_size (int_bits, 0).exists (_mode) > - && mode_for_vector (int_mode, nunits).exists (_mode)) > -return vec_mode; > - return opt_machine_mode (); > -} > - > /* If a piece of code is using vector mode VECTOR_MODE and also wants > to operate on elements of mode ELEMENT_MODE, return the vector mode > it should use for those elements. If NUNITS is nonzero, ensure that > @@ -550,6 +535,26 @@ related_vector_mode (machine_mode vector >return targetm.vectorize.related_mode (vector_mode, element_mode, nunits); > } > > +/* If a piece of code is using vector mode VECTOR_MODE and also wants > + to operate on integer vectors with the same element size and number > + of elements, return the vector mode it should use. Return an empty > + opt_machine_mode if there is no supported vector mode with the > + required properties. > + > + Unlike mode_for_vector. any returned mode is guaranteed to satisfy > + both VECTOR_MODE_P and targetm.vector_mode_supported_p. */ > + > +opt_machine_mode > +related_int_vector_mode (machine_mode vector_mode) > +{ > + gcc_assert (VECTOR_MODE_P (vector_mode)); > + scalar_int_mode int_mode; > + if (int_mode_for_mode (GET_MODE_INNER (vector_mode)).exists (_mode)) > +return related_vector_mode (vector_mode, int_mode, > + GET_MODE_NUNITS (vector_mode)); > + return opt_machine_mode (); > +} > + > /* Return the alignment of MODE. This will be bounded by 1 and > BIGGEST_ALIGNMENT. */ > > Index: gcc/optabs.c > === > --- gcc/optabs.c2019-10-08 09:23:31.582531825 +0100 > +++ gcc/optabs.c
Replace mode_for_int_vector with related_int_vector_mode
mode_for_int_vector, like mode_for_vector, can sometimes return an integer mode or an unsupported vector mode. But no callers are interested in that case, and only want supported vector modes. This patch therefore replaces mode_for_int_vector with related_int_vector_mode, which gives the target a chance to pick its preferred vector mode for the given element mode and size. 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/ * machmode.h (mode_for_int_vector): Delete. (related_int_vector_mode): Declare. * stor-layout.c (mode_for_int_vector): Delete. (related_int_vector_mode): New function. * optabs.c (expand_vec_perm_1): Use related_int_vector_mode instead of mode_for_int_vector. (expand_vec_perm_const): Likewise. * config/aarch64/aarch64.c (aarch64_emit_approx_sqrt): Likewise. (aarch64_evpc_sve_tbl): Likewise. * config/s390/s390.c (s390_expand_vec_compare_cc): Likewise. (s390_expand_vcond): Likewise. Index: gcc/machmode.h === --- gcc/machmode.h 2019-10-23 11:33:01.564510281 +0100 +++ gcc/machmode.h 2019-10-23 12:01:36.968336613 +0100 @@ -879,22 +879,9 @@ smallest_int_mode_for_size (poly_uint64 extern opt_scalar_int_mode int_mode_for_mode (machine_mode); extern opt_machine_mode bitwise_mode_for_mode (machine_mode); extern opt_machine_mode mode_for_vector (scalar_mode, poly_uint64); -extern opt_machine_mode mode_for_int_vector (unsigned int, poly_uint64); extern opt_machine_mode related_vector_mode (machine_mode, scalar_mode, poly_uint64 = 0); - -/* Return the integer vector equivalent of MODE, if one exists. In other - words, return the mode for an integer vector that has the same number - of bits as MODE and the same number of elements as MODE, with the - latter being 1 if MODE is scalar. The returned mode can be either - an integer mode or a vector mode. */ - -inline opt_machine_mode -mode_for_int_vector (machine_mode mode) -{ - return mode_for_int_vector (GET_MODE_UNIT_BITSIZE (mode), - GET_MODE_NUNITS (mode)); -} +extern opt_machine_mode related_int_vector_mode (machine_mode); /* A class for iterating through possible bitfield modes. */ class bit_field_mode_iterator Index: gcc/stor-layout.c === --- gcc/stor-layout.c 2019-10-23 11:33:01.564510281 +0100 +++ gcc/stor-layout.c 2019-10-23 12:01:36.972336585 +0100 @@ -515,21 +515,6 @@ mode_for_vector (scalar_mode innermode, return opt_machine_mode (); } -/* Return the mode for a vector that has NUNITS integer elements of - INT_BITS bits each, if such a mode exists. The mode can be either - an integer mode or a vector mode. */ - -opt_machine_mode -mode_for_int_vector (unsigned int int_bits, poly_uint64 nunits) -{ - scalar_int_mode int_mode; - machine_mode vec_mode; - if (int_mode_for_size (int_bits, 0).exists (_mode) - && mode_for_vector (int_mode, nunits).exists (_mode)) -return vec_mode; - return opt_machine_mode (); -} - /* If a piece of code is using vector mode VECTOR_MODE and also wants to operate on elements of mode ELEMENT_MODE, return the vector mode it should use for those elements. If NUNITS is nonzero, ensure that @@ -550,6 +535,26 @@ related_vector_mode (machine_mode vector return targetm.vectorize.related_mode (vector_mode, element_mode, nunits); } +/* If a piece of code is using vector mode VECTOR_MODE and also wants + to operate on integer vectors with the same element size and number + of elements, return the vector mode it should use. Return an empty + opt_machine_mode if there is no supported vector mode with the + required properties. + + Unlike mode_for_vector. any returned mode is guaranteed to satisfy + both VECTOR_MODE_P and targetm.vector_mode_supported_p. */ + +opt_machine_mode +related_int_vector_mode (machine_mode vector_mode) +{ + gcc_assert (VECTOR_MODE_P (vector_mode)); + scalar_int_mode int_mode; + if (int_mode_for_mode (GET_MODE_INNER (vector_mode)).exists (_mode)) +return related_vector_mode (vector_mode, int_mode, + GET_MODE_NUNITS (vector_mode)); + return opt_machine_mode (); +} + /* Return the alignment of MODE. This will be bounded by 1 and BIGGEST_ALIGNMENT. */ Index: gcc/optabs.c === --- gcc/optabs.c2019-10-08 09:23:31.582531825 +0100 +++ gcc/optabs.c2019-10-23 12:01:36.972336585 +0100 @@ -5542,7 +5542,7 @@ expand_vec_perm_1 (enum insn_code icode, class expand_operand ops[4]; gcc_assert (GET_MODE_CLASS (smode) == MODE_VECTOR_INT - || mode_for_int_vector (tmode).require () == smode); + ||