Remove build_{same_sized_,}truth_vector_type
authorRichard Sandiford <richard.sandiford@arm.com>
Thu, 14 Nov 2019 14:49:36 +0000 (14:49 +0000)
committerRichard Sandiford <rsandifo@gcc.gnu.org>
Thu, 14 Nov 2019 14:49:36 +0000 (14:49 +0000)
build_same_sized_truth_vector_type was confusingly named, since for
SVE and AVX512 the returned vector isn't the same byte size (although
it does have the same number of elements).  What it really returns
is the "truth" vector type for a given data vector type.

The more general truth_type_for provides the same thing when passed
a vector and IMO has a more descriptive name, so this patch replaces
all uses of build_same_sized_truth_vector_type with that.  It does
the same for a call to build_truth_vector_type, leaving truth_type_for
itself as the only remaining caller.

It's then more natural to pass build_truth_vector_type the original
vector type rather than its size and nunits, especially since the
given size isn't the size of the returned vector.  This in turn allows
a future patch to simplify the interface of get_mask_mode.  Doing this
also fixes a bug in which truth_type_for would pass a size of zero for
BLKmode vector types.

2019-11-14  Richard Sandiford  <richard.sandiford@arm.com>

gcc/
* tree.h (build_truth_vector_type): Delete.
(build_same_sized_truth_vector_type): Likewise.
* tree.c (build_truth_vector_type): Rename to...
(build_truth_vector_type_for): ...this.  Make static and take
a vector type as argument.
(truth_type_for): Update accordingly.
(build_same_sized_truth_vector_type): Delete.
* tree-vect-generic.c (expand_vector_divmod): Use truth_type_for
instead of build_same_sized_truth_vector_type.
* tree-vect-loop.c (vect_create_epilog_for_reduction): Likewise.
(vect_record_loop_mask, vect_get_loop_mask): Likewise.
* tree-vect-patterns.c (build_mask_conversion): Likeise.
* tree-vect-slp.c (vect_get_constant_vectors): Likewise.
* tree-vect-stmts.c (vect_get_vec_def_for_operand): Likewise.
(vect_build_gather_load_calls, vectorizable_call): Likewise.
(scan_store_can_perm_p, vectorizable_scan_store): Likewise.
(vectorizable_store, vectorizable_condition): Likewise.
(get_mask_type_for_scalar_type, get_same_sized_vectype): Likewise.
(vect_get_mask_type_for_stmt): Use truth_type_for instead of
build_truth_vector_type.
* config/aarch64/aarch64-sve-builtins.cc (gimple_folder::convert_pred):
Use truth_type_for instead of build_same_sized_truth_vector_type.
* config/rs6000/rs6000-call.c (fold_build_vec_cmp): Likewise.

gcc/c/
* c-typeck.c (build_conditional_expr): Use truth_type_for instead
of build_same_sized_truth_vector_type.
(build_vec_cmp): Likewise.

gcc/cp/
* call.c (build_conditional_expr_1): Use truth_type_for instead
of build_same_sized_truth_vector_type.
* typeck.c (build_vec_cmp): Likewise.

gcc/d/
* d-codegen.cc (build_boolop): Use truth_type_for instead of
build_same_sized_truth_vector_type.

From-SVN: r278232

17 files changed:
gcc/ChangeLog
gcc/c/ChangeLog
gcc/c/c-typeck.c
gcc/config/aarch64/aarch64-sve-builtins.cc
gcc/config/rs6000/rs6000-call.c
gcc/cp/ChangeLog
gcc/cp/call.c
gcc/cp/typeck.c
gcc/d/ChangeLog
gcc/d/d-codegen.cc
gcc/tree-vect-generic.c
gcc/tree-vect-loop.c
gcc/tree-vect-patterns.c
gcc/tree-vect-slp.c
gcc/tree-vect-stmts.c
gcc/tree.c
gcc/tree.h

index 79c8042b46e25354773e62209d334de98ff8258f..2b307b70e63ee0e398e1ef5139172ef1b1d48996 100644 (file)
@@ -1,3 +1,29 @@
+2019-11-14  Richard Sandiford  <richard.sandiford@arm.com>
+
+       * tree.h (build_truth_vector_type): Delete.
+       (build_same_sized_truth_vector_type): Likewise.
+       * tree.c (build_truth_vector_type): Rename to...
+       (build_truth_vector_type_for): ...this.  Make static and take
+       a vector type as argument.
+       (truth_type_for): Update accordingly.
+       (build_same_sized_truth_vector_type): Delete.
+       * tree-vect-generic.c (expand_vector_divmod): Use truth_type_for
+       instead of build_same_sized_truth_vector_type.
+       * tree-vect-loop.c (vect_create_epilog_for_reduction): Likewise.
+       (vect_record_loop_mask, vect_get_loop_mask): Likewise.
+       * tree-vect-patterns.c (build_mask_conversion): Likeise.
+       * tree-vect-slp.c (vect_get_constant_vectors): Likewise.
+       * tree-vect-stmts.c (vect_get_vec_def_for_operand): Likewise.
+       (vect_build_gather_load_calls, vectorizable_call): Likewise.
+       (scan_store_can_perm_p, vectorizable_scan_store): Likewise.
+       (vectorizable_store, vectorizable_condition): Likewise.
+       (get_mask_type_for_scalar_type, get_same_sized_vectype): Likewise.
+       (vect_get_mask_type_for_stmt): Use truth_type_for instead of
+       build_truth_vector_type.
+       * config/aarch64/aarch64-sve-builtins.cc (gimple_folder::convert_pred):
+       Use truth_type_for instead of build_same_sized_truth_vector_type.
+       * config/rs6000/rs6000-call.c (fold_build_vec_cmp): Likewise.
+
 2019-11-14  Richard Sandiford  <richard.sandiford@arm.com>
 
        * tree.h (build_truth_vector_type_for_mode): Declare.
index c19cf2fae3292527253c71f1c8a1af6e43c552ea..04dce4b45ceab01259a33957925ce2d2ed8b0cca 100644 (file)
@@ -1,3 +1,9 @@
+2019-11-14  Richard Sandiford  <richard.sandiford@arm.com>
+
+       * c-typeck.c (build_conditional_expr): Use truth_type_for instead
+       of build_same_sized_truth_vector_type.
+       (build_vec_cmp): Likewise.
+
 2019-11-14  Jakub Jelinek  <jakub@redhat.com>
 
        * c-parser.c (c_parser_omp_context_selector): Don't require score
index 793d10e072ba147509648ed5339e18499fbc1542..5f74a3b28d90851b4bde40d43a7eb27e101555e6 100644 (file)
@@ -5431,7 +5431,7 @@ build_conditional_expr (location_t colon_loc, tree ifexp, bool ifexp_bcp,
       tree elem_type = TREE_TYPE (vectype);
       tree zero = build_int_cst (elem_type, 0);
       tree zero_vec = build_vector_from_val (vectype, zero);
-      tree cmp_type = build_same_sized_truth_vector_type (vectype);
+      tree cmp_type = truth_type_for (vectype);
       ifexp = build2 (NE_EXPR, cmp_type, ifexp, zero_vec);
     }
 
@@ -11340,7 +11340,7 @@ build_vec_cmp (tree_code code, tree type,
 {
   tree zero_vec = build_zero_cst (type);
   tree minus_one_vec = build_minus_one_cst (type);
-  tree cmp_type = build_same_sized_truth_vector_type (type);
+  tree cmp_type = truth_type_for (type);
   tree cmp = build2 (code, cmp_type, arg0, arg1);
   return build3 (VEC_COND_EXPR, type, cmp, minus_one_vec, zero_vec);
 }
index 2dc2cea875bbaf65779bfaa10de1fc983131465f..63d903d0a1effbf74586876710ecb194e5a4b403 100644 (file)
@@ -2240,7 +2240,7 @@ tree
 gimple_folder::convert_pred (gimple_seq &stmts, tree vectype,
                             unsigned int argno)
 {
-  tree predtype = build_same_sized_truth_vector_type (vectype);
+  tree predtype = truth_type_for (vectype);
   tree pred = gimple_call_arg (call, argno);
   return gimple_build (&stmts, VIEW_CONVERT_EXPR, predtype, pred);
 }
index 7280a4ed9c86fe6e38baae271d71189a28b6d44b..00ba74551b3ad8e8d1c644f34c8a7c4035e284f3 100644 (file)
@@ -5195,7 +5195,7 @@ static tree
 fold_build_vec_cmp (tree_code code, tree type,
                    tree arg0, tree arg1)
 {
-  tree cmp_type = build_same_sized_truth_vector_type (type);
+  tree cmp_type = truth_type_for (type);
   tree zero_vec = build_zero_cst (type);
   tree minus_one_vec = build_minus_one_cst (type);
   tree cmp = fold_build2 (code, cmp_type, arg0, arg1);
index c836859a6f516b2a7584718ca3f8e35faf2c1bc5..f45b59b80613105acd4d0dc35e42304096a83434 100644 (file)
@@ -1,3 +1,9 @@
+2019-11-14  Richard Sandiford  <richard.sandiford@arm.com>
+
+       * call.c (build_conditional_expr_1): Use truth_type_for instead
+       of build_same_sized_truth_vector_type.
+       * typeck.c (build_vec_cmp): Likewise.
+
 2019-11-14  Jakub Jelinek  <jakub@redhat.com>
 
        * parser.c (cp_parser_omp_context_selector): Don't require score
index 0034c1cee0da8e5061813438007d86e742952bab..e9ab30d9e13ed941cf6632634f32d3a3f8339760 100644 (file)
@@ -5198,7 +5198,7 @@ build_conditional_expr_1 (const op_location_t &loc,
 
       if (!COMPARISON_CLASS_P (arg1))
        {
-         tree cmp_type = build_same_sized_truth_vector_type (arg1_type);
+         tree cmp_type = truth_type_for (arg1_type);
          arg1 = build2 (NE_EXPR, cmp_type, arg1, build_zero_cst (arg1_type));
        }
       return build3_loc (loc, VEC_COND_EXPR, arg2_type, arg1, arg2, arg3);
index ba94c54b4855ed45d560aa123e3e298f4b4d8db4..3144b7ef292d86695715a798558ec34c6970f8db 100644 (file)
@@ -4325,7 +4325,7 @@ build_vec_cmp (tree_code code, tree type,
 {
   tree zero_vec = build_zero_cst (type);
   tree minus_one_vec = build_minus_one_cst (type);
-  tree cmp_type = build_same_sized_truth_vector_type(type);
+  tree cmp_type = truth_type_for (type);
   tree cmp = build2 (code, cmp_type, arg0, arg1);
   return build3 (VEC_COND_EXPR, type, cmp, minus_one_vec, zero_vec);
 }
index 012d4958a4466ea44051e12bb7da521272c5a502..046f28373c5245c03b04486753a75a1053a4f4b3 100644 (file)
@@ -1,3 +1,8 @@
+2019-11-14  Richard Sandiford  <richard.sandiford@arm.com>
+
+       * d-codegen.cc (build_boolop): Use truth_type_for instead of
+       build_same_sized_truth_vector_type.
+
 2019-11-13  Joseph Myers  <joseph@codesourcery.com>
 
        * d-target.cc (define_float_constants): Update call to
index cf50693b2f5c983f2b90d66a6d8f518ea7e41d7a..01e6916febafa57b8897d86a7d9a83a07429d74d 100644 (file)
@@ -1399,7 +1399,7 @@ build_boolop (tree_code code, tree arg0, tree arg1)
       /* Build a vector comparison.
         VEC_COND_EXPR <e1 op e2, { -1, -1, -1, -1 }, { 0, 0, 0, 0 }>; */
       tree type = TREE_TYPE (arg0);
-      tree cmptype = build_same_sized_truth_vector_type (type);
+      tree cmptype = truth_type_for (type);
       tree cmp = fold_build2_loc (input_location, code, cmptype, arg0, arg1);
 
       return fold_build3_loc (input_location, VEC_COND_EXPR, type, cmp,
index 5855653257bb96183093be6ea882a51e159cc967..091226533e74baed6af0a67692fbf5ec07fa3934 100644 (file)
@@ -694,7 +694,7 @@ expand_vector_divmod (gimple_stmt_iterator *gsi, tree type, tree op0,
              tree zero, cst, cond, mask_type;
              gimple *stmt;
 
-             mask_type = build_same_sized_truth_vector_type (type);
+             mask_type = truth_type_for (type);
              zero = build_zero_cst (type);
              cond = build2 (LT_EXPR, mask_type, op0, zero);
              tree_vector_builder vec (type, nunits, 1);
index 5cc2f8a240e9b91cbcf69b6cf442f4845939dd00..8319cb10c1a5e40f337637fcf7162d1756bc7cda 100644 (file)
@@ -4603,8 +4603,7 @@ vect_create_epilog_for_reduction (stmt_vec_info stmt_info,
       tree index_vec_type = TREE_TYPE (induction_index);
       gcc_checking_assert (TYPE_UNSIGNED (index_vec_type));
       tree index_scalar_type = TREE_TYPE (index_vec_type);
-      tree index_vec_cmp_type = build_same_sized_truth_vector_type
-       (index_vec_type);
+      tree index_vec_cmp_type = truth_type_for (index_vec_type);
 
       /* Get an unsigned integer version of the type of the data vector.  */
       int scalar_precision
@@ -4831,7 +4830,7 @@ vect_create_epilog_for_reduction (stmt_vec_info stmt_info,
       tree index = build_index_vector (vectype, 0, 1);
       tree index_type = TREE_TYPE (index);
       tree index_elt_type = TREE_TYPE (index_type);
-      tree mask_type = build_same_sized_truth_vector_type (index_type);
+      tree mask_type = truth_type_for (index_type);
 
       /* Create a vector that, for each element, identifies which of
         the REDUC_GROUP_SIZE results should use it.  */
@@ -7948,7 +7947,7 @@ vect_record_loop_mask (loop_vec_info loop_vinfo, vec_loop_masks *masks,
   if (rgm->max_nscalars_per_iter < nscalars_per_iter)
     {
       rgm->max_nscalars_per_iter = nscalars_per_iter;
-      rgm->mask_type = build_same_sized_truth_vector_type (vectype);
+      rgm->mask_type = truth_type_for (vectype);
     }
 }
 
@@ -7993,7 +7992,7 @@ vect_get_loop_mask (gimple_stmt_iterator *gsi, vec_loop_masks *masks,
       gcc_assert (multiple_p (TYPE_VECTOR_SUBPARTS (mask_type),
                              TYPE_VECTOR_SUBPARTS (vectype)));
       gimple_seq seq = NULL;
-      mask_type = build_same_sized_truth_vector_type (vectype);
+      mask_type = truth_type_for (vectype);
       mask = gimple_build (&seq, VIEW_CONVERT_EXPR, mask_type, mask);
       if (seq)
        gsi_insert_seq_before (gsi, seq, GSI_SAME_STMT);
index 8ebbcd76b64b83764511ecbe9996568d2fabca74..86c3abfa819532398484ee2decffdecf4b4181b0 100644 (file)
@@ -4214,7 +4214,7 @@ build_mask_conversion (tree mask, tree vectype, stmt_vec_info stmt_vinfo)
   gimple *stmt;
   tree masktype, tmp;
 
-  masktype = build_same_sized_truth_vector_type (vectype);
+  masktype = truth_type_for (vectype);
   tmp = vect_recog_temp_ssa_var (TREE_TYPE (masktype), NULL);
   stmt = gimple_build_assign (tmp, CONVERT_EXPR, mask);
   append_pattern_def_seq (stmt_vinfo, stmt, masktype);
index a2c70ec5cd6e07ae46a91d59bdc1370dec905c37..61a864eec93376ebd51fa58a9e0e629774141f57 100644 (file)
@@ -3497,8 +3497,7 @@ vect_get_constant_vectors (slp_tree op_node, slp_tree slp_node,
   tree stmt_vectype = STMT_VINFO_VECTYPE (stmt_vinfo);
   if (VECT_SCALAR_BOOLEAN_TYPE_P (TREE_TYPE (op))
       && vect_mask_constant_operand_p (stmt_vinfo))
-    vector_type
-      = build_same_sized_truth_vector_type (stmt_vectype);
+    vector_type = truth_type_for (stmt_vectype);
   else
     vector_type = get_vectype_for_scalar_type (vinfo, TREE_TYPE (op));
 
index 9668643d20b8d2606eb9df3fe3bcdd295726c4aa..19984b5ad22315e7fcf879d4a141c5f63b522c58 100644 (file)
@@ -1605,7 +1605,7 @@ vect_get_vec_def_for_operand (tree op, stmt_vec_info stmt_vinfo, tree vectype)
        vector_type = vectype;
       else if (VECT_SCALAR_BOOLEAN_TYPE_P (TREE_TYPE (op))
               && VECTOR_BOOLEAN_TYPE_P (stmt_vectype))
-       vector_type = build_same_sized_truth_vector_type (stmt_vectype);
+       vector_type = truth_type_for (stmt_vectype);
       else
        vector_type = get_vectype_for_scalar_type (loop_vinfo, TREE_TYPE (op));
 
@@ -2734,7 +2734,7 @@ vect_build_gather_load_calls (stmt_vec_info stmt_info,
                           || TREE_CODE (masktype) == INTEGER_TYPE
                           || types_compatible_p (srctype, masktype)));
   if (mask && TREE_CODE (masktype) == INTEGER_TYPE)
-    masktype = build_same_sized_truth_vector_type (srctype);
+    masktype = truth_type_for (srctype);
 
   tree mask_halftype = masktype;
   tree perm_mask = NULL_TREE;
@@ -2780,8 +2780,7 @@ vect_build_gather_load_calls (stmt_vec_info stmt_info,
          mask_perm_mask = vect_gen_perm_mask_checked (masktype, indices);
        }
       else if (mask)
-       mask_halftype
-         = build_same_sized_truth_vector_type (gs_info->offset_vectype);
+       mask_halftype = truth_type_for (gs_info->offset_vectype);
     }
   else
     gcc_unreachable ();
@@ -3524,8 +3523,7 @@ vectorizable_call (stmt_vec_info stmt_info, gimple_stmt_iterator *gsi,
          if (mask_opno >= 0 && !vectypes[mask_opno])
            {
              gcc_assert (modifier != WIDEN);
-             vectypes[mask_opno]
-               = build_same_sized_truth_vector_type (vectype_in);
+             vectypes[mask_opno] = truth_type_for (vectype_in);
            }
 
          for (i = 0; i < nargs; i++)
@@ -6581,7 +6579,7 @@ scan_store_can_perm_p (tree vectype, tree init,
                   && TREE_CODE (init) != REAL_CST)
                  || !initializer_zerop (init))
                {
-                 tree masktype = build_same_sized_truth_vector_type (vectype);
+                 tree masktype = truth_type_for (vectype);
                  if (!expand_vec_cond_expr_p (vectype, masktype, VECTOR_CST))
                    return -1;
                  whole_vector_shift_kind = scan_store_kind_lshift_cond;
@@ -7106,7 +7104,7 @@ vectorizable_scan_store (stmt_vec_info stmt_info, gimple_stmt_iterator *gsi,
            zero_vec = build_zero_cst (vectype);
          if (masktype == NULL_TREE
              && use_whole_vector[i] == scan_store_kind_lshift_cond)
-           masktype = build_same_sized_truth_vector_type (vectype);
+           masktype = truth_type_for (vectype);
          perms[i] = vect_gen_perm_mask_any (vectype, indices);
        }
       else
@@ -7547,8 +7545,7 @@ vectorizable_store (stmt_vec_info stmt_info, gimple_stmt_iterator *gsi,
          ncopies *= 2;
 
          if (mask)
-           mask_halfvectype
-             = build_same_sized_truth_vector_type (gs_info.offset_vectype);
+           mask_halfvectype = truth_type_for (gs_info.offset_vectype);
        }
       else
        gcc_unreachable ();
@@ -9972,7 +9969,7 @@ vectorizable_condition (stmt_vec_info stmt_info, gimple_stmt_iterator *gsi,
     return false;
 
   masked = !COMPARISON_CLASS_P (cond_expr);
-  vec_cmp_type = build_same_sized_truth_vector_type (comp_vectype);
+  vec_cmp_type = truth_type_for (comp_vectype);
 
   if (vec_cmp_type == NULL_TREE)
     return false;
@@ -11233,8 +11230,7 @@ get_mask_type_for_scalar_type (vec_info *vinfo, tree scalar_type)
   if (!vectype)
     return NULL;
 
-  return build_truth_vector_type (TYPE_VECTOR_SUBPARTS (vectype),
-                                 vinfo->vector_size);
+  return truth_type_for (vectype);
 }
 
 /* Function get_same_sized_vectype
@@ -11246,7 +11242,7 @@ tree
 get_same_sized_vectype (tree scalar_type, tree vector_type)
 {
   if (VECT_SCALAR_BOOLEAN_TYPE_P (scalar_type))
-    return build_same_sized_truth_vector_type (vector_type);
+    return truth_type_for (vector_type);
 
   return get_vectype_for_scalar_type_and_size
           (scalar_type, GET_MODE_SIZE (TYPE_MODE (vector_type)));
@@ -12109,7 +12105,7 @@ vect_get_mask_type_for_stmt (stmt_vec_info stmt_info)
          && !VECTOR_BOOLEAN_TYPE_P (mask_type)
          && gimple_code (stmt) == GIMPLE_ASSIGN
          && TREE_CODE_CLASS (gimple_assign_rhs_code (stmt)) == tcc_comparison)
-       mask_type = build_same_sized_truth_vector_type (mask_type);
+       mask_type = truth_type_for (mask_type);
     }
 
   /* No mask_type should mean loop invariant predicate.
index 2375bf85c2daa5e7105acca22e8e20a88e0c8cd6..61b95c993c90582ed3707fad441acfdcb90b985e 100644 (file)
@@ -10887,11 +10887,16 @@ build_truth_vector_type_for_mode (poly_uint64 nunits, machine_mode mask_mode)
   return make_vector_type (bool_type, nunits, mask_mode);
 }
 
-/* Build truth vector with specified length and number of units.  */
+/* Build a vector type that holds one boolean result for each element of
+   vector type VECTYPE.  The public interface for this operation is
+   truth_type_for.  */
 
-tree
-build_truth_vector_type (poly_uint64 nunits, poly_uint64 vector_size)
+static tree
+build_truth_vector_type_for (tree vectype)
 {
+  poly_uint64 nunits = TYPE_VECTOR_SUBPARTS (vectype);
+  poly_uint64 vector_size = tree_to_poly_uint64 (TYPE_SIZE_UNIT (vectype));
+
   machine_mode mask_mode;
   if (targetm.vectorize.get_mask_mode (nunits,
                                       vector_size).exists (&mask_mode))
@@ -10904,22 +10909,6 @@ build_truth_vector_type (poly_uint64 nunits, poly_uint64 vector_size)
   return make_vector_type (bool_type, nunits, BLKmode);
 }
 
-/* Returns a vector type corresponding to a comparison of VECTYPE.  */
-
-tree
-build_same_sized_truth_vector_type (tree vectype)
-{
-  if (VECTOR_BOOLEAN_TYPE_P (vectype))
-    return vectype;
-
-  poly_uint64 size = GET_MODE_SIZE (TYPE_MODE (vectype));
-
-  if (known_eq (size, 0U))
-    size = tree_to_uhwi (TYPE_SIZE_UNIT (vectype));
-
-  return build_truth_vector_type (TYPE_VECTOR_SUBPARTS (vectype), size);
-}
-
 /* Like build_vector_type, but builds a variant type with TYPE_VECTOR_OPAQUE
    set.  */
 
@@ -11725,8 +11714,7 @@ truth_type_for (tree type)
     {
       if (VECTOR_BOOLEAN_TYPE_P (type))
        return type;
-      return build_truth_vector_type (TYPE_VECTOR_SUBPARTS (type),
-                                     GET_MODE_SIZE (TYPE_MODE (type)));
+      return build_truth_vector_type_for (type);
     }
   else
     return boolean_type_node;
index 93ccbf7fa86b6388d18fb984c6618d8e696c3e71..89114e227d87db2383f4ca0810d03342b2615b64 100644 (file)
@@ -4444,8 +4444,6 @@ extern tree build_reference_type (tree);
 extern tree build_vector_type_for_mode (tree, machine_mode);
 extern tree build_vector_type (tree, poly_int64);
 extern tree build_truth_vector_type_for_mode (poly_uint64, machine_mode);
-extern tree build_truth_vector_type (poly_uint64, poly_uint64);
-extern tree build_same_sized_truth_vector_type (tree vectype);
 extern tree build_opaque_vector_type (tree, poly_int64);
 extern tree build_index_type (tree);
 extern tree build_array_type (tree, tree, bool = false);