https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102528

--- Comment #3 from Iain Sandoe <iains at gcc dot gnu.org> ---
 (In reply to Mathias Stearn from comment #0)
 > https://godbolt.org/z/aoab9W4xG
 > 
 > 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 optimisation.

On the other hand, to say that the emitted code is unused is not quite right;

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 referred
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 failure
to elide unused code.

Reply via email to