From patchwork Fri Sep 23 12:32:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 57967 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id F221C3857340 for ; Fri, 23 Sep 2022 12:33:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F221C3857340 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663936412; bh=2JlInD1OYvpjgH8CdZcSezmWWbMJW5e78HFLgwKZK8Q=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=nrChaixmL0KonWLqpsYw5fBgBE/ggskYOF1eXoaxWGZ3nFMgRvf2yzp5mXu37DFXR zNfyR5hQmC1fCEfV3TOoGSPcAOcpZ1Qu60P7nJAvO7nrgaxByZDIkz2vPWyE9ASkPX fux2N9FQ+6QP8uES/FLumfJjvIbIfl6eFCHwGBJI= 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 [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id 616163858C52 for ; Fri, 23 Sep 2022 12:32:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 616163858C52 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 39D3921976 for ; Fri, 23 Sep 2022 12:32:58 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 176D213A00 for ; Fri, 23 Sep 2022 12:32:58 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id Wzp1BHqnLWPOdgAAMHmgww (envelope-from ) for ; Fri, 23 Sep 2022 12:32:58 +0000 Date: Fri, 23 Sep 2022 14:32:57 +0200 (CEST) To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/106922 - extend same-val clobber FRE MIME-Version: 1.0 Message-Id: <20220923123258.176D213A00@imap2.suse-dmz.suse.de> X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, 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+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" The following extends the skipping of same valued stores to handle an arbitrary number of them as long as they are from the same value (which we now record). That's an obvious extension which allows to optimize the m_engaged member of std::optional more reliably. Bootstrapped on x86_64-unknown-linux-gnu, testing in progress. PR tree-optimization/106922 * tree-ssa-sccvn.cc (vn_reference_lookup_3): Allow an arbitrary number of same valued skipped stores. * g++.dg/torture/pr106922.C: New testcase. --- gcc/testsuite/g++.dg/torture/pr106922.C | 48 +++++++++++++++++++++++++ gcc/tree-ssa-sccvn.cc | 10 ++++-- 2 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/g++.dg/torture/pr106922.C diff --git a/gcc/testsuite/g++.dg/torture/pr106922.C b/gcc/testsuite/g++.dg/torture/pr106922.C new file mode 100644 index 00000000000..046fc6cce76 --- /dev/null +++ b/gcc/testsuite/g++.dg/torture/pr106922.C @@ -0,0 +1,48 @@ +// { dg-do compile } +// { dg-require-effective-target c++17 } +// { dg-additional-options "-Wall" } +// -O1 doesn't iterate VN and thus has bogus uninit diagnostics +// { dg-skip-if "" { *-*-* } { "-O1" } { "" } } + +#include + +#include +template +using Optional = std::optional; + +#include + +struct MyOptionalStructWithInt { + int myint; /* works without this */ + Optional> myoptional; +}; + +struct MyOptionalsStruct { + MyOptionalStructWithInt external1; + MyOptionalStructWithInt external2; +}; + +struct MyStruct { }; +std::ostream &operator << (std::ostream &os, const MyStruct &myStruct); + +std::vector getMyStructs(); + +void test() +{ + MyOptionalsStruct externals; + MyOptionalStructWithInt internal1; + MyOptionalStructWithInt internal2; + + std::vector myStructs; + myStructs = getMyStructs(); + + for (const auto& myStruct : myStructs) + { + std::stringstream address_stream; + address_stream << myStruct; + internal1.myint = internal2.myint = 0; + externals.external1 = internal1; + externals.external2 = internal2; + externals.external2 = internal2; + } +} diff --git a/gcc/tree-ssa-sccvn.cc b/gcc/tree-ssa-sccvn.cc index 9c12a8e4f03..2cc2c0e1e34 100644 --- a/gcc/tree-ssa-sccvn.cc +++ b/gcc/tree-ssa-sccvn.cc @@ -2680,7 +2680,6 @@ vn_reference_lookup_3 (ao_ref *ref, tree vuse, void *data_, if (is_gimple_reg_type (TREE_TYPE (lhs)) && types_compatible_p (TREE_TYPE (lhs), vr->type) && (ref->ref || data->orig_ref.ref) - && !data->same_val && !data->mask && data->partial_defs.is_empty () && multiple_p (get_object_alignment @@ -2693,8 +2692,13 @@ vn_reference_lookup_3 (ao_ref *ref, tree vuse, void *data_, a different loop iteration but only to loop invariants. Use CONSTANT_CLASS_P (unvalueized!) as conservative approximation. The one-hop lookup below doesn't have this issue since there's - a virtual PHI before we ever reach a backedge to cross. */ - if (CONSTANT_CLASS_P (rhs)) + a virtual PHI before we ever reach a backedge to cross. + We can skip multiple defs as long as they are from the same + value though. */ + if (data->same_val + && !operand_equal_p (data->same_val, rhs)) + ; + else if (CONSTANT_CLASS_P (rhs)) { if (dump_file && (dump_flags & TDF_DETAILS)) {