From patchwork Tue Aug 17 17:00:19 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Pop X-Patchwork-Id: 61939 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 0020BB70B8 for ; Wed, 18 Aug 2010 03:01:11 +1000 (EST) Received: (qmail 25466 invoked by alias); 17 Aug 2010 17:01:06 -0000 Received: (qmail 25397 invoked by uid 22791); 17 Aug 2010 17:01:04 -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-px0-f175.google.com (HELO mail-px0-f175.google.com) (209.85.212.175) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 17 Aug 2010 17:00:55 +0000 Received: by pxi11 with SMTP id 11so2458128pxi.20 for ; Tue, 17 Aug 2010 10:00:53 -0700 (PDT) Received: by 10.142.153.6 with SMTP id a6mr6134008wfe.70.1282064453387; Tue, 17 Aug 2010 10:00:53 -0700 (PDT) Received: from napoca ([163.181.251.115]) by mx.google.com with ESMTPS id w4sm8088372wfd.8.2010.08.17.10.00.50 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 17 Aug 2010 10:00:52 -0700 (PDT) Received: by napoca (sSMTP sendmail emulation); Tue, 17 Aug 2010 12:00:49 -0500 From: Sebastian Pop To: gcc-patches@gcc.gnu.org Cc: rguenther@suse.de, Sebastian Pop Subject: [PATCH 3/3] Speed-up ifcvt_memrefs_wont_trap caching previous results. Date: Tue, 17 Aug 2010 12:00:19 -0500 Message-Id: <1282064419-13251-3-git-send-email-sebpop@gmail.com> In-Reply-To: <1282064419-13251-1-git-send-email-sebpop@gmail.com> References: <1282064419-13251-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. (IFC_DR): New. (DR_WRITTEN_AT_LEAST_ONCE): New. (DR_RW_UNCONDITIONALLY): 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 | 64 ++++++++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 60 insertions(+), 4 deletions(-) diff --git a/gcc/tree-if-conv.c b/gcc/tree-if-conv.c index 1cf53f5..f215e97 100644 --- a/gcc/tree-if-conv.c +++ b/gcc/tree-if-conv.c @@ -446,6 +446,21 @@ 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 written_at_least_once; + + /* -1 when not initialized, 0 when false, 1 when true. */ + int rw_unconditionally; +}; + +#define IFC_DR(DR) ((struct ifc_dr *) (DR)->aux) +#define DR_WRITTEN_AT_LEAST_ONCE(DR) (IFC_DR (DR)->written_at_least_once) +#define DR_RW_UNCONDITIONALLY(DR) (IFC_DR (DR)->rw_unconditionally) + /* Returns true when the memory reference A at position POS in the data references vector DRS and executed under the condition CA, is read or written unconditionally. In other words, this function @@ -461,18 +476,28 @@ memref_read_or_written_unconditionally (int pos, data_reference_p a, { int i; data_reference_p b; + int x = DR_RW_UNCONDITIONALLY (a); + + 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 (DR_RW_UNCONDITIONALLY (b) == 1 + || is_true_predicate (cb) || is_true_predicate (ca = fold_or_predicates (EXPR_LOCATION (cb), ca, cb))) - return true; + { + DR_RW_UNCONDITIONALLY (a) = 1; + DR_RW_UNCONDITIONALLY (b) = 1; + return true; + } } + DR_RW_UNCONDITIONALLY (a) = 0; return false; } @@ -507,6 +532,10 @@ write_memref_written_at_least_once (int pos, data_reference_p a, { int i; data_reference_p b; + int x = DR_WRITTEN_AT_LEAST_ONCE (a); + + if (x != -1) + return x; for (i = 0; VEC_iterate (data_reference_p, drs, i, b); i++) if (i != pos @@ -515,12 +544,18 @@ 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 (DR_WRITTEN_AT_LEAST_ONCE (b) == 1 + || is_true_predicate (cb) || is_true_predicate (ca = fold_or_predicates (EXPR_LOCATION (cb), ca, cb))) - return true; + { + DR_WRITTEN_AT_LEAST_ONCE (a) = 1; + DR_WRITTEN_AT_LEAST_ONCE (b) = 1; + return true; + } } + DR_WRITTEN_AT_LEAST_ONCE (a) = 0; return false; } @@ -984,6 +1019,18 @@ if_convertible_loop_p_1 (struct loop *loop, if (!res) return false; + if (flag_tree_loop_if_convert_memory_writes) + { + data_reference_p dr; + + for (i = 0; VEC_iterate (data_reference_p, *refs, i, dr); i++) + { + dr->aux = XNEW (struct ifc_dr); + DR_WRITTEN_AT_LEAST_ONCE (dr) = -1; + DR_RW_UNCONDITIONALLY (dr) = -1; + } + } + for (i = 0; i < loop->num_nodes; i++) { basic_block bb = ifc_bbs[i]; @@ -1057,6 +1104,15 @@ if_convertible_loop_p (struct loop *loop) ddrs = VEC_alloc (ddr_p, heap, 25); res = if_convertible_loop_p_1 (loop, &refs, &ddrs); + if (flag_tree_loop_if_convert_memory_writes) + { + data_reference_p dr; + unsigned int i; + + 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;