From patchwork Thu Oct 28 22:58:18 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Pop X-Patchwork-Id: 69508 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 71119B70D1 for ; Fri, 29 Oct 2010 09:59:14 +1100 (EST) Received: (qmail 7300 invoked by alias); 28 Oct 2010 22:59:11 -0000 Received: (qmail 7136 invoked by uid 22791); 28 Oct 2010 22:59:09 -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_TM, T_TO_NO_BRKTS_FREEMAIL 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; Thu, 28 Oct 2010 22:58:59 +0000 Received: by yxe42 with SMTP id 42so1758523yxe.20 for ; Thu, 28 Oct 2010 15:58:57 -0700 (PDT) Received: by 10.90.8.23 with SMTP id 23mr3430664agh.146.1288306737597; Thu, 28 Oct 2010 15:58:57 -0700 (PDT) Received: from napoca (adsl-76-244-77-0.dsl.austtx.sbcglobal.net [76.244.77.0]) by mx.google.com with ESMTPS id m66sm1145448yha.21.2010.10.28.15.58.53 (version=TLSv1/SSLv3 cipher=RC4-MD5); Thu, 28 Oct 2010 15:58:55 -0700 (PDT) Received: by napoca (sSMTP sendmail emulation); Thu, 28 Oct 2010 17:58:52 -0500 From: Sebastian Pop To: gcc-patches@gcc.gnu.org Cc: rguenther@suse.de, Sebastian Pop Subject: [PATCH 2/6] Remove ifcvt_memrefs_wont_trap analysis. Date: Thu, 28 Oct 2010 17:58:18 -0500 Message-Id: <1288306702-5543-3-git-send-email-sebpop@gmail.com> In-Reply-To: <1288306702-5543-1-git-send-email-sebpop@gmail.com> References: <1288306702-5543-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 2010-10-20 Sebastian Pop * tree-if-conv.c (struct ifc_dr): Removed. (IFC_DR): Removed. (DR_WRITTEN_AT_LEAST_ONCE): Removed. (DR_RW_UNCONDITIONALLY): Removed. (memrefs_read_or_written_unconditionally): Removed. (write_memrefs_written_at_least_once): Removed. (ifcvt_memrefs_wont_trap): Removed. (ifcvt_could_trap_p): Does not take refs parameter anymore. (if_convertible_gimple_assign_stmt_p): Same. (if_convertible_stmt_p): Same. (if_convertible_loop_p_1): Remove initialization of dr->aux, DR_WRITTEN_AT_LEAST_ONCE, and DR_RW_UNCONDITIONALLY. (if_convertible_loop_p): Remove deallocation of the same. --- gcc/ChangeLog | 16 +++++ gcc/tree-if-conv.c | 192 ++------------------------------------------------- 2 files changed, 24 insertions(+), 184 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index a0148d2..4a51a4d 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,5 +1,21 @@ 2010-10-20 Sebastian Pop + * tree-if-conv.c (struct ifc_dr): Removed. + (IFC_DR): Removed. + (DR_WRITTEN_AT_LEAST_ONCE): Removed. + (DR_RW_UNCONDITIONALLY): Removed. + (memrefs_read_or_written_unconditionally): Removed. + (write_memrefs_written_at_least_once): Removed. + (ifcvt_memrefs_wont_trap): Removed. + (ifcvt_could_trap_p): Does not take refs parameter anymore. + (if_convertible_gimple_assign_stmt_p): Same. + (if_convertible_stmt_p): Same. + (if_convertible_loop_p_1): Remove initialization of dr->aux, + DR_WRITTEN_AT_LEAST_ONCE, and DR_RW_UNCONDITIONALLY. + (if_convertible_loop_p): Remove deallocation of the same. + +2010-10-20 Sebastian Pop + * Makefile.in (OBJS-common): Add tree-loop-flattening.o. (tree-loop-flattening.o): New. * common.opt (ftree-loop-flatten): New. diff --git a/gcc/tree-if-conv.c b/gcc/tree-if-conv.c index 642dbda..ec03bf6 100644 --- a/gcc/tree-if-conv.c +++ b/gcc/tree-if-conv.c @@ -446,168 +446,14 @@ 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 references of STMT are read or written - unconditionally. In other words, this function returns true when - for every data reference A in STMT there exist other accesses to - the same data reference with predicates that add up (OR-up) to the - true predicate: this ensures that the data reference A is touched - (read or written) on every iteration of the if-converted loop. */ - -static bool -memrefs_read_or_written_unconditionally (gimple stmt, - VEC (data_reference_p, heap) *drs) -{ - int i, j; - data_reference_p a, b; - tree ca = bb_predicate (gimple_bb (stmt)); - - for (i = 0; VEC_iterate (data_reference_p, drs, i, a); i++) - if (DR_STMT (a) == stmt) - { - bool found = false; - int x = DR_RW_UNCONDITIONALLY (a); - - if (x == 0) - return false; - - if (x == 1) - continue; - - for (j = 0; VEC_iterate (data_reference_p, drs, j, b); j++) - if (DR_STMT (b) != stmt - && same_data_refs (a, b)) - { - tree cb = bb_predicate (gimple_bb (DR_STMT (b))); - - if (DR_RW_UNCONDITIONALLY (b) == 1 - || is_true_predicate (cb) - || is_true_predicate (ca = fold_or_predicates (EXPR_LOCATION (cb), - ca, cb))) - { - DR_RW_UNCONDITIONALLY (a) = 1; - DR_RW_UNCONDITIONALLY (b) = 1; - found = true; - break; - } - } - - if (!found) - { - DR_RW_UNCONDITIONALLY (a) = 0; - return false; - } - } - - return true; -} - -/* Returns true when the memory references of STMT are unconditionally - written. In other words, this function returns true when for every - data reference A written in STMT, there exist other writes to the - same data reference with predicates that add up (OR-up) to the true - predicate: this ensures that the data reference A is written on - every iteration of the if-converted loop. */ - -static bool -write_memrefs_written_at_least_once (gimple stmt, - VEC (data_reference_p, heap) *drs) -{ - int i, j; - data_reference_p a, b; - tree ca = bb_predicate (gimple_bb (stmt)); - - for (i = 0; VEC_iterate (data_reference_p, drs, i, a); i++) - if (DR_STMT (a) == stmt - && DR_IS_WRITE (a)) - { - bool found = false; - int x = DR_WRITTEN_AT_LEAST_ONCE (a); - - if (x == 0) - return false; - - if (x == 1) - continue; - - for (j = 0; VEC_iterate (data_reference_p, drs, j, b); j++) - if (DR_STMT (b) != stmt - && DR_IS_WRITE (b) - && same_data_refs_base_objects (a, b)) - { - tree cb = bb_predicate (gimple_bb (DR_STMT (b))); - - if (DR_WRITTEN_AT_LEAST_ONCE (b) == 1 - || is_true_predicate (cb) - || is_true_predicate (ca = fold_or_predicates (EXPR_LOCATION (cb), - ca, cb))) - { - DR_WRITTEN_AT_LEAST_ONCE (a) = 1; - DR_WRITTEN_AT_LEAST_ONCE (b) = 1; - found = true; - break; - } - } - - if (!found) - { - DR_WRITTEN_AT_LEAST_ONCE (a) = 0; - return false; - } - } - - return true; -} - -/* Return true when the memory references of STMT won't trap in the - if-converted code. There are two things that we have to check for: - - - writes to memory occur to writable memory: if-conversion of - memory writes transforms the conditional memory writes into - unconditional writes, i.e. "if (cond) A[i] = foo" is transformed - into "A[i] = cond ? foo : A[i]", and as the write to memory may not - be executed at all in the original code, it may be a readonly - memory. To check that A is not const-qualified, we check that - there exists at least an unconditional write to A in the current - function. - - - reads or writes to memory are valid memory accesses for every - iteration. To check that the memory accesses are correctly formed - and that we are allowed to read and write in these locations, we - check that the memory accesses to be if-converted occur at every - iteration unconditionally. */ - -static bool -ifcvt_memrefs_wont_trap (gimple stmt, VEC (data_reference_p, heap) *refs) -{ - return write_memrefs_written_at_least_once (stmt, refs) - && memrefs_read_or_written_unconditionally (stmt, refs); -} - /* Wrapper around gimple_could_trap_p refined for the needs of the - if-conversion. Try to prove that the memory accesses of STMT could - not trap in the innermost loop containing STMT. */ + if-conversion. */ static bool -ifcvt_could_trap_p (gimple stmt, VEC (data_reference_p, heap) *refs) +ifcvt_could_trap_p (gimple stmt) { if (gimple_vuse (stmt) - && !gimple_could_trap_p_1 (stmt, false, false) - && ifcvt_memrefs_wont_trap (stmt, refs)) + && !gimple_could_trap_p_1 (stmt, false, false)) return false; return gimple_could_trap_p (stmt); @@ -621,8 +467,7 @@ ifcvt_could_trap_p (gimple stmt, VEC (data_reference_p, heap) *refs) - LHS is not var decl. */ static bool -if_convertible_gimple_assign_stmt_p (gimple stmt, - VEC (data_reference_p, heap) *refs) +if_convertible_gimple_assign_stmt_p (gimple stmt) { tree lhs = gimple_assign_lhs (stmt); basic_block bb; @@ -650,7 +495,7 @@ if_convertible_gimple_assign_stmt_p (gimple stmt, if (flag_tree_loop_if_convert_stores) { - if (ifcvt_could_trap_p (stmt, refs)) + if (ifcvt_could_trap_p (stmt)) { if (dump_file && (dump_flags & TDF_DETAILS)) fprintf (dump_file, "tree could trap...\n"); @@ -690,7 +535,7 @@ if_convertible_gimple_assign_stmt_p (gimple stmt, - it is a GIMPLE_LABEL or a GIMPLE_COND. */ static bool -if_convertible_stmt_p (gimple stmt, VEC (data_reference_p, heap) *refs) +if_convertible_stmt_p (gimple stmt) { switch (gimple_code (stmt)) { @@ -700,7 +545,7 @@ if_convertible_stmt_p (gimple stmt, VEC (data_reference_p, heap) *refs) return true; case GIMPLE_ASSIGN: - return if_convertible_gimple_assign_stmt_p (stmt, refs); + return if_convertible_gimple_assign_stmt_p (stmt); default: /* Don't know what to do with 'em so don't do anything. */ @@ -1016,18 +861,6 @@ if_convertible_loop_p_1 (struct loop *loop, if (!res) return false; - if (flag_tree_loop_if_convert_stores) - { - 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]; @@ -1040,7 +873,7 @@ if_convertible_loop_p_1 (struct loop *loop, /* Check the if-convertibility of statements in predicated BBs. */ if (is_predicated (bb)) for (itr = gsi_start_bb (bb); !gsi_end_p (itr); gsi_next (&itr)) - if (!if_convertible_stmt_p (gsi_stmt (itr), *refs)) + if (!if_convertible_stmt_p (gsi_stmt (itr))) return false; } @@ -1101,15 +934,6 @@ 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_stores) - { - 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;