public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "hiraditya at msn dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/111806] New: g++ generates better code for variant<string, bool> at -Os compared to -O3
Date: Sat, 14 Oct 2023 06:02:01 +0000	[thread overview]
Message-ID: <bug-111806-4@http.gcc.gnu.org/bugzilla/> (raw)

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111806

            Bug ID: 111806
           Summary: g++ generates better code for variant<string, bool> at
                    -Os compared to -O3
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: hiraditya at msn dot com
  Target Milestone: ---

#include<variant>
#include<string>
#include<iostream>

int foo() {
    std::variant<std::string, bool> v {"abc"};
    std::cout << std::get<0>(v);
    return 0;
}

g++ -O3 -std=c++20 -g0  -fno-exceptions

foo():
.LFB2484:
        push    rbx
        mov     eax, 25185
        mov     edx, 3
        mov     edi, OFFSET FLAT:_ZSt4cout
        sub     rsp, 48
        lea     rbx, [rsp+16]
        mov     WORD PTR [rsp+16], ax
        mov     rsi, rbx
        mov     QWORD PTR [rsp], rbx
        mov     BYTE PTR [rsp+18], 99
        mov     QWORD PTR [rsp+8], 3
        mov     BYTE PTR [rsp+19], 0
        mov     BYTE PTR [rsp+32], 0
        call    std::basic_ostream<char, std::char_traits<char> >&
std::__ostream_insert<char, std::char_traits<char> >(std::basic_ostream<char,
std::char_traits<char> >&, char const*, long)
        cmp     BYTE PTR [rsp+32], 0
        je      .L5
.L2:
        add     rsp, 48
        xor     eax, eax
        pop     rbx
        ret
.L5:
        mov     rdi, QWORD PTR [rsp]
        cmp     rdi, rbx
        je      .L2
        mov     rax, QWORD PTR [rsp+16]
        lea     rsi, [rax+1]
        call    operator delete(void*, unsigned long)
        add     rsp, 48
        xor     eax, eax
        pop     rbx
        ret
.LFE2484:


g++ -Os -std=c++20 -g0  -fno-exceptions


foo():
.LFB2463:
        push    rbx
        mov     edx, 3
        mov     edi, OFFSET FLAT:_ZSt4cout
        sub     rsp, 48
        lea     rbx, [rsp+24]
        mov     WORD PTR [rsp+24], 25185
        mov     rsi, rbx
        mov     QWORD PTR [rsp+8], rbx
        mov     BYTE PTR [rsp+26], 99
        mov     QWORD PTR [rsp+16], 3
        mov     BYTE PTR [rsp+27], 0
        mov     BYTE PTR [rsp+40], 0
        call    std::basic_ostream<char, std::char_traits<char> >&
std::__ostream_insert<char, std::char_traits<char> >(std::basic_ostream<char,
std::char_traits<char> >&, char const*, long)
        cmp     BYTE PTR [rsp+40], 0
        jne     .L2
        mov     rdi, QWORD PTR [rsp+8]
        cmp     rdi, rbx
        je      .L2
        mov     rax, QWORD PTR [rsp+24]
        lea     rsi, [rax+1]
        call    operator delete(void*, unsigned long)
.L2:
        add     rsp, 48
        xor     eax, eax
        pop     rbx
        ret
.LFE2463:


https://godbolt.org/z/3xKh35Mrv

             reply	other threads:[~2023-10-14  6:02 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-14  6:02 hiraditya at msn dot com [this message]
2023-10-14  6:05 ` [Bug c++/111806] " hiraditya at msn dot com
2023-10-14 15:27 ` [Bug middle-end/111806] " pinskia at gcc dot gnu.org

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=bug-111806-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@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).