> The following factors out a worker that gets a mode argument
> rather than a vectype argument.  That makes a difference when
> we hit the fallback in add_stmt_cost for scalar stmts where
> vectype might be NULL and thus mode is derived from the scalar
> stmt there.  But ix86_builtin_vectorization_cost does not
> have access to the stmt.  So the patch instead dispatches
> to the new ix86_default_vector_cost there, passing down the mode
> we derived from the stmt.
> 
> This is to avoid regressions with a patch that makes even more
> scalar stmt costings have a vectype passed.
> 
> Bootstrapped and tested on x86_64-unknown-linux-gnu.
> 
> OK?
OK,
thanks,
Honza
> 
> Thanks,
> Richard.
> 
>       * config/i386/i386.cc (ix86_default_vector_cost): Split
>       out from ...
>       (ix86_builtin_vectorization_cost): ... this and use
>       mode instead of vectype as argument.
>       (ix86_vector_costs::add_stmt_cost): Call
>       ix86_default_vector_cost instead of ix86_builtin_vectorization_cost.
> ---
>  gcc/config/i386/i386.cc | 41 +++++++++++++++++++++++------------------
>  1 file changed, 23 insertions(+), 18 deletions(-)
> 
> diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc
> index e9611a11f83..613f2b2139d 100644
> --- a/gcc/config/i386/i386.cc
> +++ b/gcc/config/i386/i386.cc
> @@ -25232,20 +25232,14 @@ asm_preferred_eh_data_format (int code, int global)
>    return DW_EH_PE_absptr;
>  }
>  
> -/* Implement targetm.vectorize.builtin_vectorization_cost.  */
> +/* Worker for ix86_builtin_vectorization_cost and the fallback calls
> +   from ix86_vector_costs::add_stmt_cost.  */
>  static int
> -ix86_builtin_vectorization_cost (enum vect_cost_for_stmt type_of_cost,
> -                                 tree vectype, int)
> +ix86_default_vector_cost (enum vect_cost_for_stmt type_of_cost,
> +                       machine_mode mode)
>  {
> -  bool fp = false;
> -  machine_mode mode = TImode;
> +  bool fp = FLOAT_MODE_P (mode);
>    int index;
> -  if (vectype != NULL)
> -    {
> -      fp = FLOAT_TYPE_P (vectype);
> -      mode = TYPE_MODE (vectype);
> -    }
> -
>    switch (type_of_cost)
>      {
>        case scalar_stmt:
> @@ -25304,14 +25298,14 @@ ix86_builtin_vectorization_cost (enum 
> vect_cost_for_stmt type_of_cost,
>                             COSTS_N_INSNS
>                                (ix86_cost->gather_static
>                                 + ix86_cost->gather_per_elt
> -                                 * TYPE_VECTOR_SUBPARTS (vectype)) / 2);
> +                                 * GET_MODE_NUNITS (mode)) / 2);
>  
>        case vector_scatter_store:
>          return ix86_vec_cost (mode,
>                             COSTS_N_INSNS
>                                (ix86_cost->scatter_static
>                                 + ix86_cost->scatter_per_elt
> -                                 * TYPE_VECTOR_SUBPARTS (vectype)) / 2);
> +                                 * GET_MODE_NUNITS (mode)) / 2);
>  
>        case cond_branch_taken:
>          return ix86_cost->cond_taken_branch_cost;
> @@ -25329,7 +25323,7 @@ ix86_builtin_vectorization_cost (enum 
> vect_cost_for_stmt type_of_cost,
>  
>        case vec_construct:
>       {
> -       int n = TYPE_VECTOR_SUBPARTS (vectype);
> +       int n = GET_MODE_NUNITS (mode);
>         /* N - 1 element inserts into an SSE vector, the possible
>            GPR -> XMM move is accounted for in add_stmt_cost.  */
>         if (GET_MODE_BITSIZE (mode) <= 128)
> @@ -25357,6 +25351,17 @@ ix86_builtin_vectorization_cost (enum 
> vect_cost_for_stmt type_of_cost,
>      }
>  }
>  
> +/* Implement targetm.vectorize.builtin_vectorization_cost.  */
> +static int
> +ix86_builtin_vectorization_cost (enum vect_cost_for_stmt type_of_cost,
> +                              tree vectype, int)
> +{
> +  machine_mode mode = TImode;
> +  if (vectype != NULL)
> +    mode = TYPE_MODE (vectype);
> +  return ix86_default_vector_cost (type_of_cost, mode);
> +}
> +
>  
>  /* This function returns the calling abi specific va_list type node.
>     It returns  the FNDECL specific va_list type.  */
> @@ -25810,7 +25815,7 @@ ix86_vectorize_create_costs (vec_info *vinfo, bool 
> costing_for_scalar)
>  unsigned
>  ix86_vector_costs::add_stmt_cost (int count, vect_cost_for_stmt kind,
>                                 stmt_vec_info stmt_info, slp_tree node,
> -                               tree vectype, int misalign,
> +                               tree vectype, int,
>                                 vect_cost_model_location where)
>  {
>    unsigned retval = 0;
> @@ -26159,14 +26164,14 @@ ix86_vector_costs::add_stmt_cost (int count, 
> vect_cost_for_stmt kind,
>              || (SLP_TREE_MEMORY_ACCESS_TYPE (node)
>                  == VMAT_GATHER_SCATTER)))))
>      {
> -      stmt_cost = ix86_builtin_vectorization_cost (kind, vectype, misalign);
> +      stmt_cost = ix86_default_vector_cost (kind, mode);
>        stmt_cost *= (TYPE_VECTOR_SUBPARTS (vectype) + 1);
>      }
>    else if ((kind == vec_construct || kind == scalar_to_vec)
>          && node
>          && SLP_TREE_DEF_TYPE (node) == vect_external_def)
>      {
> -      stmt_cost = ix86_builtin_vectorization_cost (kind, vectype, misalign);
> +      stmt_cost = ix86_default_vector_cost (kind, mode);
>        unsigned i;
>        tree op;
>        FOR_EACH_VEC_ELT (SLP_TREE_SCALAR_OPS (node), i, op)
> @@ -26230,7 +26235,7 @@ ix86_vector_costs::add_stmt_cost (int count, 
> vect_cost_for_stmt kind,
>         TREE_VISITED (op) = 0;
>      }
>    if (stmt_cost == -1)
> -    stmt_cost = ix86_builtin_vectorization_cost (kind, vectype, misalign);
> +    stmt_cost = ix86_default_vector_cost (kind, mode);
>  
>    if (kind == vec_perm && vectype
>        && GET_MODE_SIZE (TYPE_MODE (vectype)) == 32)
> -- 
> 2.43.0

Reply via email to