diff mbox

[PR44297] prefetch improvements to fix 465.tonto from non-constant step prefetching

Message ID D4C76825A6780047854A11E93CDE84D02F772E@SAUSEXMBP01.amd.com
State New
Headers show

Commit Message

Fang, Changpeng June 10, 2010, 5:04 p.m. UTC
Forgot to ask. Is this version ok for trunk? Thanks

Changpeng

Comments

Zdenek Dvorak June 10, 2010, 10:07 p.m. UTC | #1
Hi,

> Forgot to ask. Is this version ok for trunk? Thanks

yes,

Zdenek
Sebastian Pop June 14, 2010, 8:59 p.m. UTC | #2
On Thu, Jun 10, 2010 at 17:07, Zdenek Dvorak <rakdver@kam.mff.cuni.cz> wrote:
> Hi,
>
>> Forgot to ask. Is this version ok for trunk? Thanks
>
> yes,

Committed r160766.
diff mbox

Patch

From bf90074c6aac420955744b7f889fca2024c31876 Mon Sep 17 00:00:00 2001
From: Changpeng Fang <chfang@houghton.(none)>
Date: Mon, 7 Jun 2010 14:57:27 -0700
Subject: [PATCH 2/2] Account prefetch_mod and unroll_factor for the computation of the prefetch count

	*tree-ssa-loop-prefetch.c (nothing_to_prefetch_p): New. Return true
	if no prefetch is going to be generated for a given group.
	(estimate_prefetch_count): Use prefetch_mod and unroll_factor to
        estimate the prefetch_count.
	(loop_prefetch_arrays): Call nothing_to_prefetch_p; estimate the
	prefetch count by considering the unroll_factor and prefetch_mod
	for is_loop_prefetching_profitable.
---
 gcc/tree-ssa-loop-prefetch.c |   36 +++++++++++++++++++++++++++++++-----
 1 files changed, 31 insertions(+), 5 deletions(-)

diff --git a/gcc/tree-ssa-loop-prefetch.c b/gcc/tree-ssa-loop-prefetch.c
index d63ede1..cde5e18 100644
--- a/gcc/tree-ssa-loop-prefetch.c
+++ b/gcc/tree-ssa-loop-prefetch.c
@@ -987,18 +987,39 @@  schedule_prefetches (struct mem_ref_group *groups, unsigned unroll_factor,
   return any;
 }
 
-/* Estimate the number of prefetches in the given GROUPS.  */
+/* Return TRUE if no prefetch is going to be generated
+   in the given GROUPS.  */
+static bool
+nothing_to_prefetch_p (struct mem_ref_group *groups)
+{
+  struct mem_ref *ref;
+
+  for (; groups; groups = groups->next)
+    for (ref = groups->refs; ref; ref = ref->next)
+      if (should_issue_prefetch_p (ref))
+	return false;
+
+  return true;
+}
+
+/* Estimate the number of prefetches in the given GROUPS.
+   UNROLL_FACTOR is the factor by which LOOP was unrolled.  */
 
 static int
-estimate_prefetch_count (struct mem_ref_group *groups)
+estimate_prefetch_count (struct mem_ref_group *groups, unsigned unroll_factor)
 {
   struct mem_ref *ref;
+  unsigned n_prefetches;
   int prefetch_count = 0;
 
   for (; groups; groups = groups->next)
     for (ref = groups->refs; ref; ref = ref->next)
       if (should_issue_prefetch_p (ref))
-	  prefetch_count++;
+	{
+	  n_prefetches = ((unroll_factor + ref->prefetch_mod - 1)
+			  / ref->prefetch_mod);
+	  prefetch_count += n_prefetches;
+	}
 
   return prefetch_count;
 }
@@ -1709,8 +1730,7 @@  loop_prefetch_arrays (struct loop *loop)
   /* Step 2: estimate the reuse effects.  */
   prune_by_reuse (refs);
 
-  prefetch_count = estimate_prefetch_count (refs);
-  if (prefetch_count == 0)
+  if (nothing_to_prefetch_p (refs))
     goto fail;
 
   determine_loop_nest_reuse (loop, refs, no_other_refs);
@@ -1726,6 +1746,12 @@  loop_prefetch_arrays (struct loop *loop)
   ninsns = tree_num_loop_insns (loop, &eni_size_weights);
   unroll_factor = determine_unroll_factor (loop, refs, ninsns, &desc,
 					   est_niter);
+
+  /* Estimate prefetch count for the unrolled loop.  */
+  prefetch_count = estimate_prefetch_count (refs, unroll_factor);
+  if (prefetch_count == 0)
+    goto fail;
+
   if (dump_file && (dump_flags & TDF_DETAILS))
     fprintf (dump_file, "Ahead %d, unroll factor %d, trip count "
 	     HOST_WIDE_INT_PRINT_DEC "\n"
-- 
1.6.3.3