From 640bfeb25ce9b2f645c75d1e04ecce9ad74c4be1 Mon Sep 17 00:00:00 2001 From: Marc Glisse Date: Mon, 13 May 2013 11:30:50 +0200 Subject: tree-vect-generic.c (uniform_vector_p): Move ... 2013-05-13 Marc Glisse 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) : Turn the second argument into a scalar. gcc/testsuite/ * gcc.dg/vector-shift-2.c: New testcase. From-SVN: r198819 --- gcc/tree.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'gcc/tree.c') diff --git a/gcc/tree.c b/gcc/tree.c index d93c6ae..d4e85e1 100644 --- a/gcc/tree.c +++ b/gcc/tree.c @@ -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 -- cgit v1.1