From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 208E43858D37; Tue, 27 Jun 2023 06:41:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 208E43858D37 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1687848096; bh=v9xsk1CjsKl1zGBm2wJvlcGnBoD2ZLuKv7wEI/uKhE4=; h=From:To:Subject:Date:In-Reply-To:References:From; b=sEGqZPvQas6QRZCk1diVQNwWpscmQNOPhngp5/nUnGX/UqDa8CEqF/m/wbUeLRdqf 9s0Ucwbf7pkEH4qAPwj2Kb8lF9/peoNd/hrz0aDPpib2S0iSiwb5T6KUd/e+wbTpT0 m290bi2ZYurb0Y+Mkephqx/6WZhb50els8m7miHw= From: "rguenther at suse dot de" To: gcc-bugs@gcc.gnu.org Subject: [Bug ipa/110334] [13/14 Regresssion] unused functions not eliminated before LTO streaming Date: Tue, 27 Jun 2023 06:41:34 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: ipa X-Bugzilla-Version: 13.1.1 X-Bugzilla-Keywords: lto, missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: rguenther at suse dot de X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: 13.2 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D110334 --- Comment #12 from rguenther at suse dot de --- On Mon, 26 Jun 2023, hubicka at ucw dot cz wrote: > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D110334 >=20 > --- Comment #11 from Jan Hubicka --- > Hi, > what about this. It should make at least quite basic inlining to happen > to always_inline. I do not think many critical always_inlines have > indirect calls in them. The test for lto is quite bad and I can > work on solving this incrementally (it would be nice to have this > tested and possibly backport it). >=20 > diff --git a/gcc/ipa-inline.cc b/gcc/ipa-inline.cc > index efc8df7d4e0..dcec07e49e1 100644 > --- a/gcc/ipa-inline.cc > +++ b/gcc/ipa-inline.cc > @@ -702,6 +702,38 @@ can_early_inline_edge_p (struct cgraph_edge *e) > if (!can_inline_edge_p (e, true, true) > || !can_inline_edge_by_limits_p (e, true, false, true)) > return false; > + /* When inlining regular functions into always-inline functions > + during early inlining watch for possible inline cycles. */ > + if (DECL_DISREGARD_INLINE_LIMITS (caller->decl) > + && lookup_attribute ("always_inline", DECL_ATTRIBUTES (caller->dec= l)) > + && (!DECL_DISREGARD_INLINE_LIMITS (callee->decl) > + || !lookup_attribute ("always_inline", DECL_ATTRIBUTES > (callee->decl)))) > + { > + /* If there are indirect calls, inlining may produce direct call. > + TODO: We may lift this restriction if we avoid errors on formely > + indirect calls to always_inline functions. Taking address > + of always_inline function is generally bad idea and should > + have been declared as undefined, but sadly we allow this. */ > + if (caller->indirect_calls || e->callee->indirect_calls) why disallow caller->indirect_calls? > + return false; > + for (cgraph_edge *e2 =3D callee->callees; e2; e2 =3D e2->next_call= ee) I don't think this flys - it looks quadratic. Can we compute this in the inline summary once instead? As for indirect calls, can we maybe mark initial direct GIMPLE call stmts as "always-inline" and only look at that marking, thus an indirect call will never become "always-inline"? Iff cgraph edges prevail during all early inlining we could mark call edges for this purpose? > + { > + struct cgraph_node *callee2 =3D e2->callee->ultimate_alias_targ= et (); > + /* As early inliner runs in RPO order, we will see uninlined > + always_inline calls only in the case of cyclic graphs. */ > + if (DECL_DISREGARD_INLINE_LIMITS (callee2->decl) > + || lookup_attribute ("always_inline", callee2->decl)) > + return false; > + /* With LTO watch for case where function is later replaced > + by always_inline definition. > + TODO: We may either stop treating noninlined cross-module al= ways > + inlines as errors, or we can extend decl merging to produce > + syntacic alias and honor always inline only in units it has > + been declared as such. */ > + if (flag_lto && callee2->externally_visible) > + return false; > + } > + } > return true; > } >=20 > @@ -3034,18 +3066,7 @@ early_inliner (function *fun) >=20 > if (!optimize > || flag_no_inline > - || !flag_early_inlining > - /* Never inline regular functions into always-inline functions > - during incremental inlining. This sucks as functions calling > - always inline functions will get less optimized, but at the > - same time inlining of functions calling always inline > - function into an always inline function might introduce > - cycles of edges to be always inlined in the callgraph. > - > - We might want to be smarter and just avoid this type of inlining= . */ > - || (DECL_DISREGARD_INLINE_LIMITS (node->decl) > - && lookup_attribute ("always_inline", > - DECL_ATTRIBUTES (node->decl)))) > + || !flag_early_inlining) > ; > else if (lookup_attribute ("flatten", > DECL_ATTRIBUTES (node->decl)) !=3D NULL) >=20 >=