2013-05-13 Marc Glisse <marc.glisse@inria.fr>
authorglisse <glisse@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 13 May 2013 09:30:50 +0000 (09:30 +0000)
committerglisse <glisse@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 13 May 2013 09:30:50 +0000 (09:30 +0000)
gcc/
* tree-vect-generic.c (uniform_vector_p): Move ...
* tree.c (uniform_vector_p): ... here.
* tree.h (uniform_vector_p): Declare it.
* fold-const.c (fold_binary_loc) <shift>: Turn the second argument
into a scalar.

gcc/testsuite/
* gcc.dg/vector-shift-2.c: New testcase.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@198819 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/fold-const.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/vector-shift-2.c [new file with mode: 0644]
gcc/tree-vect-generic.c
gcc/tree.c
gcc/tree.h

index 1f6e5c2..945f525 100644 (file)
@@ -1,3 +1,11 @@
+2013-05-13  Marc Glisse  <marc.glisse@inria.fr>
+
+       * tree-vect-generic.c (uniform_vector_p): Move ...
+       * tree.c (uniform_vector_p): ... here.
+       * tree.h (uniform_vector_p): Declare it.
+       * fold-const.c (fold_binary_loc) <shift>: Turn the second argument
+       into a scalar.
+
 2013-05-13  Jakub Jelinek  <jakub@redhat.com>
 
        PR tree-optimization/57230
index bfe9e07..cbd3445 100644 (file)
@@ -12409,6 +12409,12 @@ fold_binary_loc (location_t loc,
       if (integer_zerop (arg0))
        return omit_one_operand_loc (loc, type, arg0, arg1);
 
+      /* Prefer vector1 << scalar to vector1 << vector2
+        if vector2 is uniform.  */
+      if (VECTOR_TYPE_P (TREE_TYPE (arg1))
+         && (tem = uniform_vector_p (arg1)) != NULL_TREE)
+       return fold_build2_loc (loc, code, type, op0, tem);
+
       /* Since negative shift count is not well-defined,
         don't try to compute it in the compiler.  */
       if (TREE_CODE (arg1) == INTEGER_CST && tree_int_cst_sgn (arg1) < 0)
index e465f2a..1e59972 100644 (file)
@@ -1,3 +1,7 @@
+2013-05-13  Marc Glisse  <marc.glisse@inria.fr>
+
+       * gcc.dg/vector-shift-2.c: New testcase.
+
 2013-05-13  Jakub Jelinek  <jakub@redhat.com>
 
        PR tree-optimization/57230
diff --git a/gcc/testsuite/gcc.dg/vector-shift-2.c b/gcc/testsuite/gcc.dg/vector-shift-2.c
new file mode 100644 (file)
index 0000000..2834290
--- /dev/null
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-options "-fdump-tree-ccp1" } */
+
+typedef unsigned vec __attribute__ ((vector_size (16)));
+void
+f (vec *a)
+{
+  vec s = { 5, 5, 5, 5 };
+  *a = *a << s;
+}
+
+/* { dg-final { scan-tree-dump "<< 5" "ccp1" } } */
+/* { dg-final { cleanup-tree-dump "ccp1" } } */
index dbad6d9..516bd6f 100644 (file)
@@ -326,52 +326,6 @@ expand_vector_addition (gimple_stmt_iterator *gsi,
                                    a, b, code);
 }
 
-/* Check if vector VEC consists of all the equal elements and
-   that the number of elements corresponds to the type of VEC.
-   The function returns first element of the vector
-   or NULL_TREE if the vector is not uniform.  */
-static tree
-uniform_vector_p (tree vec)
-{
-  tree first, t;
-  unsigned i;
-
-  if (vec == NULL_TREE)
-    return NULL_TREE;
-
-  if (TREE_CODE (vec) == VECTOR_CST)
-    {
-      first = VECTOR_CST_ELT (vec, 0);
-      for (i = 1; i < VECTOR_CST_NELTS (vec); ++i)
-       if (!operand_equal_p (first, VECTOR_CST_ELT (vec, i), 0))
-         return NULL_TREE;
-
-      return first;
-    }
-
-  else if (TREE_CODE (vec) == CONSTRUCTOR)
-    {
-      first = error_mark_node;
-
-      FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (vec), i, t)
-        {
-          if (i == 0)
-            {
-              first = t;
-              continue;
-            }
-         if (!operand_equal_p (first, t, 0))
-           return NULL_TREE;
-        }
-      if (i != TYPE_VECTOR_SUBPARTS (TREE_TYPE (vec)))
-       return NULL_TREE;
-
-      return first;
-    }
-
-  return NULL_TREE;
-}
-
 /* Try to expand vector comparison expression OP0 CODE OP1 by
    querying optab if the following expression:
        VEC_COND_EXPR< OP0 CODE OP1, {-1,...}, {0,...}>
index d93c6ae..d4e85e1 100644 (file)
@@ -10133,6 +10133,54 @@ initializer_zerop (const_tree init)
     }
 }
 
+/* Check if vector VEC consists of all the equal elements and
+   that the number of elements corresponds to the type of VEC.
+   The function returns first element of the vector
+   or NULL_TREE if the vector is not uniform.  */
+tree
+uniform_vector_p (const_tree vec)
+{
+  tree first, t;
+  unsigned i;
+
+  if (vec == NULL_TREE)
+    return NULL_TREE;
+
+  gcc_assert (VECTOR_TYPE_P (TREE_TYPE (vec)));
+
+  if (TREE_CODE (vec) == VECTOR_CST)
+    {
+      first = VECTOR_CST_ELT (vec, 0);
+      for (i = 1; i < VECTOR_CST_NELTS (vec); ++i)
+       if (!operand_equal_p (first, VECTOR_CST_ELT (vec, i), 0))
+         return NULL_TREE;
+
+      return first;
+    }
+
+  else if (TREE_CODE (vec) == CONSTRUCTOR)
+    {
+      first = error_mark_node;
+
+      FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (vec), i, t)
+        {
+          if (i == 0)
+            {
+              first = t;
+              continue;
+            }
+         if (!operand_equal_p (first, t, 0))
+           return NULL_TREE;
+        }
+      if (i != TYPE_VECTOR_SUBPARTS (TREE_TYPE (vec)))
+       return NULL_TREE;
+
+      return first;
+    }
+
+  return NULL_TREE;
+}
+
 /* Build an empty statement at location LOC.  */
 
 tree
index a46d276..89c088c 100644 (file)
@@ -5291,6 +5291,11 @@ extern tree first_field (const_tree);
 
 extern bool initializer_zerop (const_tree);
 
+/* Given a vector VEC, return its first element if all elements are
+   the same.  Otherwise return NULL_TREE.  */
+
+extern tree uniform_vector_p (const_tree);
+
 /* Given a CONSTRUCTOR CTOR, return the element values as a vector.  */
 
 extern vec<tree, va_gc> *ctor_to_vec (tree);