From patchwork Thu Aug 24 09:02:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 136775 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a7d1:0:b0:3f2:4152:657d with SMTP id p17csp984832vqm; Thu, 24 Aug 2023 02:03:22 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFlqU5GEsQVW/lAZ3yhcSRv1bys4Rn8FMnypS2Zknm+Zc7q6SJOPDJFsmFxzXn46iIRnC9y X-Received: by 2002:aa7:d78d:0:b0:523:c35:c209 with SMTP id s13-20020aa7d78d000000b005230c35c209mr11026639edq.12.1692867802112; Thu, 24 Aug 2023 02:03:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692867802; cv=none; d=google.com; s=arc-20160816; b=x4kALpNhLz3b3hjFXVSmRfNprj6t3cncHr/u7dt50Tus2ccFQF0Y2fPManUbDxn5LR mFJmHAQygMbyk3uLFs46ToLax1RXxB3jhvBHzG60xBl1JiIEUUAl6/kM02XcUZc8gFmp 4zl+ASyGvnLcNJMUUvgtwzP1TSCXZyiTjWqpF01nKqwqYX6BbhUCbOiKziWetee8tESu OvEtUvU++bypCN0GqSVho3/Q/99PAxIfxdlXBaQqZ7Xnc2sqkpEqC6nqLg2uWdw5Kmw9 wKYHMn5XSqxvVkzpqCeJpsIM/8NcD3DbiHkKLDmCrLDTxo5l/PUJu+1njsR04yMKpuKN y55w== 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=sgtGcJgTCwwpaMMl3Ntoy4rp0tGOiFoyOv3Ifs5KF5o=; fh=etb9MYHN7HLF/sff76ICVdPeKiI8ZsjoOL2bcdG0aog=; b=vwD3QZwTvt5c7AkaqXQvUa7IX8HKyDorLgxz7cZbYjcnr42Biq+nce3gAN4i8doPrY bLLqGCoBj5m/M5eJuE8Tf3tEQI1cCufoM2nr78sP70dw5lM7yq1IuSCU0z87ooOcTRx2 05yGeJ5yy+FFwdevYDAnZJVUvNPrzf3HbbSFiofm0DnLN4UgIEMXajQHuZKrXxBFdu2J W4DnOxHH+JEhh7tp6/L1tnbX/j5gSUBcCdUZAQ6zfLKZ/SKoZS9DRz1z8gxpZjJ70Cmw p9MEbNLUUbGW9MHxZaiu1NEr51Wn+k6gxT46qeCWZ+Mmj2lOd+gkuIvpPi+UNtkMF226 qIzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=e52vIDwV; 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 u1-20020aa7d981000000b0052257d9655bsi9967813eds.304.2023.08.24.02.03.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Aug 2023 02:03:22 -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=e52vIDwV; 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 9947D385DC19 for ; Thu, 24 Aug 2023 09:03:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9947D385DC19 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1692867800; bh=sgtGcJgTCwwpaMMl3Ntoy4rp0tGOiFoyOv3Ifs5KF5o=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=e52vIDwVxTYekBFJ0HTQQB01qYAB7RvDWxnELpNNvpA4Y2MioqGL2RfhgpH1gIVFQ Sg4eOyk4lAeUvPK07jObwOb7tMaV36+8q58n5In6Z5m3Yp/RZeknBtlKj1z0b00+HI GoRhUZ2aUlcfAYYo5SZI534QI1KjRl2u7F+uaK30= 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 3CD733858422 for ; Thu, 24 Aug 2023 09:02:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3CD733858422 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 6669D21A70 for ; Thu, 24 Aug 2023 09:02:34 +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 5ECCC2C276 for ; Thu, 24 Aug 2023 09:02:34 +0000 (UTC) Date: Thu, 24 Aug 2023 09:02:34 +0000 (UTC) To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/111123 - indirect clobbers thrown away too early 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 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: <20230824090320.9947D385DC19@sourceware.org> X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1775100548065906645 X-GMAIL-MSGID: 1775100548065906645 The testcase in the PR shows that late uninit diagnostic relies on indirect clobbers in CTORs but we throw those away in the fab pass which is too early. The reasoning was they were supposed to keep SSA names live but that's no longer the case since DCE doesn't treat them as keeping SSA uses live. The following instead removes them before out-of-SSA coalescing which is the thing that's still affected by them. Bootstrapped and tested on x86_64-unknown-linux-gnu, I'll push this later if there are no quick comments. Richard. PR tree-optimization/111123 * tree-ssa-ccp.cc (pass_fold_builtins::execute): Do not remove indirect clobbers here ... * tree-outof-ssa.cc (rewrite_out_of_ssa): ... but here. (remove_indirect_clobbers): New function. * g++.dg/warn/Wuninitialized-pr111123-1.C: New testcase. --- .../g++.dg/warn/Wuninitialized-pr111123-1.C | 20 ++++++++++++ gcc/tree-outof-ssa.cc | 32 ++++++++++++++++++- gcc/tree-ssa-ccp.cc | 17 +--------- 3 files changed, 52 insertions(+), 17 deletions(-) create mode 100644 gcc/testsuite/g++.dg/warn/Wuninitialized-pr111123-1.C diff --git a/gcc/testsuite/g++.dg/warn/Wuninitialized-pr111123-1.C b/gcc/testsuite/g++.dg/warn/Wuninitialized-pr111123-1.C new file mode 100644 index 00000000000..17a6f2b28d8 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wuninitialized-pr111123-1.C @@ -0,0 +1,20 @@ +// { dg-do compile } +// { dg-require-effective-target c++11 } +// { dg-options "-O -Wuninitialized" } + +#include + +struct Camera { + struct P2d { + float x, y; + }; + std::vector clip_area; + float border = 10.f; + [[gnu::noinline]] Camera() : clip_area({{border,border}}) { } // { dg-warning "uninitialized" } +}; + +Camera foo() +{ + Camera c; + return c; +} diff --git a/gcc/tree-outof-ssa.cc b/gcc/tree-outof-ssa.cc index 0bf57a4bbc5..767623ab8ea 100644 --- a/gcc/tree-outof-ssa.cc +++ b/gcc/tree-outof-ssa.cc @@ -1283,6 +1283,33 @@ insert_backedge_copies (void) } } +/* Remove indirect clobbers. */ + +static void +remove_indirect_clobbers (void) +{ + basic_block bb; + + FOR_EACH_BB_FN (bb, cfun) + for (auto gsi = gsi_start_bb (bb); !gsi_end_p (gsi);) + { + gimple *stmt = gsi_stmt (gsi); + if (gimple_clobber_p (stmt)) + { + tree lhs = gimple_assign_lhs (stmt); + if (TREE_CODE (lhs) == MEM_REF + && TREE_CODE (TREE_OPERAND (lhs, 0)) == SSA_NAME) + { + unlink_stmt_vdef (stmt); + gsi_remove (&gsi, true); + release_defs (stmt); + continue; + } + } + gsi_next (&gsi); + } +} + /* Free all memory associated with going out of SSA form. SA is the outof-SSA info object. */ @@ -1305,6 +1332,10 @@ finish_out_of_ssa (struct ssaexpand *sa) unsigned int rewrite_out_of_ssa (struct ssaexpand *sa) { + /* Remove remaining indirect clobbers as we do not need those anymore. + Those might extend SSA lifetime and restrict coalescing. */ + remove_indirect_clobbers (); + /* If elimination of a PHI requires inserting a copy on a backedge, then we will have to split the backedge which has numerous undesirable performance effects. @@ -1313,7 +1344,6 @@ rewrite_out_of_ssa (struct ssaexpand *sa) copies into the loop itself. */ insert_backedge_copies (); - /* Eliminate PHIs which are of no use, such as virtual or dead phis. */ eliminate_useless_phis (); diff --git a/gcc/tree-ssa-ccp.cc b/gcc/tree-ssa-ccp.cc index 15e65f16008..e048675577f 100644 --- a/gcc/tree-ssa-ccp.cc +++ b/gcc/tree-ssa-ccp.cc @@ -4302,22 +4302,7 @@ pass_fold_builtins::execute (function *fun) if (gimple_code (stmt) != GIMPLE_CALL) { - /* Remove all *ssaname_N ={v} {CLOBBER}; stmts, - after the last GIMPLE DSE they aren't needed and might - unnecessarily keep the SSA_NAMEs live. */ - if (gimple_clobber_p (stmt)) - { - tree lhs = gimple_assign_lhs (stmt); - if (TREE_CODE (lhs) == MEM_REF - && TREE_CODE (TREE_OPERAND (lhs, 0)) == SSA_NAME) - { - unlink_stmt_vdef (stmt); - gsi_remove (&i, true); - release_defs (stmt); - continue; - } - } - else if (gimple_assign_load_p (stmt) && gimple_store_p (stmt)) + if (gimple_assign_load_p (stmt) && gimple_store_p (stmt)) optimize_memcpy (&i, gimple_assign_lhs (stmt), gimple_assign_rhs1 (stmt), NULL_TREE); gsi_next (&i);