From patchwork Thu Dec 16 21:17:02 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Pop X-Patchwork-Id: 75800 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 A5687B6EF2 for ; Fri, 17 Dec 2010 08:17:18 +1100 (EST) Received: (qmail 23891 invoked by alias); 16 Dec 2010 21:17:16 -0000 Received: (qmail 23882 invoked by uid 22791); 16 Dec 2010 21:17:15 -0000 X-SWARE-Spam-Status: No, hits=-2.2 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-vw0-f47.google.com (HELO mail-vw0-f47.google.com) (209.85.212.47) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 16 Dec 2010 21:17:09 +0000 Received: by vws6 with SMTP id 6so902037vws.20 for ; Thu, 16 Dec 2010 13:17:07 -0800 (PST) Received: by 10.220.176.134 with SMTP id be6mr2358270vcb.127.1292534227051; Thu, 16 Dec 2010 13:17:07 -0800 (PST) Received: from napoca ([163.181.251.115]) by mx.google.com with ESMTPS id v26sm173214vcr.37.2010.12.16.13.17.04 (version=TLSv1/SSLv3 cipher=RC4-MD5); Thu, 16 Dec 2010 13:17:06 -0800 (PST) Received: by napoca (sSMTP sendmail emulation); Thu, 16 Dec 2010 15:17:03 -0600 From: Sebastian Pop To: gcc-patches@gcc.gnu.org Cc: Sebastian Pop Subject: [PATCH] Fix PR46924: Do not detect reductions outside the current SESE region. Date: Thu, 16 Dec 2010 15:17:02 -0600 Message-Id: <1292534222-16150-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, Without this patch we ended up analyzing scalar reductions outside the currently analyzed scop. I am testing this on amd64-linux. I will commit this to trunk after regstrap. Sebastian 2010-12-16 Sebastian Pop PR tree-optimization/46924 * graphite-sese-to-poly.c (detect_commutative_reduction): Do not detect reductions outside the current SESE region. * sese.h (stmt_in_sese_p): New. (defined_in_sese_p): Call stmt_in_sese_p. * gcc.dg/graphite/pr46924.c: New. --- gcc/ChangeLog | 8 ++++++++ gcc/graphite-sese-to-poly.c | 15 +++++++++------ gcc/sese.h | 13 ++++++++++--- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.dg/graphite/pr46924.c | 18 ++++++++++++++++++ 5 files changed, 50 insertions(+), 9 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/graphite/pr46924.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 287d21e..2fe57ab 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,5 +1,13 @@ 2010-12-16 Sebastian Pop + PR tree-optimization/46924 + * graphite-sese-to-poly.c (detect_commutative_reduction): Do not + detect reductions outside the current SESE region. + * sese.h (stmt_in_sese_p): New. + (defined_in_sese_p): Call stmt_in_sese_p. + +2010-12-16 Sebastian Pop + PR tree-optimization/46404 * graphite-clast-to-gimple.c (gloog): Call scev_reset. diff --git a/gcc/graphite-sese-to-poly.c b/gcc/graphite-sese-to-poly.c index 5036fba..2eadd25 100644 --- a/gcc/graphite-sese-to-poly.c +++ b/gcc/graphite-sese-to-poly.c @@ -2857,12 +2857,12 @@ initial_value_for_loop_phi (gimple phi) return NULL_TREE; } -/* Detect commutative and associative scalar reductions starting at - the loop closed phi node STMT. Return the phi node of the - reduction cycle, or NULL. */ +/* Detect commutative and associative scalar reductions belonging to + the SCOP starting at the loop closed phi node STMT. Return the phi + node of the reduction cycle, or NULL. */ static gimple -detect_commutative_reduction (gimple stmt, VEC (gimple, heap) **in, +detect_commutative_reduction (scop_p scop, gimple stmt, VEC (gimple, heap) **in, VEC (gimple, heap) **out) { if (scalar_close_phi_node_p (stmt)) @@ -2879,7 +2879,10 @@ detect_commutative_reduction (gimple stmt, VEC (gimple, heap) **in, gcc_assert (gimple_phi_num_args (stmt) == 1); def = SSA_NAME_DEF_STMT (arg); - loop_phi = detect_commutative_reduction (def, in, out); + if (!stmt_in_sese_p (def, SCOP_REGION (scop))) + return NULL; + + loop_phi = detect_commutative_reduction (scop, def, in, out); if (loop_phi) { @@ -3018,7 +3021,7 @@ rewrite_commutative_reductions_out_of_ssa_close_phi (scop_p scop, VEC (gimple, heap) *in = VEC_alloc (gimple, heap, 10); VEC (gimple, heap) *out = VEC_alloc (gimple, heap, 10); - detect_commutative_reduction (close_phi, &in, &out); + detect_commutative_reduction (scop, close_phi, &in, &out); res = VEC_length (gimple, in) > 0; if (res) translate_scalar_reduction_to_array (scop, in, out); diff --git a/gcc/sese.h b/gcc/sese.h index 10bf874..97807d8 100644 --- a/gcc/sese.h +++ b/gcc/sese.h @@ -114,15 +114,22 @@ bb_in_sese_p (basic_block bb, sese region) return bb_in_region (bb, entry, exit); } +/* Returns true when STMT is defined in REGION. */ + +static inline bool +stmt_in_sese_p (gimple stmt, sese region) +{ + basic_block bb = gimple_bb (stmt); + return bb && bb_in_sese_p (bb, region); +} + /* Returns true when NAME is defined in REGION. */ static inline bool defined_in_sese_p (tree name, sese region) { gimple stmt = SSA_NAME_DEF_STMT (name); - basic_block bb = gimple_bb (stmt); - - return bb && bb_in_sese_p (bb, region); + return stmt_in_sese_p (stmt, region); } /* Returns true when LOOP is in REGION. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 8cfb516..b44f38f 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,10 @@ 2010-12-16 Sebastian Pop + PR tree-optimization/46924 + * gcc.dg/graphite/pr46924.c: New. + +2010-12-16 Sebastian Pop + PR tree-optimization/46404 * gcc.dg/graphite/pr46404-1.c: New. diff --git a/gcc/testsuite/gcc.dg/graphite/pr46924.c b/gcc/testsuite/gcc.dg/graphite/pr46924.c new file mode 100644 index 0000000..5788c2c --- /dev/null +++ b/gcc/testsuite/gcc.dg/graphite/pr46924.c @@ -0,0 +1,18 @@ +/* { dg-options "-O -fgraphite-identity -ffast-math -fno-tree-loop-im" } */ + +struct S +{ + int n; + float *a; +}; + +float foo (struct S *s) +{ + float f = 0, g=0; + int i; + for (i = 0; i < s->n; i++) + f += s->a[i]; + for (i = 0; i < s->n; i++) + ; + return f; +}