From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id DEB1A385AC33; Mon, 4 Oct 2021 19:31:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DEB1A385AC33 From: "iains at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/102528] Unused out-of-line functions emitted for trivial coroutines Date: Mon, 04 Oct 2021 19:31:15 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 11.2.1 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: iains at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- 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 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 04 Oct 2021 19:31:16 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D102528 --- Comment #3 from Iain Sandoe --- (In reply to Mathias Stearn from comment #0) > https://godbolt.org/z/aoab9W4xG >=20 > This should all compile away, and test() should just be a single ret > instruction. That is not what happens now, even with -O3. Hi Mathias, Yes, ideally, that would be the case - so I agree it's a missed optimisatio= n. On the other hand, to say that the emitted code is unused is not quite righ= t; We inline the ramp but fail to inline the 'actor' (i.e. the resume). GCC does not have 'halo' coroutine frame elision, so that we create a frame= in the inlined ramp, and that holds references to the resumer and destroyer. The net result is that all the code is "used" in the sense that it is refer= red to by the emitted test (). I have an idea (old not new) about altering the internal interfaces in the generated code to avoid a devirtualisation being necessary to see the inline opportunity - although I cannot be sure that this is the effect in play, it seems plausible. -- so the bottom line is that this is a failure to inline rather than a fai= lure to elide unused code.=