diff options
-rw-r--r-- | gcc/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/fold-const.c | 45 |
2 files changed, 50 insertions, 0 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index c2091e5..027355c 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +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 + 2009-04-08 Danny Smith <dannysmith@users.sourceforge.net> PR bootstrap/39660 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; } |