From patchwork Thu Jul 20 12:45:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 123248 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp3091264vqt; Thu, 20 Jul 2023 05:46:49 -0700 (PDT) X-Google-Smtp-Source: APBJJlFjsvs8gmzyuISX+Cqu5L98bc5QWtFyxjkW1Sz1xNuYqRnAcsoYWzo9ERNJW8tx4A1w5LgP X-Received: by 2002:a17:906:64c2:b0:997:e836:6c4 with SMTP id p2-20020a17090664c200b00997e83606c4mr4873118ejn.9.1689857209046; Thu, 20 Jul 2023 05:46:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689857209; cv=none; d=google.com; s=arc-20160816; b=yVXbtAYE8ZTiGIqmW/l67yrF9QjlFaxo1yRjAQH1XYZYF4QMUkuYCk622ozQ729+nE 77ojOajPenm/il55eFPljCyWeje65UgiGY1Dmi/NuBaQmSuM863ehuaDfvP9eYxaPx/m JMExv7lkdCH9KShDoBGxK/WSndcgqDO0Jju1z66JI5MP0ksJr7BBaReWvFkou8DxEkUg FM9E8jN3A8zEXxiCg7DoLsJenJVlSj3Wtr6j3cHCylcgcjnmbt3jqPmXJgoBFqLlVB0p x5dbxlXpPR38pufzmEkI1XFoB1uXpMwupGSahnPYhUwvhxNG2VhsF8JTm9BdtvZkQzoF aKOw== 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=qGryu0gCJ4XThkLxorI46kO2ZEAQeJF7OaIN7HARNhs=; fh=etb9MYHN7HLF/sff76ICVdPeKiI8ZsjoOL2bcdG0aog=; b=HDq85UHxXgdQqyVbJXF5IDQvMEnbG9w6/HgOxYPUdqDl/D2SBAxODAv446HTRwP71Z 0wHN7u6TZ3YCTcDkFSLfuRKuxYmMegC/1L70T+Xq20Ck0U5bqGVg4Ra70kr1pmm6XZth HPEjleEgxRNMEFGXsIsPXQgqy/CIy2EZADHFvj2m+5TwfbMgV48hS6JJlwN7GoZ8u7xs VXR2vhH/nqlkhuKhe0EypT1F3lfv9m2vKeJNrtYwG7PNHTYKk8Ex1+vQzLkCfr8e57VB HefkZdUSfguDdMzR08Lag2q8IQlm0bdauNNhV3sA+NPfKdMgOv+nxLVq+UtZAsLnkLFE Pehg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=yqueSAwk; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id p1-20020a17090628c100b0099334262e18si673503ejd.49.2023.07.20.05.46.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jul 2023 05:46:49 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=yqueSAwk; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 A1DDA385558C for ; Thu, 20 Jul 2023 12:46:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A1DDA385558C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1689857196; bh=qGryu0gCJ4XThkLxorI46kO2ZEAQeJF7OaIN7HARNhs=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=yqueSAwkFcKieMtTM4PQhrraGO7hQuofgKfSqA4cb23bPwA6IzgOhIO1DbhIWsmoi +U+K7efI1jFNOOvQ9auzHHIUGg7GKNoi87yWPNDkStxSqU+WeJhG+DLX0r4xJ+RwmI hKZnXGMQXHwfLIniYlm5UmwezZvxN7zdZQQedIs4= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by sourceware.org (Postfix) with ESMTPS id 95783385DC1A for ; Thu, 20 Jul 2023 12:45:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 95783385DC1A Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 9D01F2065B for ; Thu, 20 Jul 2023 12:45:52 +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 9253B2C142 for ; Thu, 20 Jul 2023 12:45:52 +0000 (UTC) Date: Thu, 20 Jul 2023 12:45:52 +0000 (UTC) To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/110204 - second level redundancy and simplification 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, T_SCC_BODY_TEXT_LINE 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: <20230720124636.A1DDA385558C@sourceware.org> X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771943712996159578 X-GMAIL-MSGID: 1771943712996159578 When PRE discovers a full redundancy during insertion it cannot unite the two value sets. Instead it inserts a copy old-val = new-val where new-val can also be a constant. The following looks through such copies during elimination, providing one extra level of constant and copy propagation. For the PR this helps avoiding a bogus diagnostic that's emitted on unreachable code during loop optimization. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. Richard. PR tree-optimization/110204 * tree-ssa-sccvn.cc (eliminate_dom_walker::eliminate_avail): Look through copies generated by PRE. --- gcc/tree-ssa-sccvn.cc | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/gcc/tree-ssa-sccvn.cc b/gcc/tree-ssa-sccvn.cc index 11061a374a2..a0b98c18ac8 100644 --- a/gcc/tree-ssa-sccvn.cc +++ b/gcc/tree-ssa-sccvn.cc @@ -6594,7 +6594,22 @@ eliminate_dom_walker::eliminate_avail (basic_block, tree op) if (SSA_NAME_IS_DEFAULT_DEF (valnum)) return valnum; if (avail.length () > SSA_NAME_VERSION (valnum)) - return avail[SSA_NAME_VERSION (valnum)]; + { + tree av = avail[SSA_NAME_VERSION (valnum)]; + /* When PRE discovers a new redundancy there's no way to unite + the value classes so it instead inserts a copy old-val = new-val. + Look through such copies here, providing one more level of + simplification at elimination time. */ + gassign *ass; + if (av && (ass = dyn_cast (SSA_NAME_DEF_STMT (av)))) + if (gimple_assign_rhs_class (ass) == GIMPLE_SINGLE_RHS) + { + tree rhs1 = gimple_assign_rhs1 (ass); + if (CONSTANT_CLASS_P (rhs1) || TREE_CODE (rhs1) == SSA_NAME) + av = rhs1; + } + return av; + } } else if (is_gimple_min_invariant (valnum)) return valnum;