From patchwork Tue Oct 18 13:48:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Jambor X-Patchwork-Id: 4180 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1969562wrs; Tue, 18 Oct 2022 06:48:44 -0700 (PDT) X-Google-Smtp-Source: AMsMyM78l5mZ5jXnQogWxy7Y04s+G5+ZKxkx02fTu8OoW5HKu/Cr5k1jylzzd69iwTxZOV68RA1C X-Received: by 2002:a17:907:a46:b0:782:1c1c:8141 with SMTP id be6-20020a1709070a4600b007821c1c8141mr2457788ejc.549.1666100924805; Tue, 18 Oct 2022 06:48:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666100924; cv=none; d=google.com; s=arc-20160816; b=Pbi3HyOJ+a4Rtmtw3KKHOgLoKlz62gNm+yjRrstx0Si+PPQGwnpOMFpApB6hMK5itI XQZ8D6X8WWKrtX0CzGdLcU8Gwjz8kgO7Y7VCeBIRTMdAYHaI35vUHsfiX9Jc+VmWm0Ly HsSTND+5pJvfDqY+A6K02L2ef9YafkdOOL7nTuP90Yh+wOOqX9MriUB7rz6iK1EODubk tephsAF09Dz/HXNsYku/mT8cSgQbz1TYo1V2eWpLzUtNKoNRYTK5mTQ6eaoed3VQl8JU 9spXIPY4UMggbbQ4cqLV1O+A/39P7mPt0B+llbFvlGhRYYqCvQWFFMPhbgdFuig1UStE dGug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:mime-version:message-id:date :user-agent:subject:cc:to:from:dkim-signature:dkim-signature :dmarc-filter:delivered-to; bh=RnZPWeasLJ6c0BjL5ST41bEpQz5QI60OHfQMsB0CNgA=; b=Zi2yaZ0yEs+UVqbc3Jwt/yyiilsV4iM849En+Jz8muNwpjNHqWriFUbF3jMjbUpWak e9CrkvzpQ/eDxqXq16BlOuIyRCz+46SH9VG5HoJQrfl6e0ZBMV2molow4ffmvfJ/jun1 bx3WOG/klmbOomP4/8OjN60zEjowIwfT43e08qmqmnohwrXDTJ1QyDQs17NG5WRIkUL9 gzBOPds0QwuFaMR14dmLOzuUKf/md48NeVOytcoCfJJ/fak/hq5ACOo/qqfcILOfiv6A L0ciFlU6Cm5E0GSfQPkJmI0m/ws9pTNf7h2JYgfbSVKKU9eoehlDjHG/J3kaxtlBg0b1 XLLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=e1US9MfK; dkim=neutral (no key) header.i=@gcc.gnu.org header.s=susede2_ed25519; 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" Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id a1-20020a1709065f8100b0078d85777c4fsi9433796eju.700.2022.10.18.06.48.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Oct 2022 06:48:44 -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=@suse.cz header.s=susede2_rsa header.b=e1US9MfK; dkim=neutral (no key) header.i=@gcc.gnu.org header.s=susede2_ed25519; 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" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A217C3857815 for ; Tue, 18 Oct 2022 13:48:35 +0000 (GMT) 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 A90893858406 for ; Tue, 18 Oct 2022 13:48:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A90893858406 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=suse.cz 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 6407133E7D for ; Tue, 18 Oct 2022 13:48:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1666100889; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=RnZPWeasLJ6c0BjL5ST41bEpQz5QI60OHfQMsB0CNgA=; b=e1US9MfKR7sYMfSoWpX8qXq0xjsZ3Yj7RxJL+UnVZ59zZFsoMpUbnIL5Nmn5AV1+0ECxrP X5jGtOJB6DriUggGh83t0R3EiRR2fTjGowU9Kh9GYo1aubC1nTfTIOiSZPzBFvbau/4Id+ ethu5nsGcwFubNJbeqwkHNnynIC+Y3Y= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1666100889; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=RnZPWeasLJ6c0BjL5ST41bEpQz5QI60OHfQMsB0CNgA=; b=bfauNZ0kI561cdHYQOha6rYVctHTuHIT/M7A+uKDI4APm6wQaBVxYBY7oq0x0DeM/r4n7l wuhuOAhkx0zOe7Cw== 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 5726913A84 for ; Tue, 18 Oct 2022 13:48:09 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id EIuJFJmuTmPeJwAAMHmgww (envelope-from ) for ; Tue, 18 Oct 2022 13:48:09 +0000 From: Martin Jambor To: GCC Patches Cc: Subject: [PATCH] SRA: Limit replacement creation for accesses propagated from LHSs User-Agent: Notmuch/0.35 (https://notmuchmail.org) Emacs/28.1 (x86_64-suse-linux-gnu) Date: Tue, 18 Oct 2022 15:48:08 +0200 Message-ID: MIME-Version: 1.0 X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_SOFTFAIL, 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: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747033443454686155?= X-GMAIL-MSGID: =?utf-8?q?1747033443454686155?= Hi, PR 107206 is fallout from the fix to PR 92706 where we started propagating accesses across assignments also from LHS to RHS of assignments so that we would not do harmful total scalarization of the aggregates on the RHS. But this can lead to new scalarization of these aggregates and in the testcase of PR 107206 these can appear in superfluous uses of un-initialized values and spurious warnings. Fixed by making sure the the accesses created by propagation in this direction are only used as a basis for replacements when the structure would be totally scalarized anyway. Richi has already approved the patch (without the testcase) in Bugzilla, so I plan to commit it after bootstrapping and testing it on an x86_64 (on top of a more recent trunk than last week). Thanks, Martin gcc/ChangeLog: 2022-10-18 Martin Jambor PR tree-optimization/107206 * tree-sra.cc (struct access): New field grp_result_of_prop_from_lhs. (analyze_access_subtree): Do not create replacements for accesses with this flag when not toally scalarizing. (propagate_subaccesses_from_lhs): Set the new flag. gcc/testsuite/ChangeLog: 2022-10-18 Martin Jambor PR tree-optimization/107206 * g++.dg/tree-ssa/pr107206.C: New test. --- gcc/testsuite/g++.dg/tree-ssa/pr107206.C | 27 ++++++++++++++++++++++++ gcc/tree-sra.cc | 7 ++++++ 2 files changed, 34 insertions(+) create mode 100644 gcc/testsuite/g++.dg/tree-ssa/pr107206.C diff --git a/gcc/testsuite/g++.dg/tree-ssa/pr107206.C b/gcc/testsuite/g++.dg/tree-ssa/pr107206.C new file mode 100644 index 00000000000..34810ad2b7b --- /dev/null +++ b/gcc/testsuite/g++.dg/tree-ssa/pr107206.C @@ -0,0 +1,27 @@ +// { dg-do compile } +// { dg-require-effective-target c++17 } +// { dg-options "-O -Wuninitialized" } + +#include +struct X { + X() = default; + X(X const& r) : i(r.i) {} + int i; +}; +struct Y { + Y() : x() {} + X x; + std::optional o; +}; +struct Z { + Y y; + explicit Z(Y y) : y(y) {} +}; +void f(Y const&); +void test() { + Y const y; + Z z(y); + z.y.o = 1; + auto const w = z; + f(w.y); +} diff --git a/gcc/tree-sra.cc b/gcc/tree-sra.cc index 1a3e12f18cc..6cbeddfc548 100644 --- a/gcc/tree-sra.cc +++ b/gcc/tree-sra.cc @@ -260,6 +260,9 @@ struct access /* Should TREE_NO_WARNING of a replacement be set? */ unsigned grp_no_warning : 1; + + /* Result of propagation accross link from LHS to RHS. */ + unsigned grp_result_of_prop_from_lhs : 1; }; typedef struct access *access_p; @@ -2532,6 +2535,9 @@ analyze_access_subtree (struct access *root, struct access *parent, if (allow_replacements && expr_with_var_bounded_array_refs_p (root->expr)) allow_replacements = false; + if (!totally && root->grp_result_of_prop_from_lhs) + allow_replacements = false; + for (child = root->first_child; child; child = child->next_sibling) { hole |= covered_to < child->offset; @@ -2959,6 +2965,7 @@ propagate_subaccesses_from_lhs (struct access *lacc, struct access *racc) struct access *new_acc = create_artificial_child_access (racc, lchild, norm_offset, true, false); + new_acc->grp_result_of_prop_from_lhs = 1; propagate_subaccesses_from_lhs (lchild, new_acc); } else