From patchwork Mon May 30 09:38:01 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 627689 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]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3rJBQ83lJxz9t75 for ; Mon, 30 May 2016 19:38:40 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=Nn1Nja0S; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=FQeZtF3tFJ8k/AasCP430RjtpiTz2lOYtsR8ktp7aysEa+ytNv 4vSqiNA6PYZCxqQbi13waTTxYkrbPmLdLGlMI08p3U1KDRV/C7MruZCtjyphOTsQ 4BwXn7FoUV1TolK4XX/yYg4yjFu97Niaqyd7QP33gBe25Y7vuxIVid5pY= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:message-id:date:mime-version:content-type; s= default; bh=1oQHiqqPfVQ+mM0WnxwcftLxvCY=; b=Nn1Nja0SUIn0Uqq4xKKD zTJVK+PN3vywMWVP7sXE/CuupbBOA2ITYxjwVtVkqcVKo8U3fuhiE6NICEfzwaBX bi29ix/yJF9+Fa1VwFDXv3tM6YnDCWLdwjlhXmo1IoJjneTDCaFrNTuc1f3BfuQO arIpKSYGb71NK4QMZnradPo= Received: (qmail 53155 invoked by alias); 30 May 2016 09:38:33 -0000 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 Received: (qmail 51261 invoked by uid 89); 30 May 2016 09:38:32 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.0 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, SPF_PASS, URIBL_RED autolearn=ham version=3.3.2 spammy=td, subsequently, arrive, encountering X-HELO: relay1.mentorg.com Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Mon, 30 May 2016 09:38:17 +0000 Received: from nat-ies.mentorg.com ([192.94.31.2] helo=SVR-IES-FEM-01.mgc.mentorg.com) by relay1.mentorg.com with esmtp id 1b7JeH-00030i-ET from Tom_deVries@mentor.com ; Mon, 30 May 2016 02:38:13 -0700 Received: from [127.0.0.1] (137.202.0.76) by SVR-IES-FEM-01.mgc.mentorg.com (137.202.0.104) with Microsoft SMTP Server id 14.3.224.2; Mon, 30 May 2016 10:38:12 +0100 From: Tom de Vries To: Sebastian Pop CC: GCC Patches , Richard Biener Subject: [PATCH, PR69068] Handle 3-arg phi in copy_bb_and_scalar_dependences Message-ID: <574C09F9.1050201@mentor.com> Date: Mon, 30 May 2016 11:38:01 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.8.0 MIME-Version: 1.0 Hi, this patch fixes graphite PR69068, a 6/7 regression. I. Consider this test-case: ... int qo; int zh[2]; void td (void) { int ly, en; for (ly = 0; ly < 2; ++ly) for (en = 0; en < 2; ++en) zh[en] = ((qo == 0) || (((qo * 2) != 0))) ? 1 : -1; } ... When compiling with -O1 -fgraphite-identity, we run into an assert in bb_contains_loop_phi_nodes: ... pr-graphite.c: In function ‘td’: pr-graphite.c:5:1: internal compiler error: in bb_contains_loop_phi_nodes, at graphite-isl-ast-to-gimple.c:1078 td(void) ^~ ... II. At graphite0, we have a 3 argument phi in bb 7: ... td () { int en; int ly; int qo.1_1; int _3; int iftmp.0_6; : qo.1_1 = qo; _3 = qo.1_1 * 2; goto ; : : # en_19 = PHI <0(10), en_12(3)> if (qo.1_1 == 0) goto ; else goto ; : if (_3 != 0) goto ; else goto ; : : # iftmp.0_6 = PHI <1(6), -1(5), 1(4)> zh[en_19] = iftmp.0_6; en_12 = en_19 + 1; if (en_12 <= 1) goto ; else goto ; : ly_13 = ly_18 + 1; if (ly_13 <= 1) goto ; else goto ; : : # ly_18 = PHI goto ; : return; } ... When instantiating the gimple from the graphite ast, we arrive at copy_bb_and_scalar_dependences with bb.index == 7, where we execute: ... if (num_phis > 0 && bb_contains_loop_phi_nodes (bb)) { ... Subsequently we run into this assert, because EDGE_COUNT (bb->preds) == 3: ... /* Return true when BB contains loop phi nodes. A loop phi node is the loop header containing phi nodes which has one init-edge and one back-edge. */ static bool bb_contains_loop_phi_nodes (basic_block bb) { gcc_assert (EDGE_COUNT (bb->preds) <= 2); ... III. This patch fixes the assert conservatively by aborting graphite code generation when encountering a phi with more than two arguments in copy_bb_and_scalar_dependences. Bootstrapped and reg-tested on x86_64. OK for trunk, 6 branch? Thanks, - Tom Handle 3-arg phi in copy_bb_and_scalar_dependences 2016-05-30 Tom de Vries PR tree-optimization/69068 * graphite-isl-ast-to-gimple.c (copy_bb_and_scalar_dependences): Handle phis with more than two args. * gcc.dg/graphite/pr69068.c: New test. --- gcc/graphite-isl-ast-to-gimple.c | 7 +++++++ gcc/testsuite/gcc.dg/graphite/pr69068.c | 14 ++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/gcc/graphite-isl-ast-to-gimple.c b/gcc/graphite-isl-ast-to-gimple.c index ff1d91f..c176db0 100644 --- a/gcc/graphite-isl-ast-to-gimple.c +++ b/gcc/graphite-isl-ast-to-gimple.c @@ -2725,6 +2725,13 @@ copy_bb_and_scalar_dependences (basic_block bb, edge next_e, vec iv_map) } else { + if (num_phis > 0 + && EDGE_COUNT (bb->preds) > 2) + { + codegen_error = true; + return NULL; + } + new_bb = split_edge (next_e); if (num_phis > 0 && bb_contains_loop_phi_nodes (bb)) { diff --git a/gcc/testsuite/gcc.dg/graphite/pr69068.c b/gcc/testsuite/gcc.dg/graphite/pr69068.c new file mode 100644 index 0000000..0abea06 --- /dev/null +++ b/gcc/testsuite/gcc.dg/graphite/pr69068.c @@ -0,0 +1,14 @@ +/* { dg-do compile } */ +/* { dg-options "-O1 -fgraphite-identity" } */ + +int qo; +int zh[2]; + +void +td (void) +{ + int ly, en; + for (ly = 0; ly < 2; ++ly) + for (en = 0; en < 2; ++en) + zh[en] = ((qo == 0) || (((qo * 2) != 0))) ? 1 : -1; +}