From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1611) id EA3D53857830; Wed, 19 Oct 2022 12:59:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EA3D53857830 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1666184390; bh=Fm0u7PsIkU5Q5oYeTGJ0dRRT3rNmoK/mfWdUY9EcLlA=; h=From:To:Subject:Date:From; b=uau1WuArb3Z5zf8W6eqG3AXPqTtHLQclWm1SfbRcumqa18e/ZMtE6/bEcNzm+/eGm dGh2tpTeK80Rq/Is/pAQ30wXe0AlY98O1QKeFtPsDO10wbJE9LpHPqBNr/98e1Z9Wy 7z1PD3z6PtV/rm77QkJ67UCoZ/vQ3a7eULRIQK04= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Martin Jambor To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-3378] SRA: Limit replacement creation for accesses propagated from LHSs X-Act-Checkin: gcc X-Git-Author: Martin Jambor X-Git-Refname: refs/heads/master X-Git-Oldrev: cb994acc08b67f26a54e7c5dc1f4995a2ce24d98 X-Git-Newrev: f6c168f8c06047bfaa3005e570126831b8855dcc Message-Id: <20221019125950.EA3D53857830@sourceware.org> Date: Wed, 19 Oct 2022 12:59:50 +0000 (GMT) List-Id: https://gcc.gnu.org/g:f6c168f8c06047bfaa3005e570126831b8855dcc commit r13-3378-gf6c168f8c06047bfaa3005e570126831b8855dcc Author: Martin Jambor Date: Wed Oct 19 14:43:04 2022 +0200 SRA: Limit replacement creation for accesses propagated from LHSs 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. 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. Diff: --- gcc/testsuite/g++.dg/tree-ssa/pr107206.C | 27 +++++++++++++++++++++++++++ gcc/tree-sra.cc | 7 +++++++ 2 files changed, 34 insertions(+) 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