On Wed, Oct 23, 2019 at 1:06 PM Richard Sandiford
<richard.sandif...@arm.com> 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  <richard.sandif...@arm.com>
>
> 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 (&int_mode)
> -      && mode_for_vector (int_mode, nunits).exists (&vec_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 (&int_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.c        2019-10-08 09:23:31.582531825 +0100
> +++ gcc/optabs.c        2019-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);
> +             || related_int_vector_mode (tmode).require () == smode);
>    create_output_operand (&ops[0], target, tmode);
>    create_input_operand (&ops[3], sel, smode);
>
> @@ -5679,8 +5679,7 @@ expand_vec_perm_const (machine_mode mode
>    /* The optabs are only defined for selectors with the same width
>       as the values being permuted.  */
>    machine_mode required_sel_mode;
> -  if (!mode_for_int_vector (mode).exists (&required_sel_mode)
> -      || !VECTOR_MODE_P (required_sel_mode))
> +  if (!related_int_vector_mode (mode).exists (&required_sel_mode))
>      {
>        delete_insns_since (last);
>        return NULL_RTX;
> Index: gcc/config/aarch64/aarch64.c
> ===================================================================
> --- gcc/config/aarch64/aarch64.c        2019-10-23 11:30:57.553389936 +0100
> +++ gcc/config/aarch64/aarch64.c        2019-10-23 12:01:36.964336643 +0100
> @@ -1761,7 +1761,7 @@ aarch64_sve_element_int_mode (machine_mo
>  }
>
>  /* Return the integer vector mode associated with SVE mode MODE.
> -   Unlike mode_for_int_vector, this can handle the case in which
> +   Unlike related_int_vector_mode, this can handle the case in which
>     MODE is a predicate (and thus has a different total size).  */
>
>  static machine_mode
> @@ -11829,7 +11829,7 @@ aarch64_emit_approx_sqrt (rtx dst, rtx s
>      gcc_assert (use_rsqrt_p (mode));
>
>    machine_mode mmsk = (VECTOR_MODE_P (mode)
> -                      ? mode_for_int_vector (mode).require ()
> +                      ? related_int_vector_mode (mode).require ()
>                        : int_mode_for_mode (mode).require ());
>    rtx xmsk = gen_reg_rtx (mmsk);
>    if (!recp)
> @@ -18232,7 +18232,7 @@ aarch64_evpc_sve_tbl (struct expand_vec_
>    if (d->testing_p)
>      return true;
>
> -  machine_mode sel_mode = mode_for_int_vector (d->vmode).require ();
> +  machine_mode sel_mode = related_int_vector_mode (d->vmode).require ();
>    rtx sel = vec_perm_indices_to_rtx (sel_mode, d->perm);
>    if (d->one_vector_p)
>      emit_unspec2 (d->target, UNSPEC_TBL, d->op0, force_reg (sel_mode, sel));
> Index: gcc/config/s390/s390.c
> ===================================================================
> --- gcc/config/s390/s390.c      2019-10-11 15:43:55.047486939 +0100
> +++ gcc/config/s390/s390.c      2019-10-23 12:01:36.968336613 +0100
> @@ -6653,7 +6653,7 @@ s390_expand_vec_compare_cc (rtx target,
>         case LE:   cc_producer_mode = CCVFHEmode; code = GE; swap_p = true; 
> break;
>         default: gcc_unreachable ();
>         }
> -      scratch_mode = mode_for_int_vector (GET_MODE (cmp1)).require ();
> +      scratch_mode = related_int_vector_mode (GET_MODE (cmp1)).require ();
>
>        if (inv_p)
>         all_p = !all_p;
> @@ -6759,7 +6759,7 @@ s390_expand_vcond (rtx target, rtx then,
>
>    /* We always use an integral type vector to hold the comparison
>       result.  */
> -  result_mode = mode_for_int_vector (cmp_mode).require ();
> +  result_mode = related_int_vector_mode (cmp_mode).require ();
>    result_target = gen_reg_rtx (result_mode);
>
>    /* We allow vector immediates as comparison operands that

Reply via email to