aboutsummaryrefslogtreecommitdiff
path: root/gcc/fold-const.c
diff options
context:
space:
mode:
authorBingfeng Mei <bmei@broadcom.com>2009-04-08 13:51:35 +0000
committerBingfeng Mei <meibf@gcc.gnu.org>2009-04-08 13:51:35 +0000
commitd1d1c602b81789f09e2e35ce2b5c01c13bcebb34 (patch)
tree5f363db3db831835937fc93bc08008f4d2f74046 /gcc/fold-const.c
parent40a14772d9e3ac71989aa3c8638d0fd40ed4ae9a (diff)
downloadgcc-d1d1c602b81789f09e2e35ce2b5c01c13bcebb34.zip
gcc-d1d1c602b81789f09e2e35ce2b5c01c13bcebb34.tar.gz
gcc-d1d1c602b81789f09e2e35ce2b5c01c13bcebb34.tar.bz2
fold-const.c (const_binop): Combine two VECTOR_CST under operation CODE to produce a new one.
2009-04-08 Bingfeng Mei <bmei@broadcom.com> * fold-const.c (const_binop): Combine two VECTOR_CST under operation CODE to produce a new one. Add a prototype to use fold_convert_const From-SVN: r145731
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r--gcc/fold-const.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 9c1a463..7dcf993 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -141,6 +141,7 @@ static bool reorder_operands_p (const_tree, const_tree);
static tree fold_negate_const (tree, tree);
static tree fold_not_const (tree, tree);
static tree fold_relational_const (enum tree_code, tree, tree, tree);
+static tree fold_convert_const (enum tree_code, tree, tree);
/* We know that A1 + B1 = SUM1, using 2's complement arithmetic and ignoring
@@ -1998,6 +1999,50 @@ const_binop (enum tree_code code, tree arg1, tree arg2, int notrunc)
return build_complex (type, real, imag);
}
+ if (TREE_CODE (arg1) == VECTOR_CST)
+ {
+ tree type = TREE_TYPE(arg1);
+ int count = TYPE_VECTOR_SUBPARTS (type), i;
+ tree elements1, elements2, list = NULL_TREE;
+
+ if(TREE_CODE(arg2) != VECTOR_CST)
+ return NULL_TREE;
+
+ elements1 = TREE_VECTOR_CST_ELTS (arg1);
+ elements2 = TREE_VECTOR_CST_ELTS (arg2);
+
+ for (i = 0; i < count; i++)
+ {
+ tree elem1, elem2, elem;
+
+ /* The trailing elements can be empty and should be treated as 0 */
+ if(!elements1)
+ elem1 = fold_convert_const (NOP_EXPR, TREE_TYPE (type), integer_zero_node);
+ else
+ {
+ elem1 = TREE_VALUE(elements1);
+ elements1 = TREE_CHAIN (elements1);
+ }
+
+ if(!elements2)
+ elem2 = fold_convert_const (NOP_EXPR, TREE_TYPE (type), integer_zero_node);
+ else
+ {
+ elem2 = TREE_VALUE(elements2);
+ elements2 = TREE_CHAIN (elements2);
+ }
+
+ elem = const_binop (code, elem1, elem2, notrunc);
+
+ /* It is possible that const_binop cannot handle the given
+ code and return NULL_TREE */
+ if(elem == NULL_TREE)
+ return NULL_TREE;
+
+ list = tree_cons (NULL_TREE, elem, list);
+ }
+ return build_vector(type, nreverse(list));
+ }
return NULL_TREE;
}