OSDN Git Service

PR testsuite/34168
[pf3gnuchains/gcc-fork.git] / gcc / tree-affine.c
index 972d442..3a4d897 100644 (file)
@@ -110,6 +110,9 @@ aff_combination_scale (aff_tree *comb, double_int scale)
 
   if (comb->rest)
     {
+      tree type = comb->type;
+      if (POINTER_TYPE_P (type))
+       type = sizetype;
       if (comb->n < MAX_AFF_ELTS)
        {
          comb->elts[comb->n].coef = scale;
@@ -118,8 +121,8 @@ aff_combination_scale (aff_tree *comb, double_int scale)
          comb->n++;
        }
       else
-       comb->rest = fold_build2 (MULT_EXPR, comb->type, comb->rest, 
-                                 double_int_to_tree (comb->type, scale));
+       comb->rest = fold_build2 (MULT_EXPR, type, comb->rest, 
+                                 double_int_to_tree (type, scale));
     }
 }
 
@@ -181,14 +184,8 @@ aff_combination_add_elt (aff_tree *comb, tree elt, double_int scale)
                       double_int_to_tree (type, scale)); 
 
   if (comb->rest)
-    {
-      if (POINTER_TYPE_P (comb->type))
-       comb->rest = fold_build2 (POINTER_PLUS_EXPR, comb->type,
-                                 comb->rest, elt);
-      else
-       comb->rest = fold_build2 (PLUS_EXPR, comb->type, comb->rest,
-                                 elt);
-    }
+    comb->rest = fold_build2 (PLUS_EXPR, type, comb->rest,
+                             elt);
   else
     comb->rest = elt;
 }
@@ -231,7 +228,7 @@ aff_combination_convert (aff_tree *comb, tree type)
     }
 
   comb->type = type;
-  if (comb->rest)
+  if (comb->rest && !POINTER_TYPE_P (type))
     comb->rest = fold_convert (type, comb->rest);
 
   if (TYPE_PRECISION (type) == TYPE_PRECISION (comb_type))
@@ -282,7 +279,6 @@ tree_to_aff_combination (tree expr, tree type, aff_tree *comb)
     case POINTER_PLUS_EXPR:
       tree_to_aff_combination (TREE_OPERAND (expr, 0), type, comb);
       tree_to_aff_combination (TREE_OPERAND (expr, 1), sizetype, &tmp);
-      aff_combination_convert (&tmp, type);
       aff_combination_add (comb, &tmp);
       return;
 
@@ -353,29 +349,40 @@ add_elt_to_tree (tree expr, tree type, tree elt, double_int scale,
                 aff_tree *comb)
 {
   enum tree_code code;
+  tree type1 = type;
+  if (POINTER_TYPE_P (type))
+    type1 = sizetype;
 
   scale = double_int_ext_for_comb (scale, comb);
-  elt = fold_convert (type, elt);
+  elt = fold_convert (type1, elt);
 
   if (double_int_one_p (scale))
     {
       if (!expr)
-       return elt;
+       return fold_convert (type, elt);
 
+      if (POINTER_TYPE_P (type))
+        return fold_build2 (POINTER_PLUS_EXPR, type, expr, elt);
       return fold_build2 (PLUS_EXPR, type, expr, elt);
     }
 
   if (double_int_minus_one_p (scale))
     {
       if (!expr)
-       return fold_build1 (NEGATE_EXPR, type, elt);
+       return fold_convert (type, fold_build1 (NEGATE_EXPR, type1, elt));
 
+      if (POINTER_TYPE_P (type))
+       {
+         elt = fold_build1 (NEGATE_EXPR, type1, elt);
+         return fold_build2 (POINTER_PLUS_EXPR, type, expr, elt);
+       }
       return fold_build2 (MINUS_EXPR, type, expr, elt);
     }
 
   if (!expr)
-    return fold_build2 (MULT_EXPR, type, elt,
-                       double_int_to_tree (type, scale));
+    return fold_convert (type,
+                        fold_build2 (MULT_EXPR, type1, elt,
+                                     double_int_to_tree (type1, scale)));
 
   if (double_int_negative_p (scale))
     {
@@ -385,8 +392,14 @@ add_elt_to_tree (tree expr, tree type, tree elt, double_int scale,
   else
     code = PLUS_EXPR;
 
-  elt = fold_build2 (MULT_EXPR, type, elt,
-                    double_int_to_tree (type, scale));
+  elt = fold_build2 (MULT_EXPR, type1, elt,
+                    double_int_to_tree (type1, scale));
+  if (POINTER_TYPE_P (type))
+    {
+      if (code == MINUS_EXPR)
+        elt = fold_build1 (NEGATE_EXPR, type1, elt);
+      return fold_build2 (POINTER_PLUS_EXPR, type, expr, elt);
+    }
   return fold_build2 (code, type, expr, elt);
 }
 
@@ -399,6 +412,9 @@ aff_combination_to_tree (aff_tree *comb)
   tree expr = comb->rest;
   unsigned i;
   double_int off, sgn;
+  tree type1 = type;
+  if (POINTER_TYPE_P (type))
+    type1 = sizetype;
 
   gcc_assert (comb->n == MAX_AFF_ELTS || comb->rest == NULL_TREE);
 
@@ -418,7 +434,7 @@ aff_combination_to_tree (aff_tree *comb)
       off = comb->offset;
       sgn = double_int_one;
     }
-  return add_elt_to_tree (expr, type, double_int_to_tree (type, off), sgn,
+  return add_elt_to_tree (expr, type, double_int_to_tree (type1, off), sgn,
                          comb);
 }
 
@@ -629,7 +645,7 @@ tree_to_aff_combination_expand (tree expr, tree type, aff_tree *comb,
    pointer_map_traverse.  */
 
 static bool
-free_name_expansion (void *key ATTRIBUTE_UNUSED, void **value,
+free_name_expansion (const void *key ATTRIBUTE_UNUSED, void **value,
                     void *data ATTRIBUTE_UNUSED)
 {
   struct name_expansion *exp = *value;
@@ -722,3 +738,48 @@ aff_combination_constant_multiple_p (aff_tree *val, aff_tree *div,
   gcc_assert (mult_set);
   return true;
 }
+
+/* Prints the affine VAL to the FILE. */
+
+void
+print_aff (FILE *file, aff_tree *val)
+{
+  unsigned i;
+  bool uns = TYPE_UNSIGNED (val->type);
+  if (POINTER_TYPE_P (val->type))
+    uns = false;
+  fprintf (file, "{\n  type = ");
+  print_generic_expr (file, val->type, TDF_VOPS|TDF_MEMSYMS);
+  fprintf (file, "\n  offset = ");
+  dump_double_int (file, val->offset, uns);
+  if (val->n > 0)
+    {
+      fprintf (file, "\n  elements = {\n");
+      for (i = 0; i < val->n; i++)
+       {
+         fprintf (file, "    [%d] = ", i);
+         print_generic_expr (file, val->elts[i].val, TDF_VOPS|TDF_MEMSYMS);
+         
+         fprintf (file, " * ");
+         dump_double_int (file, val->elts[i].coef, uns);
+         if (i != val->n - 1)
+           fprintf (file, ", \n");
+       }
+      fprintf (file, "\n  }");
+  }
+  if (val->rest)
+    {
+      fprintf (file, "\n  rest = ");
+      print_generic_expr (file, val->rest, TDF_VOPS|TDF_MEMSYMS);
+    }
+  fprintf (file, "\n}");
+}
+
+/* Prints the affine VAL to the standard error, used for debugging.  */
+
+void
+debug_aff (aff_tree *val)
+{
+  print_aff (stderr, val);
+  fprintf (stderr, "\n");
+}