public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* C++ copy elision and escaping address of return slot
@ 2021-06-02 10:03 Liu Hao
  2021-06-02 12:31 ` Marc Glisse
  0 siblings, 1 reply; 3+ messages in thread
From: Liu Hao @ 2021-06-02 10:03 UTC (permalink / raw)
  To: gcc-help


[-- Attachment #1.1: Type: text/plain, Size: 874 bytes --]

Deal all,

Recently, we have identified some performance penalty and code bloat, as described in [1].

This blog suggests that sometimes `-fno-elide-constructors` may result in better code. This is true 
for its tiny example, as `std::unique_ptr` is shim enough that GCC optimizes it well even without 
copy elision.

But not everything can be moved with insignificant costs, especially when the target move 
constructor has to be dispatched via an indirect call, e.g. for `std::variant` and `std::function`. 
So, this concludes to a tradeoff, and my tests suggest no performance benefit.

However I expect there to be a better way to mitigate this: Is it possible to inform GCC to assume 
that the return slot cannot alias anything?


[1] https://quuxplusone.github.io/blog/2021/03/07/copy-elision-borks-escape-analysis/


-- 
Best regards,
Liu Hao


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 840 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: C++ copy elision and escaping address of return slot
  2021-06-02 10:03 C++ copy elision and escaping address of return slot Liu Hao
@ 2021-06-02 12:31 ` Marc Glisse
  2021-06-02 13:05   ` lhmouse
  0 siblings, 1 reply; 3+ messages in thread
From: Marc Glisse @ 2021-06-02 12:31 UTC (permalink / raw)
  To: Liu Hao; +Cc: gcc-help

On Wed, 2 Jun 2021, Liu Hao via Gcc-help wrote:

> However I expect there to be a better way to mitigate this: Is it possible to 
> inform GCC to assume that the return slot cannot alias anything?

I assume we will eventually fix
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80740
it shouldn't be too hard assuming we agree that it is legal.

I am not aware of a way for a user to add restrict on the hidden return 
pointer.

-- 
Marc Glisse

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re:Re: C++ copy elision and escaping address of return slot
  2021-06-02 12:31 ` Marc Glisse
@ 2021-06-02 13:05   ` lhmouse
  0 siblings, 0 replies; 3+ messages in thread
From: lhmouse @ 2021-06-02 13:05 UTC (permalink / raw)
  To: gcc-help

在 6/2/21 8:31 PM, Marc Glisse 写道:
> On Wed, 2 Jun 2021, Liu Hao via Gcc-help wrote:
>
>> However I expect there to be a better way to mitigate this: Is it possible to inform GCC to assume
>> that the return slot cannot alias anything?
>
> I assume we will eventually fix
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80740
> it shouldn't be too hard assuming we agree that it is legal.
>
> I am not aware of a way for a user to add restrict on the hidden return pointer.
>

Does that testcase really exist in real codebases? I think it is reasonable to ignore such possibility.

And since you mentioned Clang in that PR: Do you know that Clang assumes an `unsigned short` parameter that is passed via a 32-bit register has its all upper half bits as zeroes [1]? This of course violates psABI, but there has been no problem in practice. Pedantry is sometimes hindrance.


[1] https://gcc.godbolt.org/z/4eoTPdoGx


--
Best regards,
Liu Hao






^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-06-02 13:05 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-02 10:03 C++ copy elision and escaping address of return slot Liu Hao
2021-06-02 12:31 ` Marc Glisse
2021-06-02 13:05   ` lhmouse

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).