OSDN Git Service

2009-04-08 Bingfeng Mei <bmei@broadcom.com>
authormeibf <meibf@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 8 Apr 2009 13:51:35 +0000 (13:51 +0000)
committermeibf <meibf@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 8 Apr 2009 13:51:35 +0000 (13:51 +0000)
* 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

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

gcc/ChangeLog
gcc/fold-const.c

index c2091e5..027355c 100644 (file)
@@ -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
index 9c1a463..7dcf993 100644 (file)
@@ -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;
 }