+2012-10-09 Venkataramanan Kumar <venkataramanan.kumar@amd.com>
+
+ PR middle-end/53397
+ * tree-ssa-loop-prefetch.c (gather_memory_references_ref):
+ Perform non constant step prefetching in inner loop, only
+ when it is invariant in the entire loop nest.
+ * tree-ssa-loop-prefetch.c (dump_mem_details): New function to dump
+ base, step and delta values of memeory reference analysed for
+ prefetching.
+ * tree-ssa-loop-prefetch.c (dump_mem_ref): Call dump_mem_details
+ to print base, step and delta values of memory reference.
+ * cfgloop.h (loop_outermost): New function that returns outermost
+ loop for a given loop in a loop nest.
+ * testsuite/gcc.dg/pr53397-1.c: New test case
+ Checks we are prefecthing for loop invariant steps
+ * testsuite/gcc.dg/pr53397-2.c: New test case
+ Checks we are not prefecthing for loop variant steps
+
2012-10-09 Richard Guenther <rguenther@suse.de>
PR middle-end/54837
nontemporal one. */
};
-/* Dumps information about reference REF to FILE. */
-
+/* Dumps information about memory reference */
static void
-dump_mem_ref (FILE *file, struct mem_ref *ref)
+dump_mem_details (FILE *file, tree base, tree step,
+ HOST_WIDE_INT delta, bool write_p)
{
- fprintf (file, "Reference %p:\n", (void *) ref);
-
- fprintf (file, " group %p (base ", (void *) ref->group);
- print_generic_expr (file, ref->group->base, TDF_SLIM);
+ fprintf (file, "(base ");
+ print_generic_expr (file, base, TDF_SLIM);
fprintf (file, ", step ");
- if (cst_and_fits_in_hwi (ref->group->step))
- fprintf (file, HOST_WIDE_INT_PRINT_DEC, int_cst_value (ref->group->step));
+ if (cst_and_fits_in_hwi (step))
+ fprintf (file, HOST_WIDE_INT_PRINT_DEC, int_cst_value (step));
else
- print_generic_expr (file, ref->group->step, TDF_TREE);
+ print_generic_expr (file, step, TDF_TREE);
fprintf (file, ")\n");
-
fprintf (file, " delta ");
- fprintf (file, HOST_WIDE_INT_PRINT_DEC, ref->delta);
+ fprintf (file, HOST_WIDE_INT_PRINT_DEC, delta);
fprintf (file, "\n");
+ fprintf (file, " %s\n", write_p ? "write" : "read");
+ fprintf (file, "\n");
+}
- fprintf (file, " %s\n", ref->write_p ? "write" : "read");
+/* Dumps information about reference REF to FILE. */
- fprintf (file, "\n");
+static void
+dump_mem_ref (FILE *file, struct mem_ref *ref)
+{
+ fprintf (file, "Reference %p:\n", (void *) ref);
+
+ fprintf (file, " group %p ", (void *) ref->group);
+
+ dump_mem_details (file, ref->group->base, ref->group->step, ref->delta,
+ ref->write_p);
}
/* Finds a group with BASE and STEP in GROUPS, or creates one if it does not
if (may_be_nonaddressable_p (base))
return false;
- /* Limit non-constant step prefetching only to the innermost loops. */
- if (!cst_and_fits_in_hwi (step) && loop->inner != NULL)
- return false;
+ /* Limit non-constant step prefetching only to the innermost loops and
+ only when the step is loop invariant in the entire loop nest. */
+ if (!cst_and_fits_in_hwi (step))
+ {
+ if (loop->inner != NULL)
+ {
+ if (dump_file && (dump_flags & TDF_DETAILS))
+ {
+ fprintf (dump_file, "Memory expression %p\n",(void *) ref );
+ print_generic_expr (dump_file, ref, TDF_TREE);
+ fprintf (dump_file,":");
+ dump_mem_details( dump_file, base, step, delta, write_p);
+ fprintf (dump_file,
+ "Ignoring %p, non-constant step prefetching is "
+ "limited to inner most loops \n",
+ (void *) ref);
+ }
+ return false;
+ }
+ else
+ {
+ if (!expr_invariant_in_loop_p (loop_outermost (loop), step))
+ {
+ if (dump_file && (dump_flags & TDF_DETAILS))
+ {
+ fprintf (dump_file, "Memory expression %p\n",(void *) ref );
+ print_generic_expr (dump_file, ref, TDF_TREE);
+ fprintf (dump_file,":");
+ dump_mem_details(dump_file, base, step, delta, write_p);
+ fprintf (dump_file,
+ "Not prefetching, ignoring %p due to "
+ "loop variant step\n",
+ (void *) ref);
+ }
+ return false;
+ }
+ }
+ }
/* Now we know that REF = &BASE + STEP * iter + DELTA, where DELTA and STEP
are integer constants. */