From patchwork Thu Jul 8 21:41:25 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Pop X-Patchwork-Id: 58305 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 A72CDB6EED for ; Fri, 9 Jul 2010 07:42:14 +1000 (EST) Received: (qmail 15631 invoked by alias); 8 Jul 2010 21:42:09 -0000 Received: (qmail 15348 invoked by uid 22791); 8 Jul 2010 21:42:06 -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, T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: sourceware.org Received: from mail-pw0-f47.google.com (HELO mail-pw0-f47.google.com) (209.85.160.47) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 08 Jul 2010 21:42:00 +0000 Received: by pwi10 with SMTP id 10so527334pwi.20 for ; Thu, 08 Jul 2010 14:41:58 -0700 (PDT) Received: by 10.114.190.20 with SMTP id n20mr10230183waf.10.1278625318461; Thu, 08 Jul 2010 14:41:58 -0700 (PDT) Received: from napoca ([163.181.251.115]) by mx.google.com with ESMTPS id c10sm2043027wam.1.2010.07.08.14.41.55 (version=TLSv1/SSLv3 cipher=RC4-MD5); Thu, 08 Jul 2010 14:41:57 -0700 (PDT) Received: by napoca (sSMTP sendmail emulation); Thu, 08 Jul 2010 16:41:54 -0500 From: Sebastian Pop To: gcc-patches@gcc.gnu.org Cc: rguenther@suse.de, matz@suse.de, Sebastian Pop Subject: [PATCH 4/4] Speed-up ifcvt_memrefs_wont_trap caching previous results. Date: Thu, 8 Jul 2010 16:41:25 -0500 Message-Id: <1278625285-12667-5-git-send-email-sebpop@gmail.com> In-Reply-To: <1278625285-12667-1-git-send-email-sebpop@gmail.com> References: <1278625285-12667-1-git-send-email-sebpop@gmail.com> 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 This patch speeds up the ifcvt_memrefs_wont_trap computation by caching the results of the computations in the data references ->aux fields. * tree-if-conv.c (struct ifc_dr): New. (memref_read_or_written_unconditionally): Use the cached values when possible. (write_memref_written_at_least_once): Same. (if_convertible_loop_p): Initialize and free DR->aux fields. --- gcc/tree-if-conv.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 49 insertions(+), 4 deletions(-) diff --git a/gcc/tree-if-conv.c b/gcc/tree-if-conv.c index f0bc026..655c168 100644 --- a/gcc/tree-if-conv.c +++ b/gcc/tree-if-conv.c @@ -441,6 +441,17 @@ if_convertible_phi_p (struct loop *loop, basic_block bb, gimple phi) return true; } +/* Records the status of a data reference. This struct is attached to + each DR->aux field. */ + +struct ifc_dr { + /* -1 when not initialized, 0 when false, 1 when true. */ + int dr_is_written_at_least_once; + + /* -1 when not initialized, 0 when false, 1 when true. */ + int dr_is_rw_unconditionally; +}; + /* Returns true when the memory reference A at position P in the data references vector DRS and executed under the condition CA, is read or written unconditionally. */ @@ -452,17 +463,27 @@ memref_read_or_written_unconditionally (int pos, data_reference_p a, { int i; data_reference_p b; + int x = ((struct ifc_dr *) a->aux)->dr_is_rw_unconditionally; + + if (x != -1) + return x; for (i = 0; VEC_iterate (data_reference_p, drs, i, b); i++) if (i != pos && same_data_refs (a, b)) { tree cb = bb_predicate (gimple_bb (DR_STMT (b))); - if (is_true_predicate (cb) + if (((struct ifc_dr *) b->aux)->dr_is_rw_unconditionally == 1 + || is_true_predicate (cb) || is_true_predicate (ca = fold_or_predicates (ca, cb))) - return true; + { + ((struct ifc_dr *) a->aux)->dr_is_rw_unconditionally = 1; + ((struct ifc_dr *) b->aux)->dr_is_rw_unconditionally = 1; + return true; + } } + ((struct ifc_dr *) a->aux)->dr_is_rw_unconditionally = 0; return false; } @@ -497,6 +518,10 @@ write_memref_written_at_least_once (int pos, data_reference_p a, { int i; data_reference_p b; + int x = ((struct ifc_dr *) a->aux)->dr_is_written_at_least_once; + + if (x != -1) + return x; for (i = 0; VEC_iterate (data_reference_p, drs, i, b); i++) if (i != pos @@ -505,11 +530,17 @@ write_memref_written_at_least_once (int pos, data_reference_p a, { tree cb = bb_predicate (gimple_bb (DR_STMT (b))); - if (is_true_predicate (cb) + if (((struct ifc_dr *) b->aux)->dr_is_written_at_least_once == 1 + || is_true_predicate (cb) || is_true_predicate (ca = fold_or_predicates (ca, cb))) - return true; + { + ((struct ifc_dr *) a->aux)->dr_is_written_at_least_once = 1; + ((struct ifc_dr *) b->aux)->dr_is_written_at_least_once = 1; + return true; + } } + ((struct ifc_dr *) a->aux)->dr_is_written_at_least_once = 0; return false; } @@ -972,6 +1003,7 @@ if_convertible_loop_p (struct loop *loop) edge_iterator ei; basic_block exit_bb = NULL; bool res = false; + data_reference_p dr; VEC (data_reference_p, heap) *refs; VEC (ddr_p, heap) *ddrs; @@ -1048,6 +1080,14 @@ if_convertible_loop_p (struct loop *loop) res = false; + if (flag_tree_loop_if_convert_memory_writes) + for (i = 0; VEC_iterate (data_reference_p, refs, i, dr); i++) + { + dr->aux = XNEW (struct ifc_dr); + ((struct ifc_dr *) dr->aux)->dr_is_written_at_least_once = -1; + ((struct ifc_dr *) dr->aux)->dr_is_rw_unconditionally = -1; + } + for (i = 0; i < loop->num_nodes; i++) { basic_block bb = ifc_bbs[i]; @@ -1069,6 +1109,11 @@ if_convertible_loop_p (struct loop *loop) fprintf (dump_file, "Applying if-conversion\n"); cleanup: + + if (flag_tree_loop_if_convert_memory_writes) + for (i = 0; VEC_iterate (data_reference_p, refs, i, dr); i++) + free (dr->aux); + free_data_refs (refs); free_dependence_relations (ddrs); return res;