OSDN Git Service

Daily bump.
[pf3gnuchains/gcc-fork.git] / gcc / tree-vect-generic.c
index 1d11701..cb64065 100644 (file)
@@ -1,5 +1,5 @@
 /* Lower vector operations to scalar operations.
-   Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010
+   Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
    Free Software Foundation, Inc.
 
 This file is part of GCC.
@@ -125,8 +125,10 @@ static tree
 do_binop (gimple_stmt_iterator *gsi, tree inner_type, tree a, tree b,
          tree bitpos, tree bitsize, enum tree_code code)
 {
-  a = tree_vec_extract (gsi, inner_type, a, bitsize, bitpos);
-  b = tree_vec_extract (gsi, inner_type, b, bitsize, bitpos);
+  if (TREE_CODE (TREE_TYPE (a)) == VECTOR_TYPE)
+    a = tree_vec_extract (gsi, inner_type, a, bitsize, bitpos);
+  if (TREE_CODE (TREE_TYPE (b)) == VECTOR_TYPE)
+    b = tree_vec_extract (gsi, inner_type, b, bitsize, bitpos);
   return gimplify_build2 (gsi, code, inner_type, a, b);
 }
 
@@ -235,6 +237,14 @@ expand_vector_piecewise (gimple_stmt_iterator *gsi, elem_op_func f,
   int delta = tree_low_cst (part_width, 1)
              / tree_low_cst (TYPE_SIZE (TREE_TYPE (type)), 1);
   int i;
+  location_t loc = gimple_location (gsi_stmt (*gsi));
+
+  if (types_compatible_p (gimple_expr_type (gsi_stmt (*gsi)), type))
+    warning_at (loc, OPT_Wvector_operation_performance,
+               "vector operation will be expanded piecewise");
+  else
+    warning_at (loc, OPT_Wvector_operation_performance,
+               "vector operation will be expanded in parallel");
 
   v = VEC_alloc(constructor_elt, gc, (nunits + delta - 1) / delta);
   for (i = 0; i < nunits;
@@ -260,6 +270,7 @@ expand_vector_parallel (gimple_stmt_iterator *gsi, elem_op_func f, tree type,
   tree result, compute_type;
   enum machine_mode mode;
   int n_words = tree_low_cst (TYPE_SIZE_UNIT (type), 1) / UNITS_PER_WORD;
+  location_t loc = gimple_location (gsi_stmt (*gsi));
 
   /* We have three strategies.  If the type is already correct, just do
      the operation an element at a time.  Else, if the vector is wider than
@@ -284,6 +295,9 @@ expand_vector_parallel (gimple_stmt_iterator *gsi, elem_op_func f, tree type,
       mode = mode_for_size (tree_low_cst (TYPE_SIZE (type), 1), MODE_INT, 0);
       compute_type = lang_hooks.types.type_for_mode (mode, 1);
       result = f (gsi, compute_type, a, b, NULL_TREE, NULL_TREE, code);
+      warning_at (loc, OPT_Wvector_operation_performance,
+                 "vector operation will be expanded with a "
+                 "single scalar operation");
     }
 
   return result;
@@ -400,8 +414,8 @@ expand_vector_operation (gimple_stmt_iterator *gsi, tree type, tree compute_type
       case PLUS_EXPR:
       case MINUS_EXPR:
         if (!TYPE_OVERFLOW_TRAPS (type))
-          return expand_vector_addition (gsi, do_binop, do_plus_minus, type,
-                                        gimple_assign_rhs1 (assign),
+         return expand_vector_addition (gsi, do_binop, do_plus_minus, type,
+                                        gimple_assign_rhs1 (assign),
                                         gimple_assign_rhs2 (assign), code);
        break;
 
@@ -457,13 +471,13 @@ expand_vector_operation (gimple_stmt_iterator *gsi, tree type, tree compute_type
                                    gimple_assign_rhs2 (assign), code);
 }
 \f
-/* Return a type for the widest vector mode whose components are of mode
-   INNER_MODE, or NULL_TREE if none is found.
-   SATP is true for saturating fixed-point types.  */
+/* Return a type for the widest vector mode whose components are of type
+   TYPE, or NULL_TREE if none is found.  */
 
 static tree
-type_for_widest_vector_mode (enum machine_mode inner_mode, optab op, int satp)
+type_for_widest_vector_mode (tree type, optab op)
 {
+  enum machine_mode inner_mode = TYPE_MODE (type);
   enum machine_mode best_mode = VOIDmode, mode;
   int best_nunits = 0;
 
@@ -489,13 +503,7 @@ type_for_widest_vector_mode (enum machine_mode inner_mode, optab op, int satp)
   if (best_mode == VOIDmode)
     return NULL_TREE;
   else
-    {
-      /* For fixed-point modes, we need to pass satp as the 2nd parameter.  */
-      if (ALL_FIXED_POINT_MODE_P (best_mode))
-       return lang_hooks.types.type_for_mode (best_mode, satp);
-
-      return lang_hooks.types.type_for_mode (best_mode, 1);
-    }
+    return build_vector_type_for_mode (type, best_mode);
 }
 
 
@@ -569,8 +577,9 @@ vector_element (gimple_stmt_iterator *gsi, tree vect, tree idx, tree *ptmpvec)
       else
         {
          tree size = TYPE_SIZE (vect_elt_type);
-          tree pos = fold_build2 (MULT_EXPR, TREE_TYPE (idx), idx, size);
-          return fold_build3 (BIT_FIELD_REF, vect_elt_type, vect, size, pos);
+         tree pos = fold_build2 (MULT_EXPR, bitsizetype, bitsize_int (index),
+                                 size);
+         return fold_build3 (BIT_FIELD_REF, vect_elt_type, vect, size, pos);
         }
     }
 
@@ -626,10 +635,25 @@ lower_vec_perm (gimple_stmt_iterator *gsi)
   tree constr, t, si, i_val;
   tree vec0tmp = NULL_TREE, vec1tmp = NULL_TREE, masktmp = NULL_TREE;
   bool two_operand_p = !operand_equal_p (vec0, vec1, 0);
+  location_t loc = gimple_location (gsi_stmt (*gsi));
   unsigned i;
 
-  if (expand_vec_perm_expr_p (TYPE_MODE (vect_type), vec0, vec1, mask))
+  if (TREE_CODE (mask) == VECTOR_CST)
+    {
+      unsigned char *sel_int = XALLOCAVEC (unsigned char, elements);
+      tree vals = TREE_VECTOR_CST_ELTS (mask);
+
+      for (i = 0; i < elements; ++i, vals = TREE_CHAIN (vals))
+       sel_int[i] = TREE_INT_CST_LOW (TREE_VALUE (vals)) & (2 * elements - 1);
+
+      if (can_vec_perm_p (TYPE_MODE (vect_type), false, sel_int))
+       return;
+    }
+  else if (can_vec_perm_p (TYPE_MODE (vect_type), true, NULL))
     return;
+  
+  warning_at (loc, OPT_Wvector_operation_performance,
+              "vector shuffling operation will be expanded piecewise");
 
   v = VEC_alloc (constructor_elt, gc, elements);
   for (i = 0; i < elements; i++)
@@ -758,60 +782,42 @@ expand_vector_operations_1 (gimple_stmt_iterator *gsi)
       || code == LROTATE_EXPR
       || code == RROTATE_EXPR)
     {
-      bool vector_scalar_shift;
-      op = optab_for_tree_code (code, type, optab_scalar);
+      optab opv;
 
-      /* Vector/Scalar shift is supported.  */
-      vector_scalar_shift = (op && (optab_handler (op, TYPE_MODE (type))
-                                   != CODE_FOR_nothing));
-
-      /* If the 2nd argument is vector, we need a vector/vector shift.
-         Except all the elements in the second vector are the same.  */
-      if (VECTOR_MODE_P (TYPE_MODE (TREE_TYPE (rhs2))))
+      /* Check whether we have vector <op> {x,x,x,x} where x
+         could be a scalar variable or a constant.  Transform
+         vector <op> {x,x,x,x} ==> vector <op> scalar.  */
+      if (VECTOR_INTEGER_TYPE_P (TREE_TYPE (rhs2)))
         {
           tree first;
           gimple def_stmt;
 
-          /* Check whether we have vector <op> {x,x,x,x} where x
-             could be a scalar variable or a constant. Transform
-             vector <op> {x,x,x,x} ==> vector <op> scalar.  */
-          if (vector_scalar_shift
-              && ((TREE_CODE (rhs2) == VECTOR_CST
-                  && (first = uniform_vector_p (rhs2)) != NULL_TREE)
-                 || (TREE_CODE (rhs2) == SSA_NAME
-                     && (def_stmt = SSA_NAME_DEF_STMT (rhs2))
-                     && gimple_assign_single_p (def_stmt)
-                     && (first = uniform_vector_p
-                           (gimple_assign_rhs1 (def_stmt))) != NULL_TREE)))
+          if ((TREE_CODE (rhs2) == VECTOR_CST
+              && (first = uniform_vector_p (rhs2)) != NULL_TREE)
+             || (TREE_CODE (rhs2) == SSA_NAME
+                 && (def_stmt = SSA_NAME_DEF_STMT (rhs2))
+                 && gimple_assign_single_p (def_stmt)
+                 && (first = uniform_vector_p
+                     (gimple_assign_rhs1 (def_stmt))) != NULL_TREE))
             {
               gimple_assign_set_rhs2 (stmt, first);
               update_stmt (stmt);
               rhs2 = first;
             }
-          else
-            op = optab_for_tree_code (code, type, optab_vector);
         }
 
-      /* Try for a vector/scalar shift, and if we don't have one, see if we
-         have a vector/vector shift */
-      else if (!vector_scalar_shift)
+      opv = optab_for_tree_code (code, type, optab_vector);
+      if (VECTOR_INTEGER_TYPE_P (TREE_TYPE (rhs2)))
+       op = opv;
+      else
        {
-         op = optab_for_tree_code (code, type, optab_vector);
+          op = optab_for_tree_code (code, type, optab_scalar);
 
-         if (op && (optab_handler (op, TYPE_MODE (type))
-                    != CODE_FOR_nothing))
-           {
-             /* Transform vector <op> scalar => vector <op> {x,x,x,x}.  */
-             int n_parts = TYPE_VECTOR_SUBPARTS (type);
-             int part_size = tree_low_cst (TYPE_SIZE (TREE_TYPE (type)), 1);
-             tree part_type = lang_hooks.types.type_for_size (part_size, 1);
-             tree vect_type = build_vector_type (part_type, n_parts);
-
-             rhs2 = fold_convert (part_type, rhs2);
-             rhs2 = build_vector_from_val (vect_type, rhs2);
-             gimple_assign_set_rhs2 (stmt, rhs2);
-             update_stmt (stmt);
-           }
+         /* The rtl expander will expand vector/scalar as vector/vector
+            if necessary.  Don't bother converting the stmt here.  */
+         if (optab_handler (op, TYPE_MODE (type)) == CODE_FOR_nothing
+             && optab_handler (opv, TYPE_MODE (type)) != CODE_FOR_nothing)
+           return;
        }
     }
   else
@@ -827,7 +833,9 @@ expand_vector_operations_1 (gimple_stmt_iterator *gsi)
       || code == VEC_UNPACK_LO_EXPR
       || code == VEC_PACK_TRUNC_EXPR
       || code == VEC_PACK_SAT_EXPR
-      || code == VEC_PACK_FIX_TRUNC_EXPR)
+      || code == VEC_PACK_FIX_TRUNC_EXPR
+      || code == VEC_WIDEN_LSHIFT_HI_EXPR
+      || code == VEC_WIDEN_LSHIFT_LO_EXPR)
     type = TREE_TYPE (rhs1);
 
   /* Optabs will try converting a negation into a subtraction, so
@@ -840,14 +848,15 @@ expand_vector_operations_1 (gimple_stmt_iterator *gsi)
 
   /* For very wide vectors, try using a smaller vector mode.  */
   compute_type = type;
-  if (TYPE_MODE (type) == BLKmode && op)
+  if (!VECTOR_MODE_P (TYPE_MODE (type)) && op)
     {
       tree vector_compute_type
-        = type_for_widest_vector_mode (TYPE_MODE (TREE_TYPE (type)), op,
-                                      TYPE_SATURATING (TREE_TYPE (type)));
+        = type_for_widest_vector_mode (TREE_TYPE (type), op);
       if (vector_compute_type != NULL_TREE
          && (TYPE_VECTOR_SUBPARTS (vector_compute_type)
-             < TYPE_VECTOR_SUBPARTS (compute_type)))
+             < TYPE_VECTOR_SUBPARTS (compute_type))
+         && (optab_handler (op, TYPE_MODE (vector_compute_type))
+             != CODE_FOR_nothing))
        compute_type = vector_compute_type;
     }
 
@@ -857,12 +866,7 @@ expand_vector_operations_1 (gimple_stmt_iterator *gsi)
   if (compute_type == type)
     {
       compute_mode = TYPE_MODE (compute_type);
-      if ((GET_MODE_CLASS (compute_mode) == MODE_VECTOR_INT
-          || GET_MODE_CLASS (compute_mode) == MODE_VECTOR_FLOAT
-          || GET_MODE_CLASS (compute_mode) == MODE_VECTOR_FRACT
-          || GET_MODE_CLASS (compute_mode) == MODE_VECTOR_UFRACT
-          || GET_MODE_CLASS (compute_mode) == MODE_VECTOR_ACCUM
-          || GET_MODE_CLASS (compute_mode) == MODE_VECTOR_UACCUM)
+      if (VECTOR_MODE_P (compute_mode)
           && op != NULL
          && optab_handler (op, compute_mode) != CODE_FOR_nothing)
        return;