public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/96562] New: Rather poor assembly generated for copy-list-initialization in return statement.
@ 2020-08-10 22:04 maxim.yegorushkin at gmail dot com
  2020-08-10 22:19 ` [Bug target/96562] " maxim.yegorushkin at gmail dot com
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: maxim.yegorushkin at gmail dot com @ 2020-08-10 22:04 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 96562
           Summary: Rather poor assembly generated for
                    copy-list-initialization in return statement.
           Product: gcc
           Version: 10.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: maxim.yegorushkin at gmail dot com
  Target Milestone: ---

Rather poor assembly generated for trivial code.

The following code:

    template<class P, class SizeT>
    struct Span {
        P begin_;
        SizeT size_;
    };

    Span<char*, unsigned> f(char* p, char* q) {
        return {p, static_cast<unsigned>(q - p)};
    }

When compiled with gcc-6.1 to gcc-10.2 with options "-O3 -march=skylake
-mtune=skylake" produces unexpectedly long and sub-optimal assembly code:

    f(unsigned char*, unsigned char*):
        mov     QWORD PTR [rsp-16], 0
        mov     QWORD PTR [rsp-24], rdi
        sub     rsi, rdi
        vmovdqa xmm1, XMMWORD PTR [rsp-24]
        vpinsrd xmm0, xmm1, esi, 2
        vmovdqa XMMWORD PTR [rsp-24], xmm0
        mov     rax, QWORD PTR [rsp-24]
        mov     rdx, QWORD PTR [rsp-16]
        ret

clang with the same options produces the expected assembly:

    f(unsigned char*, unsigned char*):
        mov     rdx, rsi
        mov     rax, rdi
        sub     edx, eax
        ret

Is there a way to make gcc produce the expected assembly, please?

https://gcc.godbolt.org/z/bacGW8

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2020-08-25  8:17 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-10 22:04 [Bug target/96562] New: Rather poor assembly generated for copy-list-initialization in return statement maxim.yegorushkin at gmail dot com
2020-08-10 22:19 ` [Bug target/96562] " maxim.yegorushkin at gmail dot com
2020-08-11  1:31 ` hjl.tools at gmail dot com
2020-08-11  7:01 ` crazylht at gmail dot com
2020-08-11  8:23 ` crazylht at gmail dot com
2020-08-11 11:04 ` maxim.yegorushkin at gmail dot com
2020-08-12  3:15 ` crazylht at gmail dot com
2020-08-18  6:20 ` cvs-commit at gcc dot gnu.org
2020-08-18  6:24 ` cvs-commit at gcc dot gnu.org
2020-08-18  6:29 ` crazylht at gmail dot com
2020-08-25  8:17 ` rguenth at gcc dot gnu.org

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).