static bitmap_obstack lim_bitmap_obstack;
static obstack mem_ref_obstack;
-static bool ref_indep_loop_p (struct loop *, im_mem_ref *);
+static bool ref_indep_loop_p (struct loop *, im_mem_ref *, struct loop *);
/* Minimum cost of an expensive expression. */
#define LIM_EXPENSIVE ((unsigned) PARAM_VALUE (PARAM_LIM_EXPENSIVE))
aloop != loop;
aloop = superloop_at_depth (loop, loop_depth (aloop) + 1))
if ((!ref->stored || !bitmap_bit_p (ref->stored, aloop->num))
- && ref_indep_loop_p (aloop, ref))
+ && ref_indep_loop_p (aloop, ref, loop))
return aloop;
- if (ref_indep_loop_p (loop, ref))
+ if (ref_indep_loop_p (loop, ref, loop))
return loop;
else
return NULL;
loop = loop_outer (loop);
}
-/* Returns true if REF in REF_LOOP is independent on all other memory
- references in LOOP. */
+/* Returns true if REF is independent on all other memory
+ references in LOOP. REF_LOOP is where REF is accessed, SAFELEN is the
+ safelen to apply. */
static bool
-ref_indep_loop_p_1 (int safelen, struct loop *loop,
- im_mem_ref *ref, bool stored_p)
+ref_indep_loop_p_1 (int safelen, struct loop *loop, im_mem_ref *ref,
+ bool stored_p, struct loop *ref_loop)
{
+ stored_p |= (ref->stored && bitmap_bit_p (ref->stored, loop->num));
+
+ if (loop->safelen > safelen
+ /* Check that REF is accessed inside LOOP. */
+ && (loop == ref_loop || flow_loop_nested_p (loop, ref_loop)))
+ safelen = loop->safelen;
+
+ bool indep_p = true;
bitmap refs_to_check;
- unsigned i;
- bitmap_iterator bi;
- im_mem_ref *aref;
if (stored_p)
refs_to_check = &memory_accesses.refs_in_loop[loop->num];
refs_to_check = &memory_accesses.refs_stored_in_loop[loop->num];
if (bitmap_bit_p (refs_to_check, UNANALYZABLE_MEM_ID))
- return false;
-
- if (safelen > 1)
+ indep_p = false;
+ else if (safelen > 1)
{
if (dump_file && (dump_flags & TDF_DETAILS))
{
print_generic_expr (dump_file, ref->mem.ref, TDF_SLIM);
fprintf (dump_file, "\n");
}
+
+ /* Avoid caching here as safelen depends on context and refs
+ are shared between different contexts. */
return true;
}
-
- EXECUTE_IF_SET_IN_BITMAP (refs_to_check, 0, i, bi)
+ else
{
- aref = memory_accesses.refs_list[i];
- if (!refs_independent_p (ref, aref))
+ if (bitmap_bit_p (&ref->indep_loop, LOOP_DEP_BIT (loop->num, stored_p)))
+ return true;
+ if (bitmap_bit_p (&ref->dep_loop, LOOP_DEP_BIT (loop->num, stored_p)))
return false;
- }
-
- return true;
-}
-
-/* Returns true if REF in REF_LOOP is independent on all other memory
- references in LOOP. Wrapper over ref_indep_loop_p_1, caching its
- results. */
-
-static bool
-ref_indep_loop_p_2 (int safelen, struct loop *loop,
- im_mem_ref *ref, bool stored_p)
-{
- stored_p |= (ref->stored && bitmap_bit_p (ref->stored, loop->num));
- if (bitmap_bit_p (&ref->indep_loop, LOOP_DEP_BIT (loop->num, stored_p)))
- return true;
- if (bitmap_bit_p (&ref->dep_loop, LOOP_DEP_BIT (loop->num, stored_p)))
- return false;
-
- if (loop->safelen > safelen)
- safelen = loop->safelen;
+ struct loop *inner = loop->inner;
+ while (inner)
+ {
+ if (!ref_indep_loop_p_1 (safelen, inner, ref, stored_p, ref_loop))
+ {
+ indep_p = false;
+ break;
+ }
+ inner = inner->next;
+ }
- struct loop *inner = loop->inner;
- while (inner)
- {
- if (!ref_indep_loop_p_2 (safelen, inner, ref, stored_p))
- return false;
- inner = inner->next;
+ if (indep_p)
+ {
+ unsigned i;
+ bitmap_iterator bi;
+ EXECUTE_IF_SET_IN_BITMAP (refs_to_check, 0, i, bi)
+ {
+ im_mem_ref *aref = memory_accesses.refs_list[i];
+ if (!refs_independent_p (ref, aref))
+ {
+ indep_p = false;
+ break;
+ }
+ }
+ }
}
- bool indep_p = ref_indep_loop_p_1 (safelen, loop, ref, stored_p);
-
if (dump_file && (dump_flags & TDF_DETAILS))
fprintf (dump_file, "Querying dependencies of ref %u in loop %d: %s\n",
ref->id, loop->num, indep_p ? "independent" : "dependent");
}
/* Returns true if REF is independent on all other memory references in
- LOOP. */
+ LOOP. REF_LOOP is the loop where REF is accessed. */
static bool
-ref_indep_loop_p (struct loop *loop, im_mem_ref *ref)
+ref_indep_loop_p (struct loop *loop, im_mem_ref *ref, struct loop *ref_loop)
{
gcc_checking_assert (MEM_ANALYZABLE (ref));
- return ref_indep_loop_p_2 (0, loop, ref, false);
+ return ref_indep_loop_p_1 (0, loop, ref, false, ref_loop);
}
/* Returns true if we can perform store motion of REF from LOOP. */
/* And it must be independent on all other memory references
in LOOP. */
- if (!ref_indep_loop_p (loop, ref))
+ if (!ref_indep_loop_p (loop, ref, loop))
return false;
return true;