From patchwork Thu Jul 1 18:41:34 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [for,suggestions] : How do we know a loop is the peeled version? Date: Thu, 01 Jul 2010 08:41:34 -0000 From: "Fang, Changpeng" X-Patchwork-Id: 57567 Message-Id: To: Richard Guenther , Sebastian Pop Cc: Zdenek Dvorak , Christian Borntraeger , "gcc-patches@gcc.gnu.org" , "uweigand@de.ibm.com" Hi, Just found that many optimizations (prefetch, loop unrolling) are performed on the peeled loops. This causes code size and compilation time increase without benefit. MODULE kinds INTEGER, PARAMETER :: RK8 = SELECTED_REAL_KIND(15, 300) END MODULE kinds ! -------------------------------------------------------------------- PROGRAM TEST_FPU ! A number-crunching benchmark using matrix inversion. USE kinds ! Implemented by: David Frank Dave_Frank@hotmail.com IMPLICIT NONE ! Gauss routine by: Tim Prince N8TM@aol.com ! Crout routine by: James Van Buskirk torsop@ix.netcom.com ! Lapack routine by: Jos Bergervoet bergervo@IAEhv.nl REAL(RK8) :: pool(101, 101,1000), a(101, 101) INTEGER :: i DO i = 1,1000 a = pool(:,:,i) ! get next matrix to invert END DO END PROGRAM TEST_FPU For this example (-O3 -fprefetch-loop-arrays -funroll-loops), the vectorizer peels the loop. And the prefetching and loop unrolling are performed on the peeled loops. In the attached patch, the vectorizer marked the loop as peeled, and the prefetching gives up. However, the RTL unroller could not get this information and still unroll the peeled loop. I need suggestion: How the optimizer recognizes that the loop is the peeled version (preloop or postloop)? Thanks, Changpeng >From 17fa894c3056bfdf76af19e7ca1d685b9aa4a881 Mon Sep 17 00:00:00 2001 From: Changpeng Fang Date: Thu, 1 Jul 2010 11:27:21 -0700 Subject: [PATCH] Marking peeled loop * cfgloop.h : add peeled filed for loop structure. * tree-vect-loop-manip.c (vect_do_peeling_for_loop_bound): mark new_loop as peeled. * tree-ssa-loop-prefetch.c (loop_prefetch_arrays): Do not do loop prefetch for peeled loop. --- gcc/cfgloop.h | 2 ++ gcc/tree-ssa-loop-prefetch.c | 4 ++++ gcc/tree-vect-loop-manip.c | 1 + 3 files changed, 7 insertions(+), 0 deletions(-) diff --git a/gcc/cfgloop.h b/gcc/cfgloop.h index 3821ee6..f43d6df 100644 --- a/gcc/cfgloop.h +++ b/gcc/cfgloop.h @@ -166,6 +166,8 @@ struct GTY ((chain_next ("%h.next"))) loop { /* Head of the cyclic list of the exits of the loop. */ struct loop_exit *exits; + bool peeled; + /* The single induction variable of the loop when the loop is in normal form. */ tree single_iv; diff --git a/gcc/tree-ssa-loop-prefetch.c b/gcc/tree-ssa-loop-prefetch.c index cde5e18..8a219c3 100644 --- a/gcc/tree-ssa-loop-prefetch.c +++ b/gcc/tree-ssa-loop-prefetch.c @@ -1724,6 +1724,10 @@ loop_prefetch_arrays (struct loop *loop) return false; } + /* Don't do prefetching for peeled loop. */ + if (loop->peeled) + return false; + /* Step 1: gather the memory references. */ refs = gather_memory_references (loop, &no_other_refs, &mem_ref_count); diff --git a/gcc/tree-vect-loop-manip.c b/gcc/tree-vect-loop-manip.c index 8289b36..6bf54f5 100644 --- a/gcc/tree-vect-loop-manip.c +++ b/gcc/tree-vect-loop-manip.c @@ -1905,6 +1905,7 @@ vect_do_peeling_for_loop_bound (loop_vec_info loop_vinfo, tree *ratio, cond_expr, cond_expr_stmt_list); gcc_assert (new_loop); gcc_assert (loop_num == loop->num); + new_loop->peeled = true; #ifdef ENABLE_CHECKING slpeel_verify_cfg_after_peeling (loop, new_loop); #endif -- 1.6.3.3