From: Marc Glisse Date: Fri, 19 Jun 2020 11:07:33 +0000 (+0100) Subject: libstdc++: Optimize std::optional default constructor X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=bafd12cb22e83b7da8946873513a897e48e2900f;p=gcc.git libstdc++: Optimize std::optional default constructor The attached patch changes the code generated for std::optional>f(){return{};} from movq $0, (%rdi) movq %rdi, %r8 leaq 8(%rdi), %rdi xorl %eax, %eax movq $0, 4084(%rdi) movq %r8, %rcx andq $-8, %rdi subq %rdi, %rcx addl $4100, %ecx shrl $3, %ecx rep stosq movq %r8, %rax or with different tuning subq $8, %rsp movl $4100, %edx xorl %esi, %esi call memset addq $8, %rsp to the much shorter movb $0, 4096(%rdi) movq %rdi, %rax i.e. the same as the nullopt constructor. The constructor was already non-trivial, so we don't lose that. It passes the testsuite without regression, but there is no new testcase to verify the better codegen. libstdc++-v3/ChangeLog: * include/std/optional (optional()): Explicitly define it. --- diff --git a/libstdc++-v3/include/std/optional b/libstdc++-v3/include/std/optional index b0184a4e1c0..923d45ae0e8 100644 --- a/libstdc++-v3/include/std/optional +++ b/libstdc++-v3/include/std/optional @@ -687,7 +687,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION public: using value_type = _Tp; - constexpr optional() = default; + constexpr optional() noexcept { } constexpr optional(nullopt_t) noexcept { }