From patchwork Tue Jan 18 12:52:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 50158 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 CE43B3857C4C for ; Tue, 18 Jan 2022 12:53:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CE43B3857C4C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1642510401; bh=Y++4Bc/IhcH5qHl7gPvlQ9+ZEFboRnmueTUslNQkqtY=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=dJvWqsdIR0vuqxTWegj6xZZA92DFB8nf0azjqePi17lW/qiNzm5jf52+YUNR9Ko9E JoTp+6B8eWI5dNxiSzuGfz0O7yFNyUKopGqVAJRN0zxOkFmtMNpjXF42kCabMLRE0F 9pMXAJ21qxNXVnsb6VUpFutxx6RuELtxA4CjEkX0= 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 A30383858438 for ; Tue, 18 Jan 2022 12:52:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A30383858438 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 78EDA2171F; Tue, 18 Jan 2022 12:52:51 +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 6100A13A42; Tue, 18 Jan 2022 12:52:51 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id Y6KWFiO45mHMfwAAMHmgww (envelope-from ); Tue, 18 Jan 2022 12:52:51 +0000 Date: Tue, 18 Jan 2022 13:52:51 +0100 (CET) To: gcc-patches@gcc.gnu.org Subject: [PATCH] ipa/103989 - avoid IPA inlining of small functions with -Og Message-ID: MIME-Version: 1.0 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.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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 Cc: Jan Hubicka Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" The following change avoids doing IPA inlining of small functions into functions compiled with -Og - those functions will see almost no followup scalar cleanups so that the benefit anticipated by the inliner will not be realized and instead the late diagnostic code will be confused by dead code that is left around. Bootstrap & regtest pending on x86_64-unknown-linux-gnu. OK? Thanks, Richard. 2022-01-18 Richard Biener PR ipa/103989 * ipa-inline.cc (inline_small_functions): Do not enqueue call edges originating in functions compiled with -Og. * g++.dg/opt/pr103989.C: New testcase. --- gcc/ipa-inline.cc | 7 ++++++- gcc/testsuite/g++.dg/opt/pr103989.C | 30 +++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/opt/pr103989.C diff --git a/gcc/ipa-inline.cc b/gcc/ipa-inline.cc index 38522771118..f8bb072c422 100644 --- a/gcc/ipa-inline.cc +++ b/gcc/ipa-inline.cc @@ -2029,7 +2029,12 @@ inline_small_functions (void) struct cgraph_edge *next = NULL; bool has_speculative = false; - if (!opt_for_fn (node->decl, optimize)) + if (!opt_for_fn (node->decl, optimize) + /* With -Og we do not want to perform IPA inlining of small + functions since there are no scalar cleanups after it + that would realize the anticipated win. All abstraction + is removed during early inlining. */ + || opt_for_fn (node->decl, optimize_debug)) continue; if (dump_file) diff --git a/gcc/testsuite/g++.dg/opt/pr103989.C b/gcc/testsuite/g++.dg/opt/pr103989.C new file mode 100644 index 00000000000..4604811b42a --- /dev/null +++ b/gcc/testsuite/g++.dg/opt/pr103989.C @@ -0,0 +1,30 @@ +// { dg-require-effective-target c++17 } +// { dg-options "-Og -Wall" } + +#include +#include + +struct A { + A (int a) : a {a} + {} + + const std::shared_ptr x; + int a; +}; + +class B +{ +public: + B (const std::optional & a) + : a {a} + { + } +public: + const std::optional a; +}; + +int +main () +{ + B b {std::nullopt}; +}