C++ copy elision and escaping address of return slot
Liu Hao
lh_mouse@126.com
Wed Jun 2 10:03:54 GMT 2021
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature
Type: application/pgp-signature
Size: 840 bytes
Desc: OpenPGP digital signature
URL: <https://gcc.gnu.org/pipermail/gcc-help/attachments/20210602/50d49f87/attachment-0001.sig>
More information about the Gcc-help
mailing list