This patch makes the C FE use the VECTOR_TYPE_P macro where appropriate.
The existing code in the last build_binary_op hunk was really weird...

Now the question is: do we want e.g. ARRAY_TYPE_P, etc.?

Bootstrapped/regtested on x86_64-linux, ok for trunk?

2015-06-26  Marek Polacek  <pola...@redhat.com>

        * c-common.c (check_main_parameter_types): Use VECTOR_TYPE_P
        throughout.
        * c-gimplify.c: Likewise.

        * c-typeck.c: Use VECTOR_TYPE_P throughout.

diff --git gcc/c-family/c-common.c gcc/c-family/c-common.c
index 73d0c7f..5ca7f6c 100644
--- gcc/c-family/c-common.c
+++ gcc/c-family/c-common.c
@@ -2412,7 +2412,7 @@ check_main_parameter_types (tree decl)
 bool
 vector_targets_convertible_p (const_tree t1, const_tree t2)
 {
-  if (TREE_CODE (t1) == VECTOR_TYPE && TREE_CODE (t2) == VECTOR_TYPE
+  if (VECTOR_TYPE_P (t1) && VECTOR_TYPE_P (t2)
       && (TYPE_VECTOR_OPAQUE (t1) || TYPE_VECTOR_OPAQUE (t2))
       && tree_int_cst_equal (TYPE_SIZE (t1), TYPE_SIZE (t2)))
     return true;
@@ -2500,7 +2500,7 @@ c_build_vec_perm_expr (location_t loc, tree v0, tree v1, 
tree mask,
       || mask == error_mark_node)
     return error_mark_node;
 
-  if (TREE_CODE (TREE_TYPE (mask)) != VECTOR_TYPE
+  if (!VECTOR_TYPE_P (TREE_TYPE (mask))
       || TREE_CODE (TREE_TYPE (TREE_TYPE (mask))) != INTEGER_TYPE)
     {
       if (complain)
@@ -2509,8 +2509,8 @@ c_build_vec_perm_expr (location_t loc, tree v0, tree v1, 
tree mask,
       return error_mark_node;
     }
 
-  if (TREE_CODE (TREE_TYPE (v0)) != VECTOR_TYPE
-      || TREE_CODE (TREE_TYPE (v1)) != VECTOR_TYPE)
+  if (!VECTOR_TYPE_P (TREE_TYPE (v0))
+      || !VECTOR_TYPE_P (TREE_TYPE (v1)))
     {
       if (complain)
        error_at (loc, "__builtin_shuffle arguments must be vectors");
@@ -12483,7 +12483,7 @@ convert_vector_to_pointer_for_subscript (location_t loc,
                                         tree *vecp, tree index)
 {
   bool ret = false;
-  if (TREE_CODE (TREE_TYPE (*vecp)) == VECTOR_TYPE)
+  if (VECTOR_TYPE_P (TREE_TYPE (*vecp)))
     {
       tree type = TREE_TYPE (*vecp);
       tree type1;
@@ -12549,8 +12549,7 @@ scalar_to_vector (location_t loc, enum tree_code code, 
tree op0, tree op1,
   bool integer_only_op = false;
   enum stv_conv ret = stv_firstarg;
 
-  gcc_assert (TREE_CODE (type0) == VECTOR_TYPE
-             || TREE_CODE (type1) == VECTOR_TYPE);
+  gcc_assert (VECTOR_TYPE_P (type0) || VECTOR_TYPE_P (type1));
   switch (code)
     {
       /* Most GENERIC binary expressions require homogeneous arguments.
@@ -12600,7 +12599,7 @@ scalar_to_vector (location_t loc, enum tree_code code, 
tree op0, tree op1,
       case LT_EXPR:
       case GT_EXPR:
       /* What about UNLT_EXPR?  */
-       if (TREE_CODE (type0) == VECTOR_TYPE)
+       if (VECTOR_TYPE_P (type0))
          {
            ret = stv_secondarg;
            std::swap (type0, type1);
diff --git gcc/c-family/c-gimplify.c gcc/c-family/c-gimplify.c
index 317891f..98a6d53 100644
--- gcc/c-family/c-gimplify.c
+++ gcc/c-family/c-gimplify.c
@@ -248,7 +248,7 @@ c_gimplify_expr (tree *expr_p, gimple_seq *pre_p 
ATTRIBUTE_UNUSED,
           We should get rid of this conversion when we have a proper
           type demotion/promotion pass.  */
        tree *op1_p = &TREE_OPERAND (*expr_p, 1);
-       if (TREE_CODE (TREE_TYPE (*op1_p)) != VECTOR_TYPE
+       if (!VECTOR_TYPE_P (TREE_TYPE (*op1_p))
            && !types_compatible_p (TYPE_MAIN_VARIANT (TREE_TYPE (*op1_p)),
                                    unsigned_type_node)
            && !types_compatible_p (TYPE_MAIN_VARIANT (TREE_TYPE (*op1_p)),
diff --git gcc/c/c-typeck.c gcc/c/c-typeck.c
index 9caf028..66af203 100644
--- gcc/c/c-typeck.c
+++ gcc/c/c-typeck.c
@@ -2457,7 +2457,7 @@ build_array_ref (location_t loc, tree array, tree index)
   if (TREE_CODE (TREE_TYPE (array)) != ARRAY_TYPE
       && TREE_CODE (TREE_TYPE (array)) != POINTER_TYPE
       /* Allow vector[index] but not index[vector].  */
-      && TREE_CODE (TREE_TYPE (array)) != VECTOR_TYPE)
+      && !VECTOR_TYPE_P (TREE_TYPE (array)))
     {
       if (TREE_CODE (TREE_TYPE (index)) != ARRAY_TYPE
          && TREE_CODE (TREE_TYPE (index)) != POINTER_TYPE)
@@ -6730,7 +6730,7 @@ digest_init (location_t init_loc, tree type, tree init, 
tree origtype,
      vector constructor is not constant (e.g. {1,2,3,foo()}) then punt
      below and handle as a constructor.  */
   if (code == VECTOR_TYPE
-      && TREE_CODE (TREE_TYPE (inside_init)) == VECTOR_TYPE
+      && VECTOR_TYPE_P (TREE_TYPE (inside_init))
       && vector_types_convertible_p (TREE_TYPE (inside_init), type, true)
       && TREE_CONSTANT (inside_init))
     {
@@ -7181,7 +7181,7 @@ really_start_incremental_init (tree type)
   if (type == 0)
     type = TREE_TYPE (constructor_decl);
 
-  if (TREE_CODE (type) == VECTOR_TYPE
+  if (VECTOR_TYPE_P (type)
       && TYPE_VECTOR_OPAQUE (type))
     error ("opaque vector types cannot be initialized");
 
@@ -7267,7 +7267,7 @@ really_start_incremental_init (tree type)
 
       constructor_unfilled_index = constructor_index;
     }
-  else if (TREE_CODE (constructor_type) == VECTOR_TYPE)
+  else if (VECTOR_TYPE_P (constructor_type))
     {
       /* Vectors are like simple fixed-size arrays.  */
       constructor_max_index =
@@ -7440,7 +7440,7 @@ push_init_level (location_t loc, int implicit,
       constructor_unfilled_fields = constructor_fields;
       constructor_bit_index = bitsize_zero_node;
     }
-  else if (TREE_CODE (constructor_type) == VECTOR_TYPE)
+  else if (VECTOR_TYPE_P (constructor_type))
     {
       /* Vectors are like simple fixed-size arrays.  */
       constructor_max_index =
@@ -7620,7 +7620,7 @@ pop_init_level (location_t loc, int implicit,
   else if (TREE_CODE (constructor_type) != RECORD_TYPE
           && TREE_CODE (constructor_type) != UNION_TYPE
           && TREE_CODE (constructor_type) != ARRAY_TYPE
-          && TREE_CODE (constructor_type) != VECTOR_TYPE)
+          && !VECTOR_TYPE_P (constructor_type))
     {
       /* A nonincremental scalar initializer--just return
         the element, after verifying there is just one.  */
@@ -8770,7 +8770,7 @@ process_init_element (location_t loc, struct c_expr 
value, bool implicit,
                              pop_init_level (loc, 1, braced_init_obstack),
                              true, braced_init_obstack);
       else if ((TREE_CODE (constructor_type) == ARRAY_TYPE
-               || TREE_CODE (constructor_type) == VECTOR_TYPE)
+               || VECTOR_TYPE_P (constructor_type))
               && constructor_max_index
               && tree_int_cst_lt (constructor_max_index,
                                   constructor_index))
@@ -9040,7 +9040,7 @@ process_init_element (location_t loc, struct c_expr 
value, bool implicit,
               constructor_unfilled_index.  */
            constructor_unfilled_index = constructor_index;
        }
-      else if (TREE_CODE (constructor_type) == VECTOR_TYPE)
+      else if (VECTOR_TYPE_P (constructor_type))
        {
          tree elttype = TYPE_MAIN_VARIANT (TREE_TYPE (constructor_type));
 
@@ -10303,8 +10303,7 @@ build_binary_op (location_t location, enum tree_code 
code,
 
   /* Do not apply default conversion in mixed vector/scalar expression.  */
   if (convert_p
-      && !((TREE_CODE (TREE_TYPE (op0)) == VECTOR_TYPE)
-          != (TREE_CODE (TREE_TYPE (op1)) == VECTOR_TYPE)))
+      && VECTOR_TYPE_P (TREE_TYPE (op0)) == VECTOR_TYPE_P (TREE_TYPE (op1)))
     {
       op0 = default_conversion (op0);
       op1 = default_conversion (op1);

        Marek

Reply via email to