From patchwork Wed Jan 25 12:37:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 48145 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp251264wrn; Wed, 25 Jan 2023 04:37:53 -0800 (PST) X-Google-Smtp-Source: AMrXdXuC/yu6NxNPrbAS9RctomUWquMu8pgl3IWGwUGcchR5BMkt2iQahX5eopGNeyrW6YTeFDeT X-Received: by 2002:a17:906:1918:b0:7ad:ca80:5669 with SMTP id a24-20020a170906191800b007adca805669mr34307743eje.64.1674650273263; Wed, 25 Jan 2023 04:37:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674650273; cv=none; d=google.com; s=arc-20160816; b=Pq2vFivsoWTQ2A1BRjj/t9RMHLeg8QaM5YcEc/iqZNCHOc0p0g8btey8v2iQgAJGwV PbzVgVFB/x2CXYOoDPBknA+FOKuuVYnWp3J3IsWJyJSf83TPX6iGgdbIoNqlyM8LHuAa QTBg0wel/CgMjuT+PabLhgjT4nxILC8h8yuLaF7U7OAqSDH1m5Nj7R9DwxAz/zVucxag Y/bvMTaY/GkvjOz+yNSqCv0IGnSuYzYlAXS80ADwYBinhN87YU0Va2h+xN1J84kWmq1z Y1Z8pUANK9gHVQp5qo3xqc0Rte8xnGkeQYEUEIA4lWAGXaLHxnr8Z93/Q5ZxFD3+ilt1 v0FA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:sender:errors-to:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :mime-version:user-agent:subject:to:date:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=a+wUMGIZe2fj7J7k2pIcDZO90jiwDgHR6lm96UigkwY=; b=Bms8yccPmAukhkDr8x8WTaYdgNuqBfQ5m74feyDShcEYSVYdtCPxpLcCrM2oGdr4eN Nj5UDdyCg7p+oe68aK/q1q6rsigdAMd5E64JM8SMHwhr8/63TzfBOUaI+CsUZ2R2l7TX XDsWPIX3GDgiMpXay5eQ1NNCep2Wh4yDLHhRvNSM6gpRufQCNhuIhepwzHj02PB+VdUT 2hX3r10Oc200Rat9c920QMXTye9GBm/oQbhhyEH3O++nyzIFoofapZM+q5duSxkerFWp uNEPLDOi2GuLDNLpCDiycNlSYoLkGXR8TT4tsp5eFyWreCJS7dCeNyTDFmti4NSgkQkr sy3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="AvGFw/dI"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id mz10-20020a1709071b8a00b008711359b937si5807989ejc.165.2023.01.25.04.37.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Jan 2023 04:37:53 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="AvGFw/dI"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A89F03858438 for ; Wed, 25 Jan 2023 12:37:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A89F03858438 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1674650269; bh=a+wUMGIZe2fj7J7k2pIcDZO90jiwDgHR6lm96UigkwY=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=AvGFw/dIvuJFw/UdlxAnD5lXdZk+2ohIBUCUSqzsSALiQYtqYba3IY59gq5h9eGpO kV2F083A1ilNAEFlrc8HD2TJ/Bid7gcTi45eg/isBWX/awcvsWDaV4bTdW/Db+bfXa B9ELQC0hWsxmCpKk37Pmvqfx45s8SYEgNvW8oLt0= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by sourceware.org (Postfix) with ESMTPS id 17D893858D33 for ; Wed, 25 Jan 2023 12:37:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 17D893858D33 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 0726E21C21 for ; Wed, 25 Jan 2023 12:37:05 +0000 (UTC) Received: from wotan.suse.de (wotan.suse.de [10.160.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 020632C141 for ; Wed, 25 Jan 2023 12:37:05 +0000 (UTC) Date: Wed, 25 Jan 2023 12:37:04 +0000 (UTC) To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/108523 - fix endless iteration in VN User-Agent: Alpine 2.22 (LSU 394 2020-01-19) MIME-Version: 1.0 X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, MISSING_MID, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Richard Biener via Gcc-patches From: Richard Biener Reply-To: Richard Biener Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" Message-Id: <20230125123749.A89F03858438@sourceware.org> X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1755998084768152016?= X-GMAIL-MSGID: =?utf-8?q?1755998084768152016?= The following fixes not converging iteration in value-numbering of PHI nodes when we use an equivalence to prove the PHI node is degenerate. We have to avoid the situation where we oscillate between the two equivalent values because the result is fed back via a backedge. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. PR tree-optimization/108523 * tree-ssa-sccvn.cc (visit_phi): Avoid using the exclusive backedge value for the result when using predication to prove equivalence. --- gcc/tree-ssa-sccvn.cc | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/gcc/tree-ssa-sccvn.cc b/gcc/tree-ssa-sccvn.cc index 0dba3f39aa0..edb553b07cb 100644 --- a/gcc/tree-ssa-sccvn.cc +++ b/gcc/tree-ssa-sccvn.cc @@ -5826,7 +5826,7 @@ visit_phi (gimple *phi, bool *inserted, bool backedges_varying_p) poly_int64 soff, doff; unsigned n_executable = 0; edge_iterator ei; - edge e; + edge e, sameval_e = NULL; /* TODO: We could check for this in initialization, and replace this with a gcc_assert. */ @@ -5867,7 +5867,10 @@ visit_phi (gimple *phi, bool *inserted, bool backedges_varying_p) && ssa_undefined_value_p (def, false)) seen_undef = def; else if (sameval == VN_TOP) - sameval = def; + { + sameval = def; + sameval_e = e; + } else if (!expressions_equal_p (def, sameval)) { /* We know we're arriving only with invariant addresses here, @@ -5916,6 +5919,8 @@ visit_phi (gimple *phi, bool *inserted, bool backedges_varying_p) fprintf (dump_file, " are equal on edge %d -> %d\n", e->src->index, e->dest->index); } + if (sameval_e && (sameval_e->flags & EDGE_DFS_BACK)) + sameval = def; continue; } /* If on all previous edges the value was equal to def @@ -5935,7 +5940,8 @@ visit_phi (gimple *phi, bool *inserted, bool backedges_varying_p) EDGE_PRED (bb, 0)->src->index, EDGE_PRED (bb, 0)->dest->index); } - sameval = def; + if (!(e->flags & EDGE_DFS_BACK)) + sameval = def; continue; } } @@ -5943,6 +5949,8 @@ visit_phi (gimple *phi, bool *inserted, bool backedges_varying_p) sameval = NULL_TREE; break; } + else + sameval_e = NULL; } /* If the value we want to use is flowing over the backedge and we