From patchwork Mon Sep 3 14:38:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 965465 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-485026-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="LEq85Y/0"; dkim-atps=neutral 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 423syc6gCkz9s1x for ; Tue, 4 Sep 2018 00:38:15 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=RTPEqyBq3fayaRUaGZvBg41+71Ifu5kc7FbahyHJzJQslhdTBl9Hs YhAT1YCav9RalVTvQoL8Ft+So1X3/yQDWyR0ZcyZvPlzJlrod0pWKDP4FlYnn1qe 75MtKJeYo6wI0blbzUa0MG+CectK2Cs5ku67nU5/Jlt1VAc7ECskGw= 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:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=eOGIb5KzTz2kfE5QDcR8LWqsxwU=; b=LEq85Y/0QJ+Y3Nbh2Txf bf2njQXIYrKp+SG0JkqSdBAIzYqpscCePsH0YZScHCs/tIFSmETt/nu5Jke44gw0 vcHfOTr8WXS0SGkVu/b3unBiaFNs2kWV1JOqc9tFa8ko4Yt2KZjd+Xzi9orQWYWN i52E1ddE3zUFI3cxCarba5c= Received: (qmail 19021 invoked by alias); 3 Sep 2018 14:38:08 -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 19011 invoked by uid 89); 3 Sep 2018 14:38:08 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-10.6 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, KAM_NUMSUBJECT, SPF_PASS autolearn=ham version=3.3.2 spammy=desirable X-HELO: mx1.suse.de Received: from mx2.suse.de (HELO mx1.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 03 Sep 2018 14:38:06 +0000 Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 1D30EADF2 for ; Mon, 3 Sep 2018 14:38:04 +0000 (UTC) Date: Mon, 3 Sep 2018 16:38:03 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix PR87176 Message-ID: User-Agent: Alpine 2.20 (LSU 67 2015-01-07) MIME-Version: 1.0 The following fixes a wrong-code issue similar to that in PR87132 where the alias walk reaches into code parts that are only reachable over backedges. This time not via PHI processing but by value-numbering a virtual PHI to its backedge value. That doesn't play well with the way we do iteration for the memory state. This also adds a testcase showing the desirable way of doing virtual PHI value-numbering (ideally the walking code would honor edge executability state but that would tie it even more to VN...). Bootstrap & regtest running on x86_64-unknown-linux-gnu. 2018-09-03 Richard Biener PR tree-optimization/87176 * tree-ssa-sccvn.c (visit_phi): Remove redundant allsame variable. When value-numbering a virtual PHI node make sure to not value-number to the backedge value. * gcc.dg/torture/pr87176.c: New testcase. * gcc.dg/torture/ssa-fre-1.c: Likewise. Index: gcc/tree-ssa-sccvn.c =================================================================== --- gcc/tree-ssa-sccvn.c (revision 264058) +++ gcc/tree-ssa-sccvn.c (working copy) @@ -4113,11 +4105,10 @@ static bool visit_phi (gimple *phi, bool *inserted, bool backedges_varying_p) { tree result, sameval = VN_TOP, seen_undef = NULL_TREE; - tree backedge_name = NULL_TREE; + tree backedge_val = NULL_TREE; tree sameval_base = NULL_TREE; poly_int64 soff, doff; unsigned n_executable = 0; - bool allsame = true; edge_iterator ei; edge e; @@ -4142,10 +4133,10 @@ visit_phi (gimple *phi, bool *inserted, ++n_executable; if (TREE_CODE (def) == SSA_NAME) { - if (e->flags & EDGE_DFS_BACK) - backedge_name = def; if (!backedges_varying_p || !(e->flags & EDGE_DFS_BACK)) def = SSA_VAL (def); + if (e->flags & EDGE_DFS_BACK) + backedge_val = def; } if (def == VN_TOP) ; @@ -4175,16 +4166,23 @@ visit_phi (gimple *phi, bool *inserted, && known_eq (soff, doff)) continue; } - allsame = false; + sameval = NULL_TREE; break; } } /* If the value we want to use is the backedge and that wasn't visited - yet drop to VARYING. */ - if (backedge_name - && sameval == backedge_name - && !SSA_VISITED (backedge_name)) + yet drop to VARYING. This only happens when not iterating. + If we value-number a virtual operand never value-number to the + value from the backedge as that confuses the alias-walking code. + See gcc.dg/torture/pr87176.c. */ + if (backedge_val + && TREE_CODE (backedge_val) == SSA_NAME + && sameval == backedge_val + && (SSA_NAME_IS_VIRTUAL_OPERAND (backedge_val) + || !SSA_VISITED (backedge_val))) + /* Note this just drops to VARYING without inserting the PHI into + the hashes. */ result = PHI_RESULT (phi); /* If none of the edges was executable keep the value-number at VN_TOP, if only a single edge is exectuable use its value. */ @@ -4215,7 +4213,7 @@ visit_phi (gimple *phi, bool *inserted, /* If all values are the same use that, unless we've seen undefined values as well and the value isn't constant. CCP/copyprop have the same restriction to not remove uninit warnings. */ - else if (allsame + else if (sameval && (! seen_undef || is_gimple_min_invariant (sameval))) result = sameval; else Index: gcc/testsuite/gcc.dg/torture/pr87176.c =================================================================== --- gcc/testsuite/gcc.dg/torture/pr87176.c (nonexistent) +++ gcc/testsuite/gcc.dg/torture/pr87176.c (working copy) @@ -0,0 +1,28 @@ +/* { dg-do run } */ + +int a, b, c; + +int main () +{ + int d = a = 0; + while (1) + { + a = a ^ 6; + if (!a) + break; + if (d) + goto L; + d = a; + for (b = 0; b < 2; b++) + { + const int *f[3] = { &c }; + const int **g[] = { &f[2] }; + int h = ~d; + if (d) + L: + if (h > 1) + continue; + } + } + return 0; +} Index: gcc/testsuite/gcc.dg/torture/ssa-fre-1.c =================================================================== --- gcc/testsuite/gcc.dg/torture/ssa-fre-1.c (nonexistent) +++ gcc/testsuite/gcc.dg/torture/ssa-fre-1.c (working copy) @@ -0,0 +1,16 @@ +/* { dg-do compile } */ +/* { dg-skip-if "" { *-*-* } { "-O0" } { "" } } */ +/* { dg-additional-options "-fstrict-aliasing -fdump-tree-fre1" } */ + +float f; +int foo(int *p, int *q) +{ + *p = 0; + if (*p) + *q = 1; + else + f = 8.0f; + return *p; +} + +/* { dg-final { scan-tree-dump "return 0;" "fre1" } } */