From patchwork Thu Jan 20 20:25:39 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Pop X-Patchwork-Id: 79760 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 8A914B7103 for ; Fri, 21 Jan 2011 07:25:55 +1100 (EST) Received: (qmail 13352 invoked by alias); 20 Jan 2011 20:25:53 -0000 Received: (qmail 13308 invoked by uid 22791); 20 Jan 2011 20:25:52 -0000 X-SWARE-Spam-Status: No, hits=-2.3 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, TW_TM, T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: sourceware.org Received: from mail-iw0-f175.google.com (HELO mail-iw0-f175.google.com) (209.85.214.175) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 20 Jan 2011 20:25:45 +0000 Received: by iwn8 with SMTP id 8so991183iwn.20 for ; Thu, 20 Jan 2011 12:25:44 -0800 (PST) Received: by 10.42.228.3 with SMTP id jc3mr3228115icb.307.1295555144302; Thu, 20 Jan 2011 12:25:44 -0800 (PST) Received: from napoca ([163.181.251.115]) by mx.google.com with ESMTPS id k38sm6423676ick.9.2011.01.20.12.25.41 (version=TLSv1/SSLv3 cipher=RC4-MD5); Thu, 20 Jan 2011 12:25:43 -0800 (PST) Received: by napoca (sSMTP sendmail emulation); Thu, 20 Jan 2011 14:25:40 -0600 From: Sebastian Pop To: gcc-patches@gcc.gnu.org Cc: rguenther@suse.de, gcc-graphite@googlegroups.com, Sebastian Pop Subject: [PATCH] Do not use a data ref with indices invalid in the loop of the close_phi. Date: Thu, 20 Jan 2011 14:25:39 -0600 Message-Id: <1295555139-3306-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 Hi, This patch solves two more problems from 416.gamess. Checked in the graphite branch. Sebastian 2011-01-20 Sebastian Pop * graphite-sese-to-poly.c (dr_indices_valid_in_loop): New. (close_phi_written_to_memory): Call for_each_index with dr_indices_valid_in_loop. * gfortran.dg/graphite/id-24.f: New. * gfortran.dg/graphite/id-25.f: New. --- gcc/ChangeLog.graphite | 9 ++++ gcc/graphite-sese-to-poly.c | 64 ++++++++++++++++++++++++---- gcc/testsuite/gfortran.dg/graphite/id-24.f | 9 ++++ gcc/testsuite/gfortran.dg/graphite/id-25.f | 10 ++++ 4 files changed, 84 insertions(+), 8 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/graphite/id-24.f create mode 100644 gcc/testsuite/gfortran.dg/graphite/id-25.f diff --git a/gcc/ChangeLog.graphite b/gcc/ChangeLog.graphite index 8a03a39..d211678 100644 --- a/gcc/ChangeLog.graphite +++ b/gcc/ChangeLog.graphite @@ -1,3 +1,12 @@ +2011-01-20 Sebastian Pop + + * graphite-sese-to-poly.c (dr_indices_valid_in_loop): New. + (close_phi_written_to_memory): Call for_each_index with + dr_indices_valid_in_loop. + + * gfortran.dg/graphite/id-24.f: New. + * gfortran.dg/graphite/id-25.f: New. + 2011-01-19 Sebastian Pop * graphite-sese-to-poly.c (new_pbb_from_pbb): Only copy PBB_DOMAIN diff --git a/gcc/graphite-sese-to-poly.c b/gcc/graphite-sese-to-poly.c index 48ae6df..4561537 100644 --- a/gcc/graphite-sese-to-poly.c +++ b/gcc/graphite-sese-to-poly.c @@ -2999,6 +2999,35 @@ remove_phi (gimple phi) remove_phi_node (&gsi, false); } +/* Helper function for for_each_index. For each INDEX of the data + reference REF, returns true when its indices are valid in the loop + nest LOOP passed in as DATA. */ + +static bool +dr_indices_valid_in_loop (tree ref ATTRIBUTE_UNUSED, tree *index, void *data) +{ + loop_p loop; + basic_block header, def_bb; + gimple stmt; + + if (TREE_CODE (*index) != SSA_NAME) + return true; + + loop = *((loop_p *) data); + header = loop->header; + stmt = SSA_NAME_DEF_STMT (*index); + + if (!stmt) + return true; + + def_bb = gimple_bb (stmt); + + if (!def_bb) + return true; + + return dominated_by_p (CDI_DOMINATORS, header, def_bb); +} + /* When the result of a CLOSE_PHI is written to a memory location, return a pointer to that memory reference, otherwise return NULL_TREE. */ @@ -3007,21 +3036,40 @@ static tree close_phi_written_to_memory (gimple close_phi) { imm_use_iterator imm_iter; - tree res, def = gimple_phi_result (close_phi); use_operand_p use_p; gimple stmt; + tree res, def = gimple_phi_result (close_phi); FOR_EACH_IMM_USE_FAST (use_p, imm_iter, def) if ((stmt = USE_STMT (use_p)) && gimple_code (stmt) == GIMPLE_ASSIGN - && (res = gimple_assign_lhs (stmt)) - && (TREE_CODE (res) == ARRAY_REF - || TREE_CODE (res) == MEM_REF - || TREE_CODE (res) == VAR_DECL - || TREE_CODE (res) == PARM_DECL - || TREE_CODE (res) == RESULT_DECL)) - return res; + && (res = gimple_assign_lhs (stmt))) + { + switch (TREE_CODE (res)) + { + case VAR_DECL: + case PARM_DECL: + case RESULT_DECL: + return res; + + case ARRAY_REF: + case MEM_REF: + { + tree arg = gimple_phi_arg_def (close_phi, 0); + loop_p nest = loop_containing_stmt (SSA_NAME_DEF_STMT (arg)); + + /* FIXME: this restriction is for id-{24,25}.f and + could be handled by duplicating the computation of + array indices before the loop of the close_phi. */ + if (for_each_index (&res, dr_indices_valid_in_loop, &nest)) + return res; + } + /* Fallthru. */ + default: + continue; + } + } return NULL_TREE; } diff --git a/gcc/testsuite/gfortran.dg/graphite/id-24.f b/gcc/testsuite/gfortran.dg/graphite/id-24.f new file mode 100644 index 0000000..20c40ee --- /dev/null +++ b/gcc/testsuite/gfortran.dg/graphite/id-24.f @@ -0,0 +1,9 @@ + SUBROUTINE TFTRAB(A,NA) + DIMENSION A(NA,NA) + DO 160 K=1,NA + DUM = DUM + A(K,I) + 160 CONTINUE + DO 180 I=1,NA + A(I,J) = DUM + 180 CONTINUE + END diff --git a/gcc/testsuite/gfortran.dg/graphite/id-25.f b/gcc/testsuite/gfortran.dg/graphite/id-25.f new file mode 100644 index 0000000..642ed6d --- /dev/null +++ b/gcc/testsuite/gfortran.dg/graphite/id-25.f @@ -0,0 +1,10 @@ + SUBROUTINE TFTRAB(NA,NC,D,WRK) + DIMENSION D(NA,NC), WRK(NA) + DO 160 K=1,NA + DUM = DUM + D(K,J) + 160 CONTINUE + WRK(I) = DUM + DO 180 I=1,NA + D(I,J) = WRK(I) + 180 CONTINUE + END