From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de 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) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1689857152; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=qGryu0gCJ4XThkLxorI46kO2ZEAQeJF7OaIN7HARNhs=; b=WiDFPatRm85fuz98kgRTLLudXvAs8wp/YErNRyLCyGrgHVwV/PG1NU0hJOQmlszK9dAQOh aVvxQRetsusdcWj/JhbfHPBLwn9SDJN6AUF17Uc8iYE0jrdArU5v5C7sW14E2RdGa3GLDG uDCaErc7QMENwvFLjWLfsk1k/Vv8M+A= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1689857152; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=qGryu0gCJ4XThkLxorI46kO2ZEAQeJF7OaIN7HARNhs=; b=NkF/2AsWfgGHpHjBDwYcKsGtYpeIsPkqMZ1RSAMoCAuma+KL4ocaAeZEiSM3pPbTbi4pkX QJBi83NlA45y11Cw== 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) From: Richard Biener 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 Content-Type: text/plain; charset=US-ASCII 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 List-Id: Message-ID: <20230720124552.9mMWnMjzbH_gcF6xCZJld-T1iI94eSMXIgYCpG92Qss@z> 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; -- 2.35.3