C++ copy elision and escaping address of return slot

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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: OpenPGP_signature
Description: OpenPGP digital signature


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux