This avoids redundant ref finding.

Bootstrapped and tested on x86_64-unknown-linux-gnu, applied.

Richard.

2017-08-21  Richard Biener  <rguent...@suse.de>

        * tree-ssa-loop-im.c (struct lim_aux_data): Add ref index member.
        (mem_ref_in_stmt): Remove.
        (determine_max_movement): Use ref index to get at the reference.
        (invariantness_dom_walker::before_dom_children): Deal with
        lim data already initialized.
        (gather_mem_refs_stmt): Initialize lim data and record ref index.

Index: gcc/tree-ssa-loop-im.c
===================================================================
--- gcc/tree-ssa-loop-im.c      (revision 251179)
+++ gcc/tree-ssa-loop-im.c      (working copy)
@@ -86,7 +86,9 @@ struct lim_aux_data
   unsigned cost;               /* Cost of the computation performed by the
                                   statement.  */
 
-  vec<gimple *> depends;               /* Vector of statements that must be 
also
+  unsigned ref;                        /* The simple_mem_ref in this stmt or 
0.  */
+
+  vec<gimple *> depends;       /* Vector of statements that must be also
                                   hoisted out of the loop when this statement
                                   is hoisted; i.e. those that define the
                                   operands of the statement and are inside of
@@ -586,27 +588,6 @@ simple_mem_ref_in_stmt (gimple *stmt, bo
     return NULL;
 }
 
-/* Returns the memory reference contained in STMT.  */
-
-static im_mem_ref *
-mem_ref_in_stmt (gimple *stmt)
-{
-  bool store;
-  tree *mem = simple_mem_ref_in_stmt (stmt, &store);
-  hashval_t hash;
-  im_mem_ref *ref;
-
-  if (!mem)
-    return NULL;
-  gcc_assert (!store);
-
-  hash = iterative_hash_expr (*mem, 0);
-  ref = memory_accesses.refs->find_with_hash (*mem, hash);
-
-  gcc_assert (ref != NULL);
-  return ref;
-}
-
 /* From a controlling predicate in DOM determine the arguments from
    the PHI node PHI that are chosen if the predicate evaluates to
    true and false and store them to *TRUE_ARG_P and *FALSE_ARG_P if
@@ -747,23 +728,18 @@ determine_max_movement (gimple *stmt, bo
 
   if (gimple_vuse (stmt))
     {
-      im_mem_ref *ref = mem_ref_in_stmt (stmt);
-
-      if (ref)
+      im_mem_ref *ref
+       = lim_data ? memory_accesses.refs_list[lim_data->ref] : NULL;
+      if (ref
+         && MEM_ANALYZABLE (ref))
        {
-         lim_data->max_loop
-                 = outermost_indep_loop (lim_data->max_loop, loop, ref);
+         lim_data->max_loop = outermost_indep_loop (lim_data->max_loop,
+                                                    loop, ref);
          if (!lim_data->max_loop)
            return false;
        }
-      else
-       {
-         if ((val = gimple_vuse (stmt)) != NULL_TREE)
-           {
-             if (!add_dependency (val, lim_data, loop, false))
-               return false;
-           }
-       }
+      else if (! add_dependency (gimple_vuse (stmt), lim_data, loop, false))
+       return false;
     }
 
   lim_data->cost += stmt_cost (stmt);
@@ -1000,7 +976,9 @@ invariantness_dom_walker::before_dom_chi
        if (pos == MOVE_IMPOSSIBLE)
          continue;
 
-       lim_data = init_lim_data (stmt);
+       lim_data = get_lim_data (stmt);
+       if (! lim_data)
+         lim_data = init_lim_data (stmt);
        lim_data->always_executed_in = outermost;
 
        if (!determine_max_movement (stmt, false))
@@ -1037,7 +1015,9 @@ invariantness_dom_walker::before_dom_chi
             store-motion work.  */
          else if (stmt_makes_single_store (stmt))
            {
-             struct lim_aux_data *lim_data = init_lim_data (stmt);
+             struct lim_aux_data *lim_data = get_lim_data (stmt);
+             if (! lim_data)
+               lim_data = init_lim_data (stmt);
              lim_data->always_executed_in = outermost;
            }
          continue;
@@ -1073,7 +1053,9 @@ invariantness_dom_walker::before_dom_chi
            stmt = rewrite_bittest (&bsi);
        }
 
-      lim_data = init_lim_data (stmt);
+      lim_data = get_lim_data (stmt);
+      if (! lim_data)
+       lim_data = init_lim_data (stmt);
       lim_data->always_executed_in = outermost;
 
       if (maybe_never && pos == MOVE_PRESERVE_EXECUTION)
@@ -1498,6 +1480,7 @@ gather_mem_refs_stmt (struct loop *loop,
       bitmap_set_bit (&memory_accesses.refs_stored_in_loop[loop->num], 
ref->id);
       mark_ref_stored (ref, loop);
     }
+  init_lim_data (stmt)->ref = ref->id;
   return;
 }
 

Reply via email to