Some callers of get_same_sized_vectype were dealing with operands that
are constant or defined externally, and so have no STMT_VINFO_VECTYPE
available.  Under the current model, using get_same_sized_vectype for
that case is equivalent to using get_vectype_for_scalar_type, since
get_vectype_for_scalar_type always returns vectors of the same size,
once a size is fixed.

Using get_vectype_for_scalar_type is arguably more obvious though:
if we're using the same scalar type as we would for internal
definitions, we should use the same vector type too.  (Constant and
external definitions sometimes let us change the original scalar type
to a "nicer" scalar type, but that isn't what's happening here.)

This is a prerequisite to supporting multiple vector sizes in the same
vec_info.


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

gcc/
        * tree-vect-stmts.c (vectorizable_call): If an operand is
        constant or external, use get_vectype_for_scalar_type
        rather than get_same_sized_vectype to get its vector type.
        (vectorizable_conversion, vectorizable_shift): Likewise.
        (vectorizable_operation): Likewise.

Index: gcc/tree-vect-stmts.c
===================================================================
--- gcc/tree-vect-stmts.c       2019-10-25 13:27:19.313736209 +0100
+++ gcc/tree-vect-stmts.c       2019-10-25 13:27:22.985710263 +0100
@@ -3308,10 +3308,10 @@ vectorizable_call (stmt_vec_info stmt_in
          return false;
        }
     }
-  /* If all arguments are external or constant defs use a vector type with
-     the same size as the output vector type.  */
+  /* If all arguments are external or constant defs, infer the vector type
+     from the scalar type.  */
   if (!vectype_in)
-    vectype_in = get_same_sized_vectype (rhs_type, vectype_out);
+    vectype_in = get_vectype_for_scalar_type (vinfo, rhs_type);
   if (vec_stmt)
     gcc_assert (vectype_in);
   if (!vectype_in)
@@ -4800,10 +4800,10 @@ vectorizable_conversion (stmt_vec_info s
        }
     }
 
-  /* If op0 is an external or constant defs use a vector type of
-     the same size as the output vector type.  */
+  /* If op0 is an external or constant def, infer the vector type
+     from the scalar type.  */
   if (!vectype_in)
-    vectype_in = get_same_sized_vectype (rhs_type, vectype_out);
+    vectype_in = get_vectype_for_scalar_type (vinfo, rhs_type);
   if (vec_stmt)
     gcc_assert (vectype_in);
   if (!vectype_in)
@@ -5564,10 +5564,10 @@ vectorizable_shift (stmt_vec_info stmt_i
                          "use not simple.\n");
       return false;
     }
-  /* If op0 is an external or constant def use a vector type with
-     the same size as the output vector type.  */
+  /* If op0 is an external or constant def, infer the vector type
+     from the scalar type.  */
   if (!vectype)
-    vectype = get_same_sized_vectype (TREE_TYPE (op0), vectype_out);
+    vectype = get_vectype_for_scalar_type (vinfo, TREE_TYPE (op0));
   if (vec_stmt)
     gcc_assert (vectype);
   if (!vectype)
@@ -5666,7 +5666,7 @@ vectorizable_shift (stmt_vec_info stmt_i
                          "vector/vector shift/rotate found.\n");
 
       if (!op1_vectype)
-       op1_vectype = get_same_sized_vectype (TREE_TYPE (op1), vectype_out);
+       op1_vectype = get_vectype_for_scalar_type (vinfo, TREE_TYPE (op1));
       incompatible_op1_vectype_p
        = (op1_vectype == NULL_TREE
           || maybe_ne (TYPE_VECTOR_SUBPARTS (op1_vectype),
@@ -5997,8 +5997,8 @@ vectorizable_operation (stmt_vec_info st
                          "use not simple.\n");
       return false;
     }
-  /* If op0 is an external or constant def use a vector type with
-     the same size as the output vector type.  */
+  /* If op0 is an external or constant def, infer the vector type
+     from the scalar type.  */
   if (!vectype)
     {
       /* For boolean type we cannot determine vectype by
@@ -6018,7 +6018,7 @@ vectorizable_operation (stmt_vec_info st
          vectype = vectype_out;
        }
       else
-       vectype = get_same_sized_vectype (TREE_TYPE (op0), vectype_out);
+       vectype = get_vectype_for_scalar_type (vinfo, TREE_TYPE (op0));
     }
   if (vec_stmt)
     gcc_assert (vectype);

Reply via email to