This patch replaces vec_info::vector_size with vec_info::vector_mode,
but for now continues to use it as a way of specifying a single
vector size.  This makes it easier for later patches to use
related_vector_mode instead.


2019-10-24  Richard Sandiford  <richard.sandif...@arm.com>

gcc/
        * tree-vectorizer.h (vec_info::vector_size): Replace with...
        (vec_info::vector_mode): ...this new field.
        * tree-vect-loop.c (vect_update_vf_for_slp): Update accordingly.
        (vect_analyze_loop, vect_transform_loop): Likewise.
        * tree-vect-slp.c (can_duplicate_and_interleave_p): Likewise.
        (vect_make_slp_decision, vect_slp_bb_region): Likewise.
        * tree-vect-stmts.c (get_vectype_for_scalar_type): Likewise.
        * tree-vectorizer.c (try_vectorize_loop_1): Likewise.

gcc/testsuite/
        * gcc.dg/vect/vect-tail-nomask-1.c: Update expected epilogue
        vectorization message.

Index: gcc/tree-vectorizer.h
===================================================================
--- gcc/tree-vectorizer.h       2019-10-25 13:26:59.093879082 +0100
+++ gcc/tree-vectorizer.h       2019-10-25 13:27:19.317736181 +0100
@@ -329,9 +329,9 @@ typedef std::pair<tree, tree> vec_object
   /* Cost data used by the target cost model.  */
   void *target_cost_data;
 
-  /* The vector size for this loop in bytes, or 0 if we haven't picked
-     a size yet.  */
-  poly_uint64 vector_size;
+  /* If we've chosen a vector size for this vectorization region,
+     this is one mode that has such a size, otherwise it is VOIDmode.  */
+  machine_mode vector_mode;
 
 private:
   stmt_vec_info new_stmt_vec_info (gimple *stmt);
Index: gcc/tree-vect-loop.c
===================================================================
--- gcc/tree-vect-loop.c        2019-10-25 13:27:15.525762975 +0100
+++ gcc/tree-vect-loop.c        2019-10-25 13:27:19.309736237 +0100
@@ -1414,8 +1414,8 @@ vect_update_vf_for_slp (loop_vec_info lo
        dump_printf_loc (MSG_NOTE, vect_location,
                         "Loop contains SLP and non-SLP stmts\n");
       /* Both the vectorization factor and unroll factor have the form
-        loop_vinfo->vector_size * X for some rational X, so they must have
-        a common multiple.  */
+        GET_MODE_SIZE (loop_vinfo->vector_mode) * X for some rational X,
+        so they must have a common multiple.  */
       vectorization_factor
        = force_common_multiple (vectorization_factor,
                                 LOOP_VINFO_SLP_UNROLLING_FACTOR (loop_vinfo));
@@ -2341,7 +2341,7 @@ vect_analyze_loop (class loop *loop, loo
        " loops cannot be vectorized\n");
 
   unsigned n_stmts = 0;
-  poly_uint64 autodetected_vector_size = 0;
+  machine_mode autodetected_vector_mode = VOIDmode;
   opt_loop_vec_info first_loop_vinfo = opt_loop_vec_info::success (NULL);
   machine_mode next_vector_mode = VOIDmode;
   while (1)
@@ -2357,7 +2357,7 @@ vect_analyze_loop (class loop *loop, loo
          gcc_checking_assert (first_loop_vinfo == NULL);
          return loop_vinfo;
        }
-      loop_vinfo->vector_size = GET_MODE_SIZE (next_vector_mode);
+      loop_vinfo->vector_mode = next_vector_mode;
 
       bool fatal = false;
 
@@ -2366,7 +2366,7 @@ vect_analyze_loop (class loop *loop, loo
 
       opt_result res = vect_analyze_loop_2 (loop_vinfo, fatal, &n_stmts);
       if (mode_i == 0)
-       autodetected_vector_size = loop_vinfo->vector_size;
+       autodetected_vector_mode = loop_vinfo->vector_mode;
 
       if (res)
        {
@@ -2401,21 +2401,21 @@ vect_analyze_loop (class loop *loop, loo
 
       if (mode_i < vector_modes.length ()
          && known_eq (GET_MODE_SIZE (vector_modes[mode_i]),
-                      autodetected_vector_size))
+                      GET_MODE_SIZE (autodetected_vector_mode)))
        mode_i += 1;
 
       if (mode_i == vector_modes.length ()
-         || known_eq (autodetected_vector_size, 0U))
+         || autodetected_vector_mode == VOIDmode)
        {
          if (first_loop_vinfo)
            {
              loop->aux = (loop_vec_info) first_loop_vinfo;
              if (dump_enabled_p ())
                {
+                 machine_mode mode = first_loop_vinfo->vector_mode;
                  dump_printf_loc (MSG_NOTE, vect_location,
-                                  "***** Choosing vector size ");
-                 dump_dec (MSG_NOTE, first_loop_vinfo->vector_size);
-                 dump_printf (MSG_NOTE, "\n");
+                                  "***** Choosing vector mode %s\n",
+                                  GET_MODE_NAME (mode));
                }
              return first_loop_vinfo;
            }
@@ -8238,12 +8238,9 @@ vect_transform_loop (loop_vec_info loop_
          dump_printf (MSG_NOTE, "\n");
        }
       else
-       {
-         dump_printf_loc (MSG_NOTE, vect_location,
-                          "LOOP EPILOGUE VECTORIZED (VS=");
-         dump_dec (MSG_NOTE, loop_vinfo->vector_size);
-         dump_printf (MSG_NOTE, ")\n");
-       }
+       dump_printf_loc (MSG_NOTE, vect_location,
+                        "LOOP EPILOGUE VECTORIZED (MODE=%s)\n",
+                        GET_MODE_NAME (loop_vinfo->vector_mode));
     }
 
   /* Loops vectorized with a variable factor won't benefit from
@@ -8294,14 +8291,14 @@ vect_transform_loop (loop_vec_info loop_
          unsigned int ratio;
          while (next_i < vector_modes.length ()
                 && !(constant_multiple_p
-                     (loop_vinfo->vector_size,
+                     (GET_MODE_SIZE (loop_vinfo->vector_mode),
                       GET_MODE_SIZE (vector_modes[next_i]), &ratio)
                      && eiters >= lowest_vf / ratio))
            next_i += 1;
        }
       else
        while (next_i < vector_modes.length ()
-              && maybe_lt (loop_vinfo->vector_size,
+              && maybe_lt (GET_MODE_SIZE (loop_vinfo->vector_mode),
                            GET_MODE_SIZE (vector_modes[next_i])))
          next_i += 1;
 
Index: gcc/tree-vect-slp.c
===================================================================
--- gcc/tree-vect-slp.c 2019-10-25 13:27:15.525762975 +0100
+++ gcc/tree-vect-slp.c 2019-10-25 13:27:19.313736209 +0100
@@ -274,7 +274,7 @@ can_duplicate_and_interleave_p (vec_info
     {
       scalar_int_mode int_mode;
       poly_int64 elt_bits = elt_bytes * BITS_PER_UNIT;
-      if (multiple_p (vinfo->vector_size, elt_bytes, &nelts)
+      if (multiple_p (GET_MODE_SIZE (vinfo->vector_mode), elt_bytes, &nelts)
          && int_mode_for_size (elt_bits, 0).exists (&int_mode))
        {
          tree int_type = build_nonstandard_integer_type
@@ -474,7 +474,7 @@ vect_get_and_check_slp_defs (vec_info *v
            }
          if ((dt == vect_constant_def
               || dt == vect_external_def)
-             && !vinfo->vector_size.is_constant ()
+             && !GET_MODE_SIZE (vinfo->vector_mode).is_constant ()
              && (TREE_CODE (type) == BOOLEAN_TYPE
                  || !can_duplicate_and_interleave_p (vinfo, stmts.length (),
                                                      TYPE_MODE (type))))
@@ -2339,8 +2339,11 @@ vect_make_slp_decision (loop_vec_info lo
   FOR_EACH_VEC_ELT (slp_instances, i, instance)
     {
       /* FORNOW: SLP if you can.  */
-      /* All unroll factors have the form vinfo->vector_size * X for some
-        rational X, so they must have a common multiple.  */
+      /* All unroll factors have the form:
+
+          GET_MODE_SIZE (vinfo->vector_mode) * X
+
+        for some rational X, so they must have a common multiple.  */
       unrolling_factor
        = force_common_multiple (unrolling_factor,
                                 SLP_INSTANCE_UNROLLING_FACTOR (instance));
@@ -3096,7 +3099,7 @@ vect_slp_bb_region (gimple_stmt_iterator
 
   vec_info_shared shared;
 
-  poly_uint64 autodetected_vector_size = 0;
+  machine_mode autodetected_vector_mode = VOIDmode;
   while (1)
     {
       bool vectorized = false;
@@ -3109,7 +3112,7 @@ vect_slp_bb_region (gimple_stmt_iterator
        bb_vinfo->shared->save_datarefs ();
       else
        bb_vinfo->shared->check_datarefs ();
-      bb_vinfo->vector_size = GET_MODE_SIZE (next_vector_mode);
+      bb_vinfo->vector_mode = next_vector_mode;
 
       if (vect_slp_analyze_bb_1 (bb_vinfo, n_stmts, fatal)
          && dbg_cnt (vect_slp))
@@ -3123,7 +3126,7 @@ vect_slp_bb_region (gimple_stmt_iterator
          unsigned HOST_WIDE_INT bytes;
          if (dump_enabled_p ())
            {
-             if (bb_vinfo->vector_size.is_constant (&bytes))
+             if (GET_MODE_SIZE (bb_vinfo->vector_mode).is_constant (&bytes))
                dump_printf_loc (MSG_OPTIMIZED_LOCATIONS, vect_location,
                                 "basic block part vectorized using %wu byte "
                                 "vectors\n", bytes);
@@ -3137,18 +3140,18 @@ vect_slp_bb_region (gimple_stmt_iterator
        }
 
       if (mode_i == 0)
-       autodetected_vector_size = bb_vinfo->vector_size;
+       autodetected_vector_mode = bb_vinfo->vector_mode;
 
       delete bb_vinfo;
 
       if (mode_i < vector_modes.length ()
          && known_eq (GET_MODE_SIZE (vector_modes[mode_i]),
-                      autodetected_vector_size))
+                      GET_MODE_SIZE (autodetected_vector_mode)))
        mode_i += 1;
 
       if (vectorized
          || mode_i == vector_modes.length ()
-         || known_eq (autodetected_vector_size, 0U)
+         || autodetected_vector_mode == VOIDmode
          /* If vect_slp_analyze_bb_1 signaled that analysis for all
             vector sizes will fail do not bother iterating.  */
          || fatal)
Index: gcc/tree-vect-stmts.c
===================================================================
--- gcc/tree-vect-stmts.c       2019-10-25 13:27:12.121787027 +0100
+++ gcc/tree-vect-stmts.c       2019-10-25 13:27:19.313736209 +0100
@@ -11212,11 +11212,10 @@ get_vectype_for_scalar_type_and_size (tr
 get_vectype_for_scalar_type (vec_info *vinfo, tree scalar_type)
 {
   tree vectype;
-  vectype = get_vectype_for_scalar_type_and_size (scalar_type,
-                                                 vinfo->vector_size);
-  if (vectype
-      && known_eq (vinfo->vector_size, 0U))
-    vinfo->vector_size = GET_MODE_SIZE (TYPE_MODE (vectype));
+  poly_uint64 vector_size = GET_MODE_SIZE (vinfo->vector_mode);
+  vectype = get_vectype_for_scalar_type_and_size (scalar_type, vector_size);
+  if (vectype && vinfo->vector_mode == VOIDmode)
+    vinfo->vector_mode = TYPE_MODE (vectype);
   return vectype;
 }
 
Index: gcc/tree-vectorizer.c
===================================================================
--- gcc/tree-vectorizer.c       2019-10-21 07:41:32.997886232 +0100
+++ gcc/tree-vectorizer.c       2019-10-25 13:27:19.317736181 +0100
@@ -971,7 +971,7 @@ try_vectorize_loop_1 (hash_table<simduid
   unsigned HOST_WIDE_INT bytes;
   if (dump_enabled_p ())
     {
-      if (loop_vinfo->vector_size.is_constant (&bytes))
+      if (GET_MODE_SIZE (loop_vinfo->vector_mode).is_constant (&bytes))
        dump_printf_loc (MSG_OPTIMIZED_LOCATIONS, vect_location,
                         "loop vectorized using %wu byte vectors\n", bytes);
       else
Index: gcc/testsuite/gcc.dg/vect/vect-tail-nomask-1.c
===================================================================
--- gcc/testsuite/gcc.dg/vect/vect-tail-nomask-1.c      2019-03-08 
18:15:02.260871260 +0000
+++ gcc/testsuite/gcc.dg/vect/vect-tail-nomask-1.c      2019-10-25 
13:27:19.309736237 +0100
@@ -106,4 +106,4 @@ main (int argc, const char **argv)
 }
 
 /* { dg-final { scan-tree-dump-times "LOOP VECTORIZED" 2 "vect" { target 
avx2_runtime } } } */
-/* { dg-final { scan-tree-dump-times "LOOP EPILOGUE VECTORIZED \\(VS=16\\)" 2 
"vect" { target avx2_runtime } } } */
+/* { dg-final { scan-tree-dump-times "LOOP EPILOGUE VECTORIZED 
\\(MODE=V16QI\\)" 2 "vect" { target avx2_runtime } } } */

Reply via email to