From 9d9610b1f1add2ab68c463361510a53072f2d394 Mon Sep 17 00:00:00 2001 From: Changpeng Fang Date: Mon, 26 Apr 2010 14:57:04 -0700 Subject: [PATCH 7/7] Don't generate prefetches for loops with small trip counts. * tree-ssa-loop-prefetch.c (PREFETCH_MIN_LOOP_TRIP_COUNT): New. (is_loop_prefetching_profitable): Don't generate prefetches for loops with small trip counts. --- gcc/tree-ssa-loop-prefetch.c | 12 +++++++++++- 1 files changed, 11 insertions(+), 1 deletions(-) diff --git a/gcc/tree-ssa-loop-prefetch.c b/gcc/tree-ssa-loop-prefetch.c index 687bc10..afbdc28 100644 --- a/gcc/tree-ssa-loop-prefetch.c +++ b/gcc/tree-ssa-loop-prefetch.c @@ -209,6 +209,10 @@ along with GCC; see the file COPYING3. If not see prefetching. */ #define TRIP_COUNT_TO_AHEAD_RATIO 2 +/* Don't generate prefetches when the loop trip count is smaller than + PREFETCH_MIN_LOOP_TRIP_COUNT. */ +#define PREFETCH_MIN_LOOP_TRIP_COUNT 5 + /* The group of references between that reuse may occur. */ struct mem_ref_group @@ -1600,7 +1604,13 @@ is_loop_prefetching_profitable (unsigned ahead, HOST_WIDE_INT est_niter, else if (est_niter < 0) return true; - if (est_niter < (HOST_WIDE_INT) (TRIP_COUNT_TO_AHEAD_RATIO * ahead)) + /* If the loop trip count is too small, loop prefetch is not likely + to be effective. For these cases, the size of the loop body is + usually big, and basic-block prefetch may be more appropriate + where prefetch instruction can be scheduled more precisely inside + the basic block. */ + if (est_niter < (HOST_WIDE_INT) (TRIP_COUNT_TO_AHEAD_RATIO * ahead) + || est_niter < PREFETCH_MIN_LOOP_TRIP_COUNT) { if (dump_file && (dump_flags & TDF_DETAILS)) fprintf (dump_file, -- 1.6.3.3