tree-affine.c (tree_to_aff_combination): Remove unreachable MEM_REF case.
authorRichard Biener <rguenther@suse.de>
Mon, 10 Dec 2018 14:20:18 +0000 (14:20 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Mon, 10 Dec 2018 14:20:18 +0000 (14:20 +0000)
2018-12-10  Richard Biener  <rguenther@suse.de>

* tree-affine.c (tree_to_aff_combination): Remove unreachable
MEM_REF case.
(aff_combination_expand): Cache on SSA names, not possibly
on conversion trees.  Avoid expanding cases we do not handle.

From-SVN: r266956

gcc/ChangeLog
gcc/tree-affine.c

index e91b1f9..08354fa 100644 (file)
@@ -1,5 +1,12 @@
 2018-12-10  Richard Biener  <rguenther@suse.de>
 
+       * tree-affine.c (tree_to_aff_combination): Remove unreachable
+       MEM_REF case.
+       (aff_combination_expand): Cache on SSA names, not possibly
+       on conversion trees.  Avoid expanding cases we do not handle.
+
+2018-12-10  Richard Biener  <rguenther@suse.de>
+
        PR tree-optimization/88427
        * vr-values.c (vr_values::extract_range_from_phi_node):
        Handle symbolic ranges conservatively when trying to drop
index 96b479d..c10cdd0 100644 (file)
@@ -350,25 +350,6 @@ tree_to_aff_combination (tree expr, tree type, aff_tree *comb)
        }
       return;
 
-    case MEM_REF:
-      if (TREE_CODE (TREE_OPERAND (expr, 0)) == ADDR_EXPR)
-       tree_to_aff_combination (TREE_OPERAND (TREE_OPERAND (expr, 0), 0),
-                                type, comb);
-      else if (integer_zerop (TREE_OPERAND (expr, 1)))
-       {
-         aff_combination_elt (comb, type, expr);
-         return;
-       }
-      else
-       aff_combination_elt (comb, type,
-                            build2 (MEM_REF, TREE_TYPE (expr),
-                                    TREE_OPERAND (expr, 0),
-                                    build_int_cst
-                                     (TREE_TYPE (TREE_OPERAND (expr, 1)), 0)));
-      tree_to_aff_combination (TREE_OPERAND (expr, 1), sizetype, &tmp);
-      aff_combination_add (comb, &tmp);
-      return;
-
     CASE_CONVERT:
       {
        tree otype = TREE_TYPE (expr);
@@ -721,21 +702,39 @@ aff_combination_expand (aff_tree *comb ATTRIBUTE_UNUSED,
       if (TREE_CODE_CLASS (code) == tcc_reference)
        continue;
 
-      if (!*cache)
-       *cache = new hash_map<tree, name_expansion *>;
-      name_expansion **slot = &(*cache)->get_or_insert (e);
-      exp = *slot;
-
+      name_expansion **slot = NULL;
+      if (*cache)
+       slot = (*cache)->get (name);
+      exp = slot ? *slot : NULL;
       if (!exp)
        {
+         /* Only bother to handle cases tree_to_aff_combination will.  */
+         switch (code)
+           {
+           case POINTER_PLUS_EXPR:
+           case PLUS_EXPR:
+           case MINUS_EXPR:
+           case MULT_EXPR:
+           case NEGATE_EXPR:
+           case BIT_NOT_EXPR:
+           CASE_CONVERT:
+             rhs = gimple_assign_rhs_to_tree (def);
+             break;
+           case ADDR_EXPR:
+           case INTEGER_CST:
+           case POLY_INT_CST:
+             rhs = gimple_assign_rhs1 (def);
+             break;
+           default:
+             continue;
+           }
+         tree_to_aff_combination (rhs, TREE_TYPE (name), &current);
          exp = XNEW (struct name_expansion);
          exp->in_progress = 1;
-         *slot = exp;
-         rhs = gimple_assign_rhs_to_tree (def);
-         if (e != name)
-           rhs = fold_convert (type, rhs);
-
-         tree_to_aff_combination_expand (rhs, comb->type, &current, cache);
+         if (!*cache)
+           *cache = new hash_map<tree, name_expansion *>;
+         (*cache)->put (name, exp);
+         aff_combination_expand (&current, cache);
          exp->expansion = current;
          exp->in_progress = 0;
        }
@@ -746,6 +745,8 @@ aff_combination_expand (aff_tree *comb ATTRIBUTE_UNUSED,
          gcc_assert (!exp->in_progress);
          current = exp->expansion;
        }
+      if (!useless_type_conversion_p (comb->type, current.type))
+       aff_combination_convert (&current, comb->type);
 
       /* Accumulate the new terms to TO_ADD, so that we do not modify
         COMB while traversing it; include the term -coef * E, to remove