public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
From: Martin Liska <marxin@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org
Subject: [gcc(refs/users/marxin/heads/cond-expr-ssa-name)] libstdc++: Optimize std::optional default constructor
Date: Wed, 24 Jun 2020 09:20:59 +0000 (GMT)	[thread overview]
Message-ID: <20200624092059.8A9C03938C3A@sourceware.org> (raw)

https://gcc.gnu.org/g:bafd12cb22e83b7da8946873513a897e48e2900f

commit bafd12cb22e83b7da8946873513a897e48e2900f
Author: Marc Glisse <marc.glisse@inria.fr>
Date:   Fri Jun 19 12:07:33 2020 +0100

    libstdc++: Optimize std::optional default constructor
    
    The attached patch changes the code generated for
    
    std::optional<std::array<int,1024>>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:
---
 libstdc++-v3/include/std/optional | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

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 { }


                 reply	other threads:[~2020-06-24  9:20 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200624092059.8A9C03938C3A@sourceware.org \
    --to=marxin@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    --cc=libstdc++-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).