Noticed during the VECTOR_CST representation change.

Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk.

Richard.

2012-03-16  Richard Guenther  <rguent...@suse.de>

        * tree-vect-loop.c (get_initial_def_for_induction): Use
        build_constructor directly.
        * tree-vect-stmts.c (vect_get_vec_def_for_operand): Use
        build_vector_from_val.
        * tree.c (build_vector_from_val): Avoid creating a constructor
        first when we want a constant vector.

Index: trunk/gcc/tree-vect-loop.c
===================================================================
*** trunk.orig/gcc/tree-vect-loop.c     2012-03-15 14:55:24.000000000 +0100
--- trunk/gcc/tree-vect-loop.c  2012-03-15 14:55:47.000000000 +0100
*************** get_initial_def_for_induction (gimple iv
*** 3041,3046 ****
--- 3041,3048 ----
      }
    else
      {
+       VEC(constructor_elt,gc) *v;
+ 
        /* iv_loop is the loop to be vectorized. Create:
         vec_init = [X, X+S, X+2*S, X+3*S] (S = step_expr, X = init_expr)  */
        new_var = vect_get_new_vect_var (scalar_type, vect_scalar_var, "var_");
*************** get_initial_def_for_induction (gimple iv
*** 3053,3060 ****
          gcc_assert (!new_bb);
        }
  
!       t = NULL_TREE;
!       t = tree_cons (NULL_TREE, new_name, t);
        for (i = 1; i < nunits; i++)
        {
          /* Create: new_name_i = new_name + step_expr  */
--- 3055,3062 ----
          gcc_assert (!new_bb);
        }
  
!       v = VEC_alloc (constructor_elt, gc, nunits);
!       CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, new_name);
        for (i = 1; i < nunits; i++)
        {
          /* Create: new_name_i = new_name + step_expr  */
*************** get_initial_def_for_induction (gimple iv
*** 3073,3082 ****
              fprintf (vect_dump, "created new init_stmt: ");
              print_gimple_stmt (vect_dump, init_stmt, 0, TDF_SLIM);
            }
!         t = tree_cons (NULL_TREE, new_name, t);
        }
        /* Create a vector from [new_name_0, new_name_1, ..., 
new_name_nunits-1]  */
!       vec = build_constructor_from_list (vectype, nreverse (t));
        vec_init = vect_init_vector (iv_phi, vec, vectype, NULL);
      }
  
--- 3075,3084 ----
              fprintf (vect_dump, "created new init_stmt: ");
              print_gimple_stmt (vect_dump, init_stmt, 0, TDF_SLIM);
            }
!         CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, new_name);
        }
        /* Create a vector from [new_name_0, new_name_1, ..., 
new_name_nunits-1]  */
!       vec = build_constructor (vectype, v);
        vec_init = vect_init_vector (iv_phi, vec, vectype, NULL);
      }
  
Index: trunk/gcc/tree-vect-stmts.c
===================================================================
*** trunk.orig/gcc/tree-vect-stmts.c    2012-03-15 14:55:24.000000000 +0100
--- trunk/gcc/tree-vect-stmts.c 2012-03-15 14:55:47.000000000 +0100
*************** vect_get_vec_def_for_operand (tree op, g
*** 1227,1235 ****
    loop_vec_info loop_vinfo = STMT_VINFO_LOOP_VINFO (stmt_vinfo);
    tree vec_inv;
    tree vec_cst;
-   tree t = NULL_TREE;
    tree def;
-   int i;
    enum vect_def_type dt;
    bool is_simple_use;
    tree vector_type;
--- 1227,1233 ----
*************** vect_get_vec_def_for_operand (tree op, g
*** 1284,1290 ****
        {
        vector_type = get_vectype_for_scalar_type (TREE_TYPE (def));
        gcc_assert (vector_type);
-       nunits = TYPE_VECTOR_SUBPARTS (vector_type);
  
        if (scalar_def)
          *scalar_def = def;
--- 1282,1287 ----
*************** vect_get_vec_def_for_operand (tree op, g
*** 1293,1305 ****
          if (vect_print_dump_info (REPORT_DETAILS))
            fprintf (vect_dump, "Create vector_inv.");
  
!         for (i = nunits - 1; i >= 0; --i)
!           {
!             t = tree_cons (NULL_TREE, def, t);
!           }
! 
!       /* FIXME: use build_constructor directly.  */
!         vec_inv = build_constructor_from_list (vector_type, t);
          return vect_init_vector (stmt, vec_inv, vector_type, NULL);
        }
  
--- 1290,1296 ----
          if (vect_print_dump_info (REPORT_DETAILS))
            fprintf (vect_dump, "Create vector_inv.");
  
!       vec_inv = build_vector_from_val (vector_type, def);
          return vect_init_vector (stmt, vec_inv, vector_type, NULL);
        }
  
Index: trunk/gcc/tree.c
===================================================================
*** trunk.orig/gcc/tree.c       2012-03-15 14:55:24.000000000 +0100
--- trunk/gcc/tree.c    2012-03-15 14:58:12.000000000 +0100
*************** tree
*** 1372,1378 ****
  build_vector_from_val (tree vectype, tree sc) 
  {
    int i, nunits = TYPE_VECTOR_SUBPARTS (vectype);
-   VEC(constructor_elt, gc) *v = NULL;
  
    if (sc == error_mark_node)
      return sc;
--- 1372,1377 ----
*************** build_vector_from_val (tree vectype, tre
*** 1386,1399 ****
    gcc_checking_assert (types_compatible_p (TYPE_MAIN_VARIANT (TREE_TYPE (sc)),
                                           TREE_TYPE (vectype)));
  
-   v = VEC_alloc (constructor_elt, gc, nunits);
-   for (i = 0; i < nunits; ++i)
-     CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, sc);
- 
    if (CONSTANT_CLASS_P (sc))
!     return build_vector_from_ctor (vectype, v);
!   else 
!     return build_constructor (vectype, v);
  }
  
  /* Return a new CONSTRUCTOR node whose type is TYPE and whose values
--- 1385,1404 ----
    gcc_checking_assert (types_compatible_p (TYPE_MAIN_VARIANT (TREE_TYPE (sc)),
                                           TREE_TYPE (vectype)));
  
    if (CONSTANT_CLASS_P (sc))
!     {
!       tree *v = XALLOCAVEC (tree, nunits);
!       for (i = 0; i < nunits; ++i)
!       v[i] = sc;
!       return build_vector (vectype, v);
!     }
!   else
!     {
!       VEC(constructor_elt, gc) *v = VEC_alloc (constructor_elt, gc, nunits);
!       for (i = 0; i < nunits; ++i)
!       CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, sc);
!       return build_constructor (vectype, v);
!     }
  }
  
  /* Return a new CONSTRUCTOR node whose type is TYPE and whose values

Reply via email to