From patchwork Sat Jul 31 15:27:54 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Pop X-Patchwork-Id: 60432 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 71821B70AA for ; Sun, 1 Aug 2010 01:28:40 +1000 (EST) Received: (qmail 2372 invoked by alias); 31 Jul 2010 15:28:36 -0000 Received: (qmail 2145 invoked by uid 22791); 31 Jul 2010 15:28:34 -0000 X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, TW_IV, TW_TM X-Spam-Check-By: sourceware.org Received: from mail-yx0-f175.google.com (HELO mail-yx0-f175.google.com) (209.85.213.175) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 31 Jul 2010 15:28:28 +0000 Received: by yxi11 with SMTP id 11so1024174yxi.20 for ; Sat, 31 Jul 2010 08:28:26 -0700 (PDT) Received: by 10.151.123.19 with SMTP id a19mr4849473ybn.203.1280590106120; Sat, 31 Jul 2010 08:28:26 -0700 (PDT) Received: from napoca (cpe-70-120-196-107.austin.res.rr.com [70.120.196.107]) by mx.google.com with ESMTPS id m12sm3349704ybn.19.2010.07.31.08.28.24 (version=TLSv1/SSLv3 cipher=RC4-MD5); Sat, 31 Jul 2010 08:28:25 -0700 (PDT) Received: by napoca (sSMTP sendmail emulation); Sat, 31 Jul 2010 10:28:22 -0500 From: Sebastian Pop To: Richard Guenther Cc: gcc-patches@gcc.gnu.org, Sebastian Pop Subject: [PATCH 1/3] Add pass_loop_distribute_memset_zero. Date: Sat, 31 Jul 2010 10:27:54 -0500 Message-Id: <1280590076-2581-2-git-send-email-sebpop@gmail.com> In-Reply-To: References: X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org --- gcc/common.opt | 4 +++ gcc/doc/invoke.texi | 22 +++++++++++++++++++- gcc/tree-data-ref.c | 26 ++++++++++++++++++++++++ gcc/tree-data-ref.h | 1 + gcc/tree-loop-distribution.c | 45 +++++++++++++++++++++++++++++------------ 5 files changed, 84 insertions(+), 14 deletions(-) diff --git a/gcc/common.opt b/gcc/common.opt index 41a9838..77cf58e 100644 --- a/gcc/common.opt +++ b/gcc/common.opt @@ -1337,6 +1337,10 @@ ftree-loop-distribution Common Report Var(flag_tree_loop_distribution) Optimization Enable loop distribution on trees +ftree-loop-distribute-memset-zero +Common Report Var(flag_tree_loop_distribute_memset_zero) Optimization +Enable loop distribution of initialization loops using memset zero + ftree-loop-im Common Report Var(flag_tree_loop_im) Init(1) Optimization Enable loop invariant motion on trees diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 73051de..2d61382 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -384,7 +384,7 @@ Objective-C and Objective-C++ Dialects}. -ftree-builtin-call-dce -ftree-ccp -ftree-ch -ftree-copy-prop @gol -ftree-copyrename -ftree-dce -ftree-dominator-opts -ftree-dse @gol -ftree-forwprop -ftree-fre -ftree-loop-if-convert -ftree-loop-im @gol --ftree-phiprop -ftree-loop-distribution @gol +-ftree-phiprop -ftree-loop-distribution -ftree-loop-distribute-memset-zero @gol -ftree-loop-ivcanon -ftree-loop-linear -ftree-loop-optimize @gol -ftree-parallelize-loops=@var{n} -ftree-pre -ftree-pta -ftree-reassoc @gol -ftree-sink -ftree-sra -ftree-switch-conversion @gol @@ -6925,6 +6925,26 @@ DO I = 1, N ENDDO @end smallexample +@item -ftree-loop-distribute-memset-zero +Perform loop distribution of initialization loops and code generate +them with a call to memset zero. For example, the loop +@smallexample +DO I = 1, N + A(I) = 0 + B(I) = A(I) + I +ENDDO +@end smallexample +is transformed to +@smallexample +DO I = 1, N + A(I) = 0 +ENDDO +DO I = 1, N + B(I) = A(I) + I +ENDDO +@end smallexample +and the initialization loop is transformed into a call to memset zero. + @item -ftree-loop-im @opindex ftree-loop-im Perform loop invariant motion on trees. This pass moves only invariants that diff --git a/gcc/tree-data-ref.c b/gcc/tree-data-ref.c index e7aa277..2656350 100644 --- a/gcc/tree-data-ref.c +++ b/gcc/tree-data-ref.c @@ -5038,6 +5038,32 @@ stores_from_loop (struct loop *loop, VEC (gimple, heap) **stmts) free (bbs); } +/* Initialize STMTS with all the statements of LOOP that contain a + store to memory of the form "A[i] = 0". */ + +void +stores_zero_from_loop (struct loop *loop, VEC (gimple, heap) **stmts) +{ + unsigned int i; + basic_block bb; + gimple_stmt_iterator si; + gimple stmt; + tree op; + basic_block *bbs = get_loop_body_in_dom_order (loop); + + for (i = 0; i < loop->num_nodes; i++) + for (bb = bbs[i], si = gsi_start_bb (bb); !gsi_end_p (si); gsi_next (&si)) + if ((stmt = gsi_stmt (si)) + && gimple_vdef (stmt) + && is_gimple_assign (stmt) + && gimple_assign_rhs_code (stmt) == INTEGER_CST + && (op = gimple_assign_rhs1 (stmt)) + && (integer_zerop (op) || real_zerop (op))) + VEC_safe_push (gimple, heap, *stmts, gsi_stmt (si)); + + free (bbs); +} + /* For a data reference REF, return the declaration of its base address or NULL_TREE if the base is not determined. */ diff --git a/gcc/tree-data-ref.h b/gcc/tree-data-ref.h index eff5348..9e18e26 100644 --- a/gcc/tree-data-ref.h +++ b/gcc/tree-data-ref.h @@ -564,6 +564,7 @@ index_in_loop_nest (int var, VEC (loop_p, heap) *loop_nest) } void stores_from_loop (struct loop *, VEC (gimple, heap) **); +void stores_zero_from_loop (struct loop *, VEC (gimple, heap) **); void remove_similar_memory_refs (VEC (gimple, heap) **); bool rdg_defs_used_in_other_loops_p (struct graph *, int); bool have_similar_memory_accesses (gimple, gimple); diff --git a/gcc/tree-loop-distribution.c b/gcc/tree-loop-distribution.c index 099a7fe..920f744 100644 --- a/gcc/tree-loop-distribution.c +++ b/gcc/tree-loop-distribution.c @@ -1184,18 +1184,36 @@ tree_loop_distribution (void) { VEC (gimple, heap) *work_list = VEC_alloc (gimple, heap, 3); - /* With the following working list, we're asking distribute_loop - to separate the stores of the loop: when dependences allow, - it will end on having one store per loop. */ - stores_from_loop (loop, &work_list); - - /* A simple heuristic for cache locality is to not split stores - to the same array. Without this call, an unrolled loop would - be split into as many loops as unroll factor, each loop - storing in the same array. */ - remove_similar_memory_refs (&work_list); - - nb_generated_loops = distribute_loop (loop, work_list); + /* If both flag_tree_loop_distribute_memset_zero and + flag_tree_loop_distribution are set, then only memset_zero is + executed. */ + if (flag_tree_loop_distribute_memset_zero) + { + /* With the following working list, we're asking + distribute_loop to separate from the rest of the loop the + stores of the form "A[i] = 0". */ + stores_zero_from_loop (loop, &work_list); + + /* If there is nothing to be distributed */ + if (VEC_length (gimple, work_list) > 0) + nb_generated_loops = distribute_loop (loop, work_list); + } + else if (flag_tree_loop_distribution) + { + /* With the following working list, we're asking + distribute_loop to separate the stores of the loop: when + dependences allow, it will end on having one store per + loop. */ + stores_from_loop (loop, &work_list); + + /* A simple heuristic for cache locality is to not split + stores to the same array. Without this call, an unrolled + loop would be split into as many loops as unroll factor, + each loop storing in the same array. */ + remove_similar_memory_refs (&work_list); + + nb_generated_loops = distribute_loop (loop, work_list); + } if (dump_file && (dump_flags & TDF_DETAILS)) { @@ -1217,7 +1235,8 @@ tree_loop_distribution (void) static bool gate_tree_loop_distribution (void) { - return flag_tree_loop_distribution != 0; + return flag_tree_loop_distribution + || flag_tree_loop_distribute_memset_zero; } struct gimple_opt_pass pass_loop_distribution =