diff mbox series

Use tree_vector_builder instead of build_vector

Message ID 87a7yvank3.fsf_-_@linaro.org
State Accepted
Commit 5ebaa4774fb6de458422c660ae11f1c3b7d96262
Headers show
Series Use tree_vector_builder instead of build_vector | expand

Commit Message

Richard Sandiford Dec. 6, 2017, 3:22 p.m. UTC
This patch switches most build_vector calls over to tree_vector_builder,
using explicit encodings where appropriate.  Later patches handle
the remaining uses of build_vector.

Tested on aarch64-linux-gnu, x86_64-linux-gnu and powerpc64le-linux-gnu.
Also spot-checked on sparc64-linux-gnu.  OK to install?

Thanks,
Richard


2017-12-06  Richard Sandiford  <richard.sandiford@linaro.org>

gcc/
	* config/sparc/sparc.c: Include tree-vector-builder.h.
	(sparc_fold_builtin): Use tree_vector_builder instead of build_vector.
	* expmed.c: Include tree-vector-builder.h.
	(make_tree): Use tree_vector_builder instead of build_vector.
	* fold-const.c: Include tree-vector-builder.h.
	(const_binop): Use tree_vector_builder instead of build_vector.
	(const_unop): Likewise.
	(native_interpret_vector): Likewise.
	(fold_vec_perm): Likewise.
	(fold_ternary_loc): Likewise.
	* gimple-fold.c: Include tree-vector-builder.h.
	(gimple_fold_stmt_to_constant_1): Use tree_vector_builder instead
	of build_vector.
	* tree-ssa-forwprop.c: Include tree-vector-builder.h.
	(simplify_vector_constructor): Use tree_vector_builder instead
	of build_vector.
	* tree-vect-generic.c: Include tree-vector-builder.h.
	(add_rshift): Use tree_vector_builder instead of build_vector.
	(expand_vector_divmod): Likewise.
	(optimize_vector_constructor): Likewise.
	* tree-vect-loop.c: Include tree-vector-builder.h.
	(vect_create_epilog_for_reduction): Use tree_vector_builder instead
	of build_vector.  Explicitly use a stepped encoding for
	{ 1, 2, 3, ... }.
	* tree-vect-slp.c: Include tree-vector-builder.h.
	(vect_get_constant_vectors): Use tree_vector_builder instead
	of build_vector.
	(vect_transform_slp_perm_load): Likewise.
	(vect_schedule_slp_instance): Likewise.
	* tree-vect-stmts.c: Include tree-vector-builder.h.
	(vectorizable_bswap): Use tree_vector_builder instead of build_vector.
	(vect_gen_perm_mask_any): Likewise.
	(vectorizable_call): Likewise.  Explicitly use a stepped encoding.
	* tree.c: (build_vector_from_ctor): Use tree_vector_builder instead
	of build_vector.
	(build_vector_from_val): Likewise.  Explicitly use a duplicate
	encoding.

Comments

Richard Biener Dec. 7, 2017, 11:06 a.m. UTC | #1
On Wed, Dec 6, 2017 at 4:22 PM, Richard Sandiford
<richard.sandiford@linaro.org> wrote:
> This patch switches most build_vector calls over to tree_vector_builder,

> using explicit encodings where appropriate.  Later patches handle

> the remaining uses of build_vector.

>

> Tested on aarch64-linux-gnu, x86_64-linux-gnu and powerpc64le-linux-gnu.

> Also spot-checked on sparc64-linux-gnu.  OK to install?


Ok.

Richard.

> Thanks,

> Richard


>

> 2017-12-06  Richard Sandiford  <richard.sandiford@linaro.org>

>

> gcc/

>         * config/sparc/sparc.c: Include tree-vector-builder.h.

>         (sparc_fold_builtin): Use tree_vector_builder instead of build_vector.

>         * expmed.c: Include tree-vector-builder.h.

>         (make_tree): Use tree_vector_builder instead of build_vector.

>         * fold-const.c: Include tree-vector-builder.h.

>         (const_binop): Use tree_vector_builder instead of build_vector.

>         (const_unop): Likewise.

>         (native_interpret_vector): Likewise.

>         (fold_vec_perm): Likewise.

>         (fold_ternary_loc): Likewise.

>         * gimple-fold.c: Include tree-vector-builder.h.

>         (gimple_fold_stmt_to_constant_1): Use tree_vector_builder instead

>         of build_vector.

>         * tree-ssa-forwprop.c: Include tree-vector-builder.h.

>         (simplify_vector_constructor): Use tree_vector_builder instead

>         of build_vector.

>         * tree-vect-generic.c: Include tree-vector-builder.h.

>         (add_rshift): Use tree_vector_builder instead of build_vector.

>         (expand_vector_divmod): Likewise.

>         (optimize_vector_constructor): Likewise.

>         * tree-vect-loop.c: Include tree-vector-builder.h.

>         (vect_create_epilog_for_reduction): Use tree_vector_builder instead

>         of build_vector.  Explicitly use a stepped encoding for

>         { 1, 2, 3, ... }.

>         * tree-vect-slp.c: Include tree-vector-builder.h.

>         (vect_get_constant_vectors): Use tree_vector_builder instead

>         of build_vector.

>         (vect_transform_slp_perm_load): Likewise.

>         (vect_schedule_slp_instance): Likewise.

>         * tree-vect-stmts.c: Include tree-vector-builder.h.

>         (vectorizable_bswap): Use tree_vector_builder instead of build_vector.

>         (vect_gen_perm_mask_any): Likewise.

>         (vectorizable_call): Likewise.  Explicitly use a stepped encoding.

>         * tree.c: (build_vector_from_ctor): Use tree_vector_builder instead

>         of build_vector.

>         (build_vector_from_val): Likewise.  Explicitly use a duplicate

>         encoding.

>

> Index: gcc/config/sparc/sparc.c

> ===================================================================

> --- gcc/config/sparc/sparc.c    2017-12-05 14:24:52.587013199 +0000

> +++ gcc/config/sparc/sparc.c    2017-12-06 14:48:52.885162299 +0000

> @@ -57,6 +57,7 @@ the Free Software Foundation; either ver

>  #include "tree-pass.h"

>  #include "context.h"

>  #include "builtins.h"

> +#include "tree-vector-builder.h"

>

>  /* This file should be included last.  */

>  #include "target-def.h"

> @@ -11752,14 +11753,14 @@ sparc_fold_builtin (tree fndecl, int n_a

>           tree inner_type = TREE_TYPE (rtype);

>           unsigned i;

>

> -         auto_vec<tree, 32> n_elts (VECTOR_CST_NELTS (arg0));

> +         tree_vector_builder n_elts (rtype, VECTOR_CST_NELTS (arg0), 1);

>           for (i = 0; i < VECTOR_CST_NELTS (arg0); ++i)

>             {

>               unsigned HOST_WIDE_INT val

>                 = TREE_INT_CST_LOW (VECTOR_CST_ELT (arg0, i));

>               n_elts.quick_push (build_int_cst (inner_type, val << 4));

>             }

> -         return build_vector (rtype, n_elts);

> +         return n_elts.build ();

>         }

>        break;

>

> @@ -11774,9 +11775,9 @@ sparc_fold_builtin (tree fndecl, int n_a

>        if (TREE_CODE (arg0) == VECTOR_CST && TREE_CODE (arg1) == VECTOR_CST)

>         {

>           tree inner_type = TREE_TYPE (rtype);

> -         auto_vec<tree, 32> n_elts (VECTOR_CST_NELTS (arg0));

> +         tree_vector_builder n_elts (rtype, VECTOR_CST_NELTS (arg0), 1);

>           sparc_handle_vis_mul8x16 (&n_elts, code, inner_type, arg0, arg1);

> -         return build_vector (rtype, n_elts);

> +         return n_elts.build ();

>         }

>        break;

>

> @@ -11788,7 +11789,7 @@ sparc_fold_builtin (tree fndecl, int n_a

>

>        if (TREE_CODE (arg0) == VECTOR_CST && TREE_CODE (arg1) == VECTOR_CST)

>         {

> -         auto_vec<tree, 32> n_elts (2 * VECTOR_CST_NELTS (arg0));

> +         tree_vector_builder n_elts (rtype, 2 * VECTOR_CST_NELTS (arg0), 1);

>           unsigned i;

>           for (i = 0; i < VECTOR_CST_NELTS (arg0); ++i)

>             {

> @@ -11796,7 +11797,7 @@ sparc_fold_builtin (tree fndecl, int n_a

>               n_elts.quick_push (VECTOR_CST_ELT (arg1, i));

>             }

>

> -         return build_vector (rtype, n_elts);

> +         return n_elts.build ();

>         }

>        break;

>

> Index: gcc/expmed.c

> ===================================================================

> --- gcc/expmed.c        2017-11-29 11:06:34.698180685 +0000

> +++ gcc/expmed.c        2017-12-06 14:48:52.886162258 +0000

> @@ -40,6 +40,7 @@ Software Foundation; either version 3, o

>  #include "explow.h"

>  #include "expr.h"

>  #include "langhooks.h"

> +#include "tree-vector-builder.h"

>

>  struct target_expmed default_target_expmed;

>  #if SWITCHABLE_TARGET

> @@ -5184,14 +5185,14 @@ make_tree (tree type, rtx x)

>         int i;

>

>         /* Build a tree with vector elements.  */

> -       auto_vec<tree, 32> elts (units);

> +       tree_vector_builder elts (type, units, 1);

>         for (i = 0; i < units; ++i)

>           {

>             rtx elt = CONST_VECTOR_ELT (x, i);

>             elts.quick_push (make_tree (itype, elt));

>           }

>

> -       return build_vector (type, elts);

> +       return elts.build ();

>        }

>

>      case PLUS:

> Index: gcc/fold-const.c

> ===================================================================

> --- gcc/fold-const.c    2017-12-06 14:46:14.129599986 +0000

> +++ gcc/fold-const.c    2017-12-06 14:48:52.887162217 +0000

> @@ -81,6 +81,7 @@ Software Foundation; either version 3, o

>  #include "selftest.h"

>  #include "stringpool.h"

>  #include "attribs.h"

> +#include "tree-vector-builder.h"

>

>  /* Nonzero if we are folding constants inside an initializer; zero

>     otherwise.  */

> @@ -1507,7 +1508,7 @@ const_binop (enum tree_code code, tree t

>         gcc_assert (in_nelts == VECTOR_CST_NELTS (arg2)

>                     && out_nelts == TYPE_VECTOR_SUBPARTS (type));

>

> -       auto_vec<tree, 32> elts (out_nelts);

> +       tree_vector_builder elts (type, out_nelts, 1);

>         for (i = 0; i < out_nelts; i++)

>           {

>             tree elt = (i < in_nelts

> @@ -1521,7 +1522,7 @@ const_binop (enum tree_code code, tree t

>             elts.quick_push (elt);

>           }

>

> -       return build_vector (type, elts);

> +       return elts.build ();

>        }

>

>      case VEC_WIDEN_MULT_LO_EXPR:

> @@ -1548,7 +1549,7 @@ const_binop (enum tree_code code, tree t

>         else /* if (code == VEC_WIDEN_MULT_ODD_EXPR) */

>           scale = 1, ofs = 1;

>

> -       auto_vec<tree, 32> elts (out_nelts);

> +       tree_vector_builder elts (type, out_nelts, 1);

>         for (out = 0; out < out_nelts; out++)

>           {

>             unsigned int in = (out << scale) + ofs;

> @@ -1565,7 +1566,7 @@ const_binop (enum tree_code code, tree t

>             elts.quick_push (elt);

>           }

>

> -       return build_vector (type, elts);

> +       return elts.build ();

>        }

>

>      default:;

> @@ -1704,7 +1705,7 @@ const_unop (enum tree_code code, tree ty

>         else

>           subcode = FLOAT_EXPR;

>

> -       auto_vec<tree, 32> elts (out_nelts);

> +       tree_vector_builder elts (type, out_nelts, 1);

>         for (i = 0; i < out_nelts; i++)

>           {

>             tree elt = fold_convert_const (subcode, TREE_TYPE (type),

> @@ -1714,7 +1715,7 @@ const_unop (enum tree_code code, tree ty

>             elts.quick_push (elt);

>           }

>

> -       return build_vector (type, elts);

> +       return elts.build ();

>        }

>

>      default:

> @@ -7377,7 +7378,7 @@ native_interpret_vector (tree type, cons

>    if (size * count > len)

>      return NULL_TREE;

>

> -  auto_vec<tree, 32> elements (count);

> +  tree_vector_builder elements (type, count, 1);

>    for (i = 0; i < count; ++i)

>      {

>        elem = native_interpret_expr (etype, ptr+(i*size), size);

> @@ -7385,7 +7386,7 @@ native_interpret_vector (tree type, cons

>         return NULL_TREE;

>        elements.quick_push (elem);

>      }

> -  return build_vector (type, elements);

> +  return elements.build ();

>  }

>

>

> @@ -8755,7 +8756,7 @@ fold_vec_perm (tree type, tree arg0, tre

>        || !vec_cst_ctor_to_array (arg1, nelts, in_elts + nelts))

>      return NULL_TREE;

>

> -  auto_vec<tree, 32> out_elts (nelts);

> +  tree_vector_builder out_elts (type, nelts, 1);

>    for (i = 0; i < nelts; i++)

>      {

>        if (!CONSTANT_CLASS_P (in_elts[sel[i]]))

> @@ -8772,7 +8773,7 @@ fold_vec_perm (tree type, tree arg0, tre

>        return build_constructor (type, v);

>      }

>    else

> -    return build_vector (type, out_elts);

> +    return out_elts.build ();

>  }

>

>  /* Try to fold a pointer difference of type TYPE two address expressions of

> @@ -11426,10 +11427,10 @@ fold_ternary_loc (location_t loc, enum t

>                   if (n == 1)

>                     return VECTOR_CST_ELT (arg0, idx);

>

> -                 auto_vec<tree, 32> vals (n);

> +                 tree_vector_builder vals (type, n, 1);

>                   for (unsigned i = 0; i < n; ++i)

>                     vals.quick_push (VECTOR_CST_ELT (arg0, idx + i));

> -                 return build_vector (type, vals);

> +                 return vals.build ();

>                 }

>             }

>         }

> @@ -11565,10 +11566,10 @@ fold_ternary_loc (location_t loc, enum t

>           if (need_mask_canon && arg2 == op2)

>             {

>               tree eltype = TREE_TYPE (TREE_TYPE (arg2));

> -             auto_vec<tree, 32> tsel (nelts);

> +             tree_vector_builder tsel (TREE_TYPE (arg2), nelts, 1);

>               for (i = 0; i < nelts; i++)

>                 tsel.quick_push (build_int_cst (eltype, sel[i]));

> -             op2 = build_vector (TREE_TYPE (arg2), tsel);

> +             op2 = tsel.build ();

>               changed = true;

>             }

>

> @@ -11608,11 +11609,11 @@ fold_ternary_loc (location_t loc, enum t

>               else

>                 {

>                   unsigned int nelts = VECTOR_CST_NELTS (arg0);

> -                 auto_vec<tree, 32> elts (nelts);

> +                 tree_vector_builder elts (type, nelts, 1);

>                   elts.quick_grow (nelts);

> -                 for (unsigned int i = 0; i < VECTOR_CST_NELTS (arg0); ++i)

> +                 for (unsigned int i = 0; i < nelts; ++i)

>                     elts[i] = (i == k ? arg1 : VECTOR_CST_ELT (arg0, i));

> -                 return build_vector (type, elts);

> +                 return elts.build ();

>                 }

>             }

>         }

> Index: gcc/gimple-fold.c

> ===================================================================

> --- gcc/gimple-fold.c   2017-12-05 14:24:56.014949665 +0000

> +++ gcc/gimple-fold.c   2017-12-06 14:48:52.888162175 +0000

> @@ -63,6 +63,7 @@ Free Software Foundation; either version

>  #include "diagnostic-core.h"

>  #include "intl.h"

>  #include "calls.h"

> +#include "tree-vector-builder.h"

>

>  /* Return true when DECL can be referenced from current unit.

>     FROM_DECL (if non-null) specify constructor of variable DECL was taken from.

> @@ -6022,7 +6023,7 @@ gimple_fold_stmt_to_constant_1 (gimple *

>                   tree val;

>

>                   nelts = TYPE_VECTOR_SUBPARTS (TREE_TYPE (rhs));

> -                 auto_vec<tree, 32> vec (nelts);

> +                 tree_vector_builder vec (TREE_TYPE (rhs), nelts, 1);

>                   FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (rhs), i, val)

>                     {

>                       val = (*valueize) (val);

> @@ -6034,7 +6035,7 @@ gimple_fold_stmt_to_constant_1 (gimple *

>                         return NULL_TREE;

>                     }

>

> -                 return build_vector (TREE_TYPE (rhs), vec);

> +                 return vec.build ();

>                 }

>               if (subcode == OBJ_TYPE_REF)

>                 {

> Index: gcc/tree-ssa-forwprop.c

> ===================================================================

> --- gcc/tree-ssa-forwprop.c     2017-11-29 11:06:31.942215941 +0000

> +++ gcc/tree-ssa-forwprop.c     2017-12-06 14:48:52.888162175 +0000

> @@ -46,6 +46,7 @@ the Free Software Foundation; either ver

>  #include "tree-cfgcleanup.h"

>  #include "cfganal.h"

>  #include "optabs-tree.h"

> +#include "tree-vector-builder.h"

>

>  /* This pass propagates the RHS of assignment statements into use

>     sites of the LHS of the assignment.  It's basically a specialized

> @@ -2116,10 +2117,10 @@ simplify_vector_constructor (gimple_stmt

>           || GET_MODE_SIZE (TYPE_MODE (mask_type))

>              != GET_MODE_SIZE (TYPE_MODE (type)))

>         return false;

> -      auto_vec<tree, 32> mask_elts (nelts);

> +      tree_vector_builder mask_elts (mask_type, nelts, 1);

>        for (i = 0; i < nelts; i++)

>         mask_elts.quick_push (build_int_cst (TREE_TYPE (mask_type), sel[i]));

> -      op2 = build_vector (mask_type, mask_elts);

> +      op2 = mask_elts.build ();

>        if (conv_code == ERROR_MARK)

>         gimple_assign_set_rhs_with_ops (gsi, VEC_PERM_EXPR, orig, orig, op2);

>        else

> Index: gcc/tree-vect-generic.c

> ===================================================================

> --- gcc/tree-vect-generic.c     2017-11-29 11:06:34.810688336 +0000

> +++ gcc/tree-vect-generic.c     2017-12-06 14:48:52.889162134 +0000

> @@ -37,6 +37,7 @@ Free Software Foundation; either version

>  #include "gimplify-me.h"

>  #include "gimplify.h"

>  #include "tree-cfg.h"

> +#include "tree-vector-builder.h"

>

>

>  static void expand_vector_operations_1 (gimple_stmt_iterator *);

> @@ -398,11 +399,10 @@ add_rshift (gimple_stmt_iterator *gsi, t

>    if (op != unknown_optab

>        && optab_handler (op, TYPE_MODE (type)) != CODE_FOR_nothing)

>      {

> -      auto_vec<tree, 32> vec (nunits);

> +      tree_vector_builder vec (type, nunits, 1);

>        for (i = 0; i < nunits; i++)

>         vec.quick_push (build_int_cst (TREE_TYPE (type), shiftcnts[i]));

> -      return gimplify_build2 (gsi, RSHIFT_EXPR, type, op0,

> -                             build_vector (type, vec));

> +      return gimplify_build2 (gsi, RSHIFT_EXPR, type, op0, vec.build ());

>      }

>

>    return NULL_TREE;

> @@ -635,12 +635,12 @@ expand_vector_divmod (gimple_stmt_iterat

>               mask_type = build_same_sized_truth_vector_type (type);

>               zero = build_zero_cst (type);

>               cond = build2 (LT_EXPR, mask_type, op0, zero);

> -             auto_vec<tree, 32> vec (nunits);

> +             tree_vector_builder vec (type, nunits, 1);

>               for (i = 0; i < nunits; i++)

>                 vec.quick_push (build_int_cst (TREE_TYPE (type),

>                                                (HOST_WIDE_INT_1U

>                                                 << shifts[i]) - 1));

> -             cst = build_vector (type, vec);

> +             cst = vec.build ();

>               addend = make_ssa_name (type);

>               stmt = gimple_build_assign (addend, VEC_COND_EXPR, cond,

>                                           cst, zero);

> @@ -674,12 +674,12 @@ expand_vector_divmod (gimple_stmt_iterat

>        else

>         {

>           tree mask;

> -         auto_vec<tree, 32> vec (nunits);

> +         tree_vector_builder vec (type, nunits, 1);

>           for (i = 0; i < nunits; i++)

>             vec.quick_push (build_int_cst (TREE_TYPE (type),

>                                            (HOST_WIDE_INT_1U

>                                             << shifts[i]) - 1));

> -         mask = build_vector (type, vec);

> +         mask = vec.build ();

>           op = optab_for_tree_code (BIT_AND_EXPR, type, optab_default);

>           if (op != unknown_optab

>               && optab_handler (op, TYPE_MODE (type)) != CODE_FOR_nothing)

> @@ -753,10 +753,10 @@ expand_vector_divmod (gimple_stmt_iterat

>        return NULL_TREE;

>      }

>

> -  auto_vec<tree, 32> vec (nunits);

> +  tree_vector_builder vec (type, nunits, 1);

>    for (i = 0; i < nunits; i++)

>      vec.quick_push (build_int_cst (TREE_TYPE (type), mulc[i]));

> -  mulcst = build_vector (type, vec);

> +  mulcst = vec.build ();

>

>    cur_op = gimplify_build2 (gsi, MULT_HIGHPART_EXPR, type, cur_op, mulcst);

>

> @@ -1104,7 +1104,7 @@ optimize_vector_constructor (gimple_stmt

>        }

>    if (all_same)

>      return;

> -  auto_vec<tree, 32> cst (nelts);

> +  tree_vector_builder cst (type, nelts, 1);

>    for (i = 0; i < nelts; i++)

>      {

>        tree this_base = CONSTRUCTOR_ELT (rhs, i)->value;

> @@ -1127,7 +1127,7 @@ optimize_vector_constructor (gimple_stmt

>    g = gimple_build_assign (make_ssa_name (type), rhs);

>    gsi_insert_before (gsi, g, GSI_SAME_STMT);

>    g = gimple_build_assign (lhs, PLUS_EXPR, gimple_assign_lhs (g),

> -                          build_vector (type, cst));

> +                          cst.build ());

>    gsi_replace (gsi, g, false);

>  }

>

> Index: gcc/tree-vect-loop.c

> ===================================================================

> --- gcc/tree-vect-loop.c        2017-11-29 11:06:34.910905236 +0000

> +++ gcc/tree-vect-loop.c        2017-12-06 14:48:52.889162134 +0000

> @@ -51,6 +51,7 @@ Software Foundation; either version 3, o

>  #include "tree-cfg.h"

>  #include "tree-if-conv.h"

>  #include "internal-fn.h"

> +#include "tree-vector-builder.h"

>

>  /* Loop Vectorization Pass.

>

> @@ -4497,10 +4498,10 @@ vect_create_epilog_for_reduction (vec<tr

>          vector size (STEP).  */

>

>        /* Create a {1,2,3,...} vector.  */

> -      auto_vec<tree, 32> vtemp (nunits_out);

> -      for (k = 0; k < nunits_out; ++k)

> +      tree_vector_builder vtemp (cr_index_vector_type, 1, 3);

> +      for (k = 0; k < 3; ++k)

>         vtemp.quick_push (build_int_cst (cr_index_scalar_type, k + 1));

> -      tree series_vect = build_vector (cr_index_vector_type, vtemp);

> +      tree series_vect = vtemp.build ();

>

>        /* Create a vector of the step value.  */

>        tree step = build_int_cst (cr_index_scalar_type, nunits_out);

> Index: gcc/tree-vect-slp.c

> ===================================================================

> --- gcc/tree-vect-slp.c 2017-12-05 14:24:56.178946625 +0000

> +++ gcc/tree-vect-slp.c 2017-12-06 14:48:52.890162093 +0000

> @@ -41,6 +41,7 @@ Software Foundation; either version 3, o

>  #include "langhooks.h"

>  #include "gimple-walk.h"

>  #include "dbgcnt.h"

> +#include "tree-vector-builder.h"

>

>

>  /* Recursively free the memory allocated for the SLP tree rooted at NODE.  */

> @@ -3222,7 +3223,7 @@ vect_get_constant_vectors (tree op, slp_

>

>    number_of_places_left_in_vector = nunits;

>    constant_p = true;

> -  auto_vec<tree, 32> elts (nunits);

> +  tree_vector_builder elts (vector_type, nunits, 1);

>    elts.quick_grow (nunits);

>    bool place_after_defs = false;

>    for (j = 0; j < number_of_copies; j++)

> @@ -3340,7 +3341,7 @@ vect_get_constant_vectors (tree op, slp_

>            if (number_of_places_left_in_vector == 0)

>              {

>               if (constant_p)

> -               vec_cst = build_vector (vector_type, elts);

> +               vec_cst = elts.build ();

>               else

>                 {

>                   vec<constructor_elt, va_gc> *v;

> @@ -3371,6 +3372,8 @@ vect_get_constant_vectors (tree op, slp_

>               place_after_defs = false;

>                number_of_places_left_in_vector = nunits;

>               constant_p = true;

> +             elts.new_vector (vector_type, nunits, 1);

> +             elts.quick_grow (nunits);

>              }

>          }

>      }

> @@ -3667,11 +3670,11 @@ vect_transform_slp_perm_load (slp_tree n

>

>                   if (! noop_p)

>                     {

> -                     auto_vec<tree, 32> mask_elts (nunits);

> +                     tree_vector_builder mask_elts (mask_type, nunits, 1);

>                       for (int l = 0; l < nunits; ++l)

>                         mask_elts.quick_push (build_int_cst (mask_element_type,

>                                                              mask[l]));

> -                     mask_vec = build_vector (mask_type, mask_elts);

> +                     mask_vec = mask_elts.build ();

>                     }

>

>                   if (second_vec_index == -1)

> @@ -3823,7 +3826,7 @@ vect_schedule_slp_instance (slp_tree nod

>           for (j = 0; j < v0.length (); ++j)

>             {

>               unsigned int nunits = TYPE_VECTOR_SUBPARTS (vectype);

> -             auto_vec<tree, 32> melts (nunits);

> +             tree_vector_builder melts (mvectype, nunits, 1);

>               for (l = 0; l < nunits; ++l)

>                 {

>                   if (k >= group_size)

> @@ -3831,7 +3834,7 @@ vect_schedule_slp_instance (slp_tree nod

>                   tree t = build_int_cst (meltype, mask[k++] * nunits + l);

>                   melts.quick_push (t);

>                 }

> -             tmask = build_vector (mvectype, melts);

> +             tmask = melts.build ();

>

>               /* ???  Not all targets support a VEC_PERM_EXPR with a

>                  constant mask that would translate to a vec_merge RTX

> Index: gcc/tree-vect-stmts.c

> ===================================================================

> --- gcc/tree-vect-stmts.c       2017-11-29 11:06:29.970567408 +0000

> +++ gcc/tree-vect-stmts.c       2017-12-06 14:48:52.890162093 +0000

> @@ -48,6 +48,7 @@ Software Foundation; either version 3, o

>  #include "tree-vectorizer.h"

>  #include "builtins.h"

>  #include "internal-fn.h"

> +#include "tree-vector-builder.h"

>

>  /* For lang_hooks.types.type_for_mode.  */

>  #include "langhooks.h"

> @@ -2520,10 +2521,10 @@ vectorizable_bswap (gimple *stmt, gimple

>        return true;

>      }

>

> -  auto_vec<tree, 32> telts (num_bytes);

> +  tree_vector_builder telts (char_vectype, num_bytes, 1);

>    for (unsigned i = 0; i < num_bytes; ++i)

>      telts.quick_push (build_int_cst (char_type_node, elts[i]));

> -  tree bswap_vconst = build_vector (char_vectype, telts);

> +  tree bswap_vconst = telts.build ();

>

>    /* Transform.  */

>    vec<tree> vec_oprnds = vNULL;

> @@ -2941,11 +2942,11 @@ vectorizable_call (gimple *gs, gimple_st

>           if (gimple_call_internal_p (stmt)

>               && gimple_call_internal_fn (stmt) == IFN_GOMP_SIMD_LANE)

>             {

> -             auto_vec<tree, 32> v (nunits_out);

> -             for (int k = 0; k < nunits_out; ++k)

> +             tree_vector_builder v (vectype_out, 1, 3);

> +             for (int k = 0; k < 3; ++k)

>                 v.quick_push (build_int_cst (unsigned_type_node,

>                                              j * nunits_out + k));

> -             tree cst = build_vector (vectype_out, v);

> +             tree cst = v.build ();

>               tree new_var

>                 = vect_get_new_ssa_name (vectype_out, vect_simple_var, "cst_");

>               gimple *init_stmt = gimple_build_assign (new_var, cst);

> @@ -6507,7 +6508,7 @@ vectorizable_store (gimple *stmt, gimple

>  tree

>  vect_gen_perm_mask_any (tree vectype, vec_perm_indices sel)

>  {

> -  tree mask_elt_type, mask_type, mask_vec;

> +  tree mask_elt_type, mask_type;

>

>    unsigned int nunits = sel.length ();

>    gcc_checking_assert (nunits == TYPE_VECTOR_SUBPARTS (vectype));

> @@ -6516,12 +6517,10 @@ vect_gen_perm_mask_any (tree vectype, ve

>      (int_mode_for_mode (TYPE_MODE (TREE_TYPE (vectype))).require (), 1);

>    mask_type = get_vectype_for_scalar_type (mask_elt_type);

>

> -  auto_vec<tree, 32> mask_elts (nunits);

> +  tree_vector_builder mask_elts (mask_type, nunits, 1);

>    for (unsigned int i = 0; i < nunits; ++i)

>      mask_elts.quick_push (build_int_cst (mask_elt_type, sel[i]));

> -  mask_vec = build_vector (mask_type, mask_elts);

> -

> -  return mask_vec;

> +  return mask_elts.build ();

>  }

>

>  /* Checked version of vect_gen_perm_mask_any.  Asserts can_vec_perm_p,

> Index: gcc/tree.c

> ===================================================================

> --- gcc/tree.c  2017-12-06 14:46:14.132599861 +0000

> +++ gcc/tree.c  2017-12-06 14:48:52.891162052 +0000

> @@ -1757,7 +1757,7 @@ build_vector_from_ctor (tree type, vec<c

>    unsigned HOST_WIDE_INT idx;

>    tree value;

>

> -  auto_vec<tree, 32> vec (nelts);

> +  tree_vector_builder vec (type, nelts, 1);

>    FOR_EACH_CONSTRUCTOR_VALUE (v, idx, value)

>      {

>        if (TREE_CODE (value) == VECTOR_CST)

> @@ -1769,7 +1769,7 @@ build_vector_from_ctor (tree type, vec<c

>    while (vec.length () < nelts)

>      vec.quick_push (build_zero_cst (TREE_TYPE (type)));

>

> -  return build_vector (type, vec);

> +  return vec.build ();

>  }

>

>  /* Build a vector of type VECTYPE where all the elements are SCs.  */

> @@ -1792,10 +1792,9 @@ build_vector_from_val (tree vectype, tre

>

>    if (CONSTANT_CLASS_P (sc))

>      {

> -      auto_vec<tree, 32> v (nunits);

> -      for (i = 0; i < nunits; ++i)

> -       v.quick_push (sc);

> -      return build_vector (vectype, v);

> +      tree_vector_builder v (vectype, 1, 1);

> +      v.quick_push (sc);

> +      return v.build ();

>      }

>    else

>      {
diff mbox series

Patch

Index: gcc/config/sparc/sparc.c
===================================================================
--- gcc/config/sparc/sparc.c	2017-12-05 14:24:52.587013199 +0000
+++ gcc/config/sparc/sparc.c	2017-12-06 14:48:52.885162299 +0000
@@ -57,6 +57,7 @@  the Free Software Foundation; either ver
 #include "tree-pass.h"
 #include "context.h"
 #include "builtins.h"
+#include "tree-vector-builder.h"
 
 /* This file should be included last.  */
 #include "target-def.h"
@@ -11752,14 +11753,14 @@  sparc_fold_builtin (tree fndecl, int n_a
 	  tree inner_type = TREE_TYPE (rtype);
 	  unsigned i;
 
-	  auto_vec<tree, 32> n_elts (VECTOR_CST_NELTS (arg0));
+	  tree_vector_builder n_elts (rtype, VECTOR_CST_NELTS (arg0), 1);
 	  for (i = 0; i < VECTOR_CST_NELTS (arg0); ++i)
 	    {
 	      unsigned HOST_WIDE_INT val
 		= TREE_INT_CST_LOW (VECTOR_CST_ELT (arg0, i));
 	      n_elts.quick_push (build_int_cst (inner_type, val << 4));
 	    }
-	  return build_vector (rtype, n_elts);
+	  return n_elts.build ();
 	}
       break;
 
@@ -11774,9 +11775,9 @@  sparc_fold_builtin (tree fndecl, int n_a
       if (TREE_CODE (arg0) == VECTOR_CST && TREE_CODE (arg1) == VECTOR_CST)
 	{
 	  tree inner_type = TREE_TYPE (rtype);
-	  auto_vec<tree, 32> n_elts (VECTOR_CST_NELTS (arg0));
+	  tree_vector_builder n_elts (rtype, VECTOR_CST_NELTS (arg0), 1);
 	  sparc_handle_vis_mul8x16 (&n_elts, code, inner_type, arg0, arg1);
-	  return build_vector (rtype, n_elts);
+	  return n_elts.build ();
 	}
       break;
 
@@ -11788,7 +11789,7 @@  sparc_fold_builtin (tree fndecl, int n_a
 
       if (TREE_CODE (arg0) == VECTOR_CST && TREE_CODE (arg1) == VECTOR_CST)
 	{
-	  auto_vec<tree, 32> n_elts (2 * VECTOR_CST_NELTS (arg0));
+	  tree_vector_builder n_elts (rtype, 2 * VECTOR_CST_NELTS (arg0), 1);
 	  unsigned i;
 	  for (i = 0; i < VECTOR_CST_NELTS (arg0); ++i)
 	    {
@@ -11796,7 +11797,7 @@  sparc_fold_builtin (tree fndecl, int n_a
 	      n_elts.quick_push (VECTOR_CST_ELT (arg1, i));
 	    }
 
-	  return build_vector (rtype, n_elts);
+	  return n_elts.build ();
 	}
       break;
 
Index: gcc/expmed.c
===================================================================
--- gcc/expmed.c	2017-11-29 11:06:34.698180685 +0000
+++ gcc/expmed.c	2017-12-06 14:48:52.886162258 +0000
@@ -40,6 +40,7 @@  Software Foundation; either version 3, o
 #include "explow.h"
 #include "expr.h"
 #include "langhooks.h"
+#include "tree-vector-builder.h"
 
 struct target_expmed default_target_expmed;
 #if SWITCHABLE_TARGET
@@ -5184,14 +5185,14 @@  make_tree (tree type, rtx x)
 	int i;
 
 	/* Build a tree with vector elements.  */
-	auto_vec<tree, 32> elts (units);
+	tree_vector_builder elts (type, units, 1);
 	for (i = 0; i < units; ++i)
 	  {
 	    rtx elt = CONST_VECTOR_ELT (x, i);
 	    elts.quick_push (make_tree (itype, elt));
 	  }
 
-	return build_vector (type, elts);
+	return elts.build ();
       }
 
     case PLUS:
Index: gcc/fold-const.c
===================================================================
--- gcc/fold-const.c	2017-12-06 14:46:14.129599986 +0000
+++ gcc/fold-const.c	2017-12-06 14:48:52.887162217 +0000
@@ -81,6 +81,7 @@  Software Foundation; either version 3, o
 #include "selftest.h"
 #include "stringpool.h"
 #include "attribs.h"
+#include "tree-vector-builder.h"
 
 /* Nonzero if we are folding constants inside an initializer; zero
    otherwise.  */
@@ -1507,7 +1508,7 @@  const_binop (enum tree_code code, tree t
 	gcc_assert (in_nelts == VECTOR_CST_NELTS (arg2)
 		    && out_nelts == TYPE_VECTOR_SUBPARTS (type));
 
-	auto_vec<tree, 32> elts (out_nelts);
+	tree_vector_builder elts (type, out_nelts, 1);
 	for (i = 0; i < out_nelts; i++)
 	  {
 	    tree elt = (i < in_nelts
@@ -1521,7 +1522,7 @@  const_binop (enum tree_code code, tree t
 	    elts.quick_push (elt);
 	  }
 
-	return build_vector (type, elts);
+	return elts.build ();
       }
 
     case VEC_WIDEN_MULT_LO_EXPR:
@@ -1548,7 +1549,7 @@  const_binop (enum tree_code code, tree t
 	else /* if (code == VEC_WIDEN_MULT_ODD_EXPR) */
 	  scale = 1, ofs = 1;
 
-	auto_vec<tree, 32> elts (out_nelts);
+	tree_vector_builder elts (type, out_nelts, 1);
 	for (out = 0; out < out_nelts; out++)
 	  {
 	    unsigned int in = (out << scale) + ofs;
@@ -1565,7 +1566,7 @@  const_binop (enum tree_code code, tree t
 	    elts.quick_push (elt);
 	  }
 
-	return build_vector (type, elts);
+	return elts.build ();
       }
 
     default:;
@@ -1704,7 +1705,7 @@  const_unop (enum tree_code code, tree ty
 	else
 	  subcode = FLOAT_EXPR;
 
-	auto_vec<tree, 32> elts (out_nelts);
+	tree_vector_builder elts (type, out_nelts, 1);
 	for (i = 0; i < out_nelts; i++)
 	  {
 	    tree elt = fold_convert_const (subcode, TREE_TYPE (type),
@@ -1714,7 +1715,7 @@  const_unop (enum tree_code code, tree ty
 	    elts.quick_push (elt);
 	  }
 
-	return build_vector (type, elts);
+	return elts.build ();
       }
 
     default:
@@ -7377,7 +7378,7 @@  native_interpret_vector (tree type, cons
   if (size * count > len)
     return NULL_TREE;
 
-  auto_vec<tree, 32> elements (count);
+  tree_vector_builder elements (type, count, 1);
   for (i = 0; i < count; ++i)
     {
       elem = native_interpret_expr (etype, ptr+(i*size), size);
@@ -7385,7 +7386,7 @@  native_interpret_vector (tree type, cons
 	return NULL_TREE;
       elements.quick_push (elem);
     }
-  return build_vector (type, elements);
+  return elements.build ();
 }
 
 
@@ -8755,7 +8756,7 @@  fold_vec_perm (tree type, tree arg0, tre
       || !vec_cst_ctor_to_array (arg1, nelts, in_elts + nelts))
     return NULL_TREE;
 
-  auto_vec<tree, 32> out_elts (nelts);
+  tree_vector_builder out_elts (type, nelts, 1);
   for (i = 0; i < nelts; i++)
     {
       if (!CONSTANT_CLASS_P (in_elts[sel[i]]))
@@ -8772,7 +8773,7 @@  fold_vec_perm (tree type, tree arg0, tre
       return build_constructor (type, v);
     }
   else
-    return build_vector (type, out_elts);
+    return out_elts.build ();
 }
 
 /* Try to fold a pointer difference of type TYPE two address expressions of
@@ -11426,10 +11427,10 @@  fold_ternary_loc (location_t loc, enum t
 		  if (n == 1)
 		    return VECTOR_CST_ELT (arg0, idx);
 
-		  auto_vec<tree, 32> vals (n);
+		  tree_vector_builder vals (type, n, 1);
 		  for (unsigned i = 0; i < n; ++i)
 		    vals.quick_push (VECTOR_CST_ELT (arg0, idx + i));
-		  return build_vector (type, vals);
+		  return vals.build ();
 		}
 	    }
 	}
@@ -11565,10 +11566,10 @@  fold_ternary_loc (location_t loc, enum t
 	  if (need_mask_canon && arg2 == op2)
 	    {
 	      tree eltype = TREE_TYPE (TREE_TYPE (arg2));
-	      auto_vec<tree, 32> tsel (nelts);
+	      tree_vector_builder tsel (TREE_TYPE (arg2), nelts, 1);
 	      for (i = 0; i < nelts; i++)
 		tsel.quick_push (build_int_cst (eltype, sel[i]));
-	      op2 = build_vector (TREE_TYPE (arg2), tsel);
+	      op2 = tsel.build ();
 	      changed = true;
 	    }
 
@@ -11608,11 +11609,11 @@  fold_ternary_loc (location_t loc, enum t
 	      else
 		{
 		  unsigned int nelts = VECTOR_CST_NELTS (arg0);
-		  auto_vec<tree, 32> elts (nelts);
+		  tree_vector_builder elts (type, nelts, 1);
 		  elts.quick_grow (nelts);
-		  for (unsigned int i = 0; i < VECTOR_CST_NELTS (arg0); ++i)
+		  for (unsigned int i = 0; i < nelts; ++i)
 		    elts[i] = (i == k ? arg1 : VECTOR_CST_ELT (arg0, i));
-		  return build_vector (type, elts);
+		  return elts.build ();
 		}
 	    }
 	}
Index: gcc/gimple-fold.c
===================================================================
--- gcc/gimple-fold.c	2017-12-05 14:24:56.014949665 +0000
+++ gcc/gimple-fold.c	2017-12-06 14:48:52.888162175 +0000
@@ -63,6 +63,7 @@  Free Software Foundation; either version
 #include "diagnostic-core.h"
 #include "intl.h"
 #include "calls.h"
+#include "tree-vector-builder.h"
 
 /* Return true when DECL can be referenced from current unit.
    FROM_DECL (if non-null) specify constructor of variable DECL was taken from.
@@ -6022,7 +6023,7 @@  gimple_fold_stmt_to_constant_1 (gimple *
 		  tree val;
 
 		  nelts = TYPE_VECTOR_SUBPARTS (TREE_TYPE (rhs));
-		  auto_vec<tree, 32> vec (nelts);
+		  tree_vector_builder vec (TREE_TYPE (rhs), nelts, 1);
 		  FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (rhs), i, val)
 		    {
 		      val = (*valueize) (val);
@@ -6034,7 +6035,7 @@  gimple_fold_stmt_to_constant_1 (gimple *
 			return NULL_TREE;
 		    }
 
-		  return build_vector (TREE_TYPE (rhs), vec);
+		  return vec.build ();
 		}
 	      if (subcode == OBJ_TYPE_REF)
 		{
Index: gcc/tree-ssa-forwprop.c
===================================================================
--- gcc/tree-ssa-forwprop.c	2017-11-29 11:06:31.942215941 +0000
+++ gcc/tree-ssa-forwprop.c	2017-12-06 14:48:52.888162175 +0000
@@ -46,6 +46,7 @@  the Free Software Foundation; either ver
 #include "tree-cfgcleanup.h"
 #include "cfganal.h"
 #include "optabs-tree.h"
+#include "tree-vector-builder.h"
 
 /* This pass propagates the RHS of assignment statements into use
    sites of the LHS of the assignment.  It's basically a specialized
@@ -2116,10 +2117,10 @@  simplify_vector_constructor (gimple_stmt
 	  || GET_MODE_SIZE (TYPE_MODE (mask_type))
 	     != GET_MODE_SIZE (TYPE_MODE (type)))
 	return false;
-      auto_vec<tree, 32> mask_elts (nelts);
+      tree_vector_builder mask_elts (mask_type, nelts, 1);
       for (i = 0; i < nelts; i++)
 	mask_elts.quick_push (build_int_cst (TREE_TYPE (mask_type), sel[i]));
-      op2 = build_vector (mask_type, mask_elts);
+      op2 = mask_elts.build ();
       if (conv_code == ERROR_MARK)
 	gimple_assign_set_rhs_with_ops (gsi, VEC_PERM_EXPR, orig, orig, op2);
       else
Index: gcc/tree-vect-generic.c
===================================================================
--- gcc/tree-vect-generic.c	2017-11-29 11:06:34.810688336 +0000
+++ gcc/tree-vect-generic.c	2017-12-06 14:48:52.889162134 +0000
@@ -37,6 +37,7 @@  Free Software Foundation; either version
 #include "gimplify-me.h"
 #include "gimplify.h"
 #include "tree-cfg.h"
+#include "tree-vector-builder.h"
 
 
 static void expand_vector_operations_1 (gimple_stmt_iterator *);
@@ -398,11 +399,10 @@  add_rshift (gimple_stmt_iterator *gsi, t
   if (op != unknown_optab
       && optab_handler (op, TYPE_MODE (type)) != CODE_FOR_nothing)
     {
-      auto_vec<tree, 32> vec (nunits);
+      tree_vector_builder vec (type, nunits, 1);
       for (i = 0; i < nunits; i++)
 	vec.quick_push (build_int_cst (TREE_TYPE (type), shiftcnts[i]));
-      return gimplify_build2 (gsi, RSHIFT_EXPR, type, op0,
-			      build_vector (type, vec));
+      return gimplify_build2 (gsi, RSHIFT_EXPR, type, op0, vec.build ());
     }
 
   return NULL_TREE;
@@ -635,12 +635,12 @@  expand_vector_divmod (gimple_stmt_iterat
 	      mask_type = build_same_sized_truth_vector_type (type);
 	      zero = build_zero_cst (type);
 	      cond = build2 (LT_EXPR, mask_type, op0, zero);
-	      auto_vec<tree, 32> vec (nunits);
+	      tree_vector_builder vec (type, nunits, 1);
 	      for (i = 0; i < nunits; i++)
 		vec.quick_push (build_int_cst (TREE_TYPE (type),
 					       (HOST_WIDE_INT_1U
 						<< shifts[i]) - 1));
-	      cst = build_vector (type, vec);
+	      cst = vec.build ();
 	      addend = make_ssa_name (type);
 	      stmt = gimple_build_assign (addend, VEC_COND_EXPR, cond,
 					  cst, zero);
@@ -674,12 +674,12 @@  expand_vector_divmod (gimple_stmt_iterat
       else
 	{
 	  tree mask;
-	  auto_vec<tree, 32> vec (nunits);
+	  tree_vector_builder vec (type, nunits, 1);
 	  for (i = 0; i < nunits; i++)
 	    vec.quick_push (build_int_cst (TREE_TYPE (type),
 					   (HOST_WIDE_INT_1U
 					    << shifts[i]) - 1));
-	  mask = build_vector (type, vec);
+	  mask = vec.build ();
 	  op = optab_for_tree_code (BIT_AND_EXPR, type, optab_default);
 	  if (op != unknown_optab
 	      && optab_handler (op, TYPE_MODE (type)) != CODE_FOR_nothing)
@@ -753,10 +753,10 @@  expand_vector_divmod (gimple_stmt_iterat
       return NULL_TREE;
     }
 
-  auto_vec<tree, 32> vec (nunits);
+  tree_vector_builder vec (type, nunits, 1);
   for (i = 0; i < nunits; i++)
     vec.quick_push (build_int_cst (TREE_TYPE (type), mulc[i]));
-  mulcst = build_vector (type, vec);
+  mulcst = vec.build ();
 
   cur_op = gimplify_build2 (gsi, MULT_HIGHPART_EXPR, type, cur_op, mulcst);
 
@@ -1104,7 +1104,7 @@  optimize_vector_constructor (gimple_stmt
       }
   if (all_same)
     return;
-  auto_vec<tree, 32> cst (nelts);
+  tree_vector_builder cst (type, nelts, 1);
   for (i = 0; i < nelts; i++)
     {
       tree this_base = CONSTRUCTOR_ELT (rhs, i)->value;
@@ -1127,7 +1127,7 @@  optimize_vector_constructor (gimple_stmt
   g = gimple_build_assign (make_ssa_name (type), rhs);
   gsi_insert_before (gsi, g, GSI_SAME_STMT);
   g = gimple_build_assign (lhs, PLUS_EXPR, gimple_assign_lhs (g),
-			   build_vector (type, cst));
+			   cst.build ());
   gsi_replace (gsi, g, false);
 }
 
Index: gcc/tree-vect-loop.c
===================================================================
--- gcc/tree-vect-loop.c	2017-11-29 11:06:34.910905236 +0000
+++ gcc/tree-vect-loop.c	2017-12-06 14:48:52.889162134 +0000
@@ -51,6 +51,7 @@  Software Foundation; either version 3, o
 #include "tree-cfg.h"
 #include "tree-if-conv.h"
 #include "internal-fn.h"
+#include "tree-vector-builder.h"
 
 /* Loop Vectorization Pass.
 
@@ -4497,10 +4498,10 @@  vect_create_epilog_for_reduction (vec<tr
 	 vector size (STEP).  */
 
       /* Create a {1,2,3,...} vector.  */
-      auto_vec<tree, 32> vtemp (nunits_out);
-      for (k = 0; k < nunits_out; ++k)
+      tree_vector_builder vtemp (cr_index_vector_type, 1, 3);
+      for (k = 0; k < 3; ++k)
 	vtemp.quick_push (build_int_cst (cr_index_scalar_type, k + 1));
-      tree series_vect = build_vector (cr_index_vector_type, vtemp);
+      tree series_vect = vtemp.build ();
 
       /* Create a vector of the step value.  */
       tree step = build_int_cst (cr_index_scalar_type, nunits_out);
Index: gcc/tree-vect-slp.c
===================================================================
--- gcc/tree-vect-slp.c	2017-12-05 14:24:56.178946625 +0000
+++ gcc/tree-vect-slp.c	2017-12-06 14:48:52.890162093 +0000
@@ -41,6 +41,7 @@  Software Foundation; either version 3, o
 #include "langhooks.h"
 #include "gimple-walk.h"
 #include "dbgcnt.h"
+#include "tree-vector-builder.h"
 
 
 /* Recursively free the memory allocated for the SLP tree rooted at NODE.  */
@@ -3222,7 +3223,7 @@  vect_get_constant_vectors (tree op, slp_
 
   number_of_places_left_in_vector = nunits;
   constant_p = true;
-  auto_vec<tree, 32> elts (nunits);
+  tree_vector_builder elts (vector_type, nunits, 1);
   elts.quick_grow (nunits);
   bool place_after_defs = false;
   for (j = 0; j < number_of_copies; j++)
@@ -3340,7 +3341,7 @@  vect_get_constant_vectors (tree op, slp_
           if (number_of_places_left_in_vector == 0)
             {
 	      if (constant_p)
-		vec_cst = build_vector (vector_type, elts);
+		vec_cst = elts.build ();
 	      else
 		{
 		  vec<constructor_elt, va_gc> *v;
@@ -3371,6 +3372,8 @@  vect_get_constant_vectors (tree op, slp_
 	      place_after_defs = false;
               number_of_places_left_in_vector = nunits;
 	      constant_p = true;
+	      elts.new_vector (vector_type, nunits, 1);
+	      elts.quick_grow (nunits);
             }
         }
     }
@@ -3667,11 +3670,11 @@  vect_transform_slp_perm_load (slp_tree n
 		  
 		  if (! noop_p)
 		    {
-		      auto_vec<tree, 32> mask_elts (nunits);
+		      tree_vector_builder mask_elts (mask_type, nunits, 1);
 		      for (int l = 0; l < nunits; ++l)
 			mask_elts.quick_push (build_int_cst (mask_element_type,
 							     mask[l]));
-		      mask_vec = build_vector (mask_type, mask_elts);
+		      mask_vec = mask_elts.build ();
 		    }
 
 		  if (second_vec_index == -1)
@@ -3823,7 +3826,7 @@  vect_schedule_slp_instance (slp_tree nod
 	  for (j = 0; j < v0.length (); ++j)
 	    {
 	      unsigned int nunits = TYPE_VECTOR_SUBPARTS (vectype);
-	      auto_vec<tree, 32> melts (nunits);
+	      tree_vector_builder melts (mvectype, nunits, 1);
 	      for (l = 0; l < nunits; ++l)
 		{
 		  if (k >= group_size)
@@ -3831,7 +3834,7 @@  vect_schedule_slp_instance (slp_tree nod
 		  tree t = build_int_cst (meltype, mask[k++] * nunits + l);
 		  melts.quick_push (t);
 		}
-	      tmask = build_vector (mvectype, melts);
+	      tmask = melts.build ();
 
 	      /* ???  Not all targets support a VEC_PERM_EXPR with a
 	         constant mask that would translate to a vec_merge RTX
Index: gcc/tree-vect-stmts.c
===================================================================
--- gcc/tree-vect-stmts.c	2017-11-29 11:06:29.970567408 +0000
+++ gcc/tree-vect-stmts.c	2017-12-06 14:48:52.890162093 +0000
@@ -48,6 +48,7 @@  Software Foundation; either version 3, o
 #include "tree-vectorizer.h"
 #include "builtins.h"
 #include "internal-fn.h"
+#include "tree-vector-builder.h"
 
 /* For lang_hooks.types.type_for_mode.  */
 #include "langhooks.h"
@@ -2520,10 +2521,10 @@  vectorizable_bswap (gimple *stmt, gimple
       return true;
     }
 
-  auto_vec<tree, 32> telts (num_bytes);
+  tree_vector_builder telts (char_vectype, num_bytes, 1);
   for (unsigned i = 0; i < num_bytes; ++i)
     telts.quick_push (build_int_cst (char_type_node, elts[i]));
-  tree bswap_vconst = build_vector (char_vectype, telts);
+  tree bswap_vconst = telts.build ();
 
   /* Transform.  */
   vec<tree> vec_oprnds = vNULL;
@@ -2941,11 +2942,11 @@  vectorizable_call (gimple *gs, gimple_st
 	  if (gimple_call_internal_p (stmt)
 	      && gimple_call_internal_fn (stmt) == IFN_GOMP_SIMD_LANE)
 	    {
-	      auto_vec<tree, 32> v (nunits_out);
-	      for (int k = 0; k < nunits_out; ++k)
+	      tree_vector_builder v (vectype_out, 1, 3);
+	      for (int k = 0; k < 3; ++k)
 		v.quick_push (build_int_cst (unsigned_type_node,
 					     j * nunits_out + k));
-	      tree cst = build_vector (vectype_out, v);
+	      tree cst = v.build ();
 	      tree new_var
 		= vect_get_new_ssa_name (vectype_out, vect_simple_var, "cst_");
 	      gimple *init_stmt = gimple_build_assign (new_var, cst);
@@ -6507,7 +6508,7 @@  vectorizable_store (gimple *stmt, gimple
 tree
 vect_gen_perm_mask_any (tree vectype, vec_perm_indices sel)
 {
-  tree mask_elt_type, mask_type, mask_vec;
+  tree mask_elt_type, mask_type;
 
   unsigned int nunits = sel.length ();
   gcc_checking_assert (nunits == TYPE_VECTOR_SUBPARTS (vectype));
@@ -6516,12 +6517,10 @@  vect_gen_perm_mask_any (tree vectype, ve
     (int_mode_for_mode (TYPE_MODE (TREE_TYPE (vectype))).require (), 1);
   mask_type = get_vectype_for_scalar_type (mask_elt_type);
 
-  auto_vec<tree, 32> mask_elts (nunits);
+  tree_vector_builder mask_elts (mask_type, nunits, 1);
   for (unsigned int i = 0; i < nunits; ++i)
     mask_elts.quick_push (build_int_cst (mask_elt_type, sel[i]));
-  mask_vec = build_vector (mask_type, mask_elts);
-
-  return mask_vec;
+  return mask_elts.build ();
 }
 
 /* Checked version of vect_gen_perm_mask_any.  Asserts can_vec_perm_p,
Index: gcc/tree.c
===================================================================
--- gcc/tree.c	2017-12-06 14:46:14.132599861 +0000
+++ gcc/tree.c	2017-12-06 14:48:52.891162052 +0000
@@ -1757,7 +1757,7 @@  build_vector_from_ctor (tree type, vec<c
   unsigned HOST_WIDE_INT idx;
   tree value;
 
-  auto_vec<tree, 32> vec (nelts);
+  tree_vector_builder vec (type, nelts, 1);
   FOR_EACH_CONSTRUCTOR_VALUE (v, idx, value)
     {
       if (TREE_CODE (value) == VECTOR_CST)
@@ -1769,7 +1769,7 @@  build_vector_from_ctor (tree type, vec<c
   while (vec.length () < nelts)
     vec.quick_push (build_zero_cst (TREE_TYPE (type)));
 
-  return build_vector (type, vec);
+  return vec.build ();
 }
 
 /* Build a vector of type VECTYPE where all the elements are SCs.  */
@@ -1792,10 +1792,9 @@  build_vector_from_val (tree vectype, tre
 
   if (CONSTANT_CLASS_P (sc))
     {
-      auto_vec<tree, 32> v (nunits);
-      for (i = 0; i < nunits; ++i)
-	v.quick_push (sc);
-      return build_vector (vectype, v);
+      tree_vector_builder v (vectype, 1, 1);
+      v.quick_push (sc);
+      return v.build ();
     }
   else
     {