From patchwork Tue Feb 21 17:58:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Law X-Patchwork-Id: 730707 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 3vSSsY4Vd4z9ryj for ; Wed, 22 Feb 2017 04:58:25 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="KYggFxXY"; 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:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=sUa0991CYQHj2wja3P+0MxCNTzNO37dCk/oIuAp4Of9p4YmDzC iaBBK05+UBnxWgw5OF1f987+PLCpcUZkfWM7XqiIulJ/Bz8cffKIJtpHiaouCZC2 Q8vGYsOoRzHmC1acE/Dzuri0QmdsMCFFv0c4bcvJ9u1LcA4a6lw8fQ8Ao= 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:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=DL/zltkGc0VCB++1b1UDnGJY5+M=; b=KYggFxXY6Ix9975CzqdL Wi3DfwNK5wsyy4n+Xjp21PR64yn+O1+mDKgsT12I2yKZtdCgYAjZRZEr/eisq+f+ HVh25YVjIlPk4r8mWBLznlXf2SWWfARqaQ+CsmhVvQI1cQzP04WRcX4ml9XAYC90 Ghfdib2z3LmdeMlPRvLrpXc= Received: (qmail 32054 invoked by alias); 21 Feb 2017 17:58:18 -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 32045 invoked by uid 89); 21 Feb 2017 17:58:18 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=installing X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 21 Feb 2017 17:58:16 +0000 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0F5F88048A for ; Tue, 21 Feb 2017 17:58:17 +0000 (UTC) Received: from localhost.localdomain (ovpn-123-213.rdu2.redhat.com [10.10.123.213] (may be forged)) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1LHwE44001141 for ; Tue, 21 Feb 2017 12:58:15 -0500 To: gcc-patches From: Jeff Law Subject: [PATCH][PR tree-optimization/79621] Avoid path isolation on block with edge to itself Message-ID: <914638e4-b41e-0623-83b1-fa3f1e853a64@redhat.com> Date: Tue, 21 Feb 2017 10:58:12 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.7.0 MIME-Version: 1.0 X-IsSubscribed: yes Erroneous path isolation inherently duplicates blocks with erroneous behavior when reached via certain paths. This allows us to modify one copy without affecting the other. Block duplication can cause re-allocation of a PHI nodes in successor blocks and thus referencing the old PHI references stale data. This is what's happening in this BZ. We duplicate the block with an edge to itself. This causes PHIs to be reallocated which gimple-ssa-isolate-paths can't handle. This can only occur in a block which itself as a direct successor and which also has some other path that triggers erroneous behavior. Fixed by avoiding isolation if the block with erroneous behaviour can reach itself. This avoids the ICE, but does leave a missed optimization in the IL. So I'll update the BZ rather than closing. Bootstrapped and regression tested on x86_64. Installing on the trunk. Jeff diff --git a/gcc/ChangeLog b/gcc/ChangeLog index a58a516..a7b0b49 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2017-02-21 Jeff Law + + PR tree-optimization/79621 + * gimple-ssa-isolate-paths.c (find_implicit_erroneous_behavior): Ignore + blocks with edges to themselves. + 2017-02-21 Jakub Jelinek PR target/79570 diff --git a/gcc/gimple-ssa-isolate-paths.c b/gcc/gimple-ssa-isolate-paths.c index 25e8c8a..7babe09 100644 --- a/gcc/gimple-ssa-isolate-paths.c +++ b/gcc/gimple-ssa-isolate-paths.c @@ -35,6 +35,7 @@ along with GCC; see the file COPYING3. If not see #include "tree-ssa.h" #include "cfgloop.h" #include "tree-cfg.h" +#include "cfganal.h" #include "intl.h" @@ -352,6 +353,16 @@ find_implicit_erroneous_behavior (void) if (has_abnormal_or_eh_outgoing_edge_p (bb)) continue; + + /* If BB has an edge to itself, then duplication of BB below + could result in reallocation of BB's PHI nodes. If that happens + then the loop below over the PHIs would use the old PHI and + thus invalid information. We don't have a good way to know + if a PHI has been reallocated, so just avoid isolation in + this case. */ + if (find_edge (bb, bb)) + continue; + /* First look for a PHI which sets a pointer to NULL and which is then dereferenced within BB. This is somewhat overly conservative, but probably catches most of the interesting diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index f6f2e37..b164483 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-02-21 Jeff Law + + PR tree-optimization/79621 + * gcc.c-torture/compile/pr79621.c: New test. + 2017-02-21 Jakub Jelinek PR target/79570 diff --git a/gcc/testsuite/gcc.c-torture/compile/pr79621.c b/gcc/testsuite/gcc.c-torture/compile/pr79621.c new file mode 100644 index 0000000..f115c07 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/pr79621.c @@ -0,0 +1,18 @@ +int b5; + +void +h6 (int zb, int e7) +{ + while (b5 > 0) + { + int gv; + + for (gv = 1; gv < 4; ++gv) + { + ((zb != 0) ? b5 : gv) && (b5 /= e7); + zb = 0; + } + e7 = 0; + } +} +