public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/114342] New: suboptimal codegen of vector::vector(range)
@ 2024-03-14 23:25 hiraditya at msn dot com
  2024-03-14 23:32 ` [Bug middle-end/114342] " pinskia at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: hiraditya at msn dot com @ 2024-03-14 23:25 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 114342
           Summary: suboptimal codegen of vector::vector(range)
           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<vector>
#include <ranges>

std::vector<int> td() {
  int arr[]{-5, 10, 15, -5, 10, 15, -5, 10, 15, -5, 10, 15, -5, 10, 15, -5, 10,
15, -5, 10, 15,-5, 10, 15 -5, 10, 15, -5, 10, 15, -5, 10, 15, -5, 10, 15, -5,
10, 15, -5, 10, 15, -5, 10,-5, 10, 15, -5, 10, 15, -5, 10, 15, -5, 10, 15, -5,
10, 15, -5, 10,-5, 10, 15, -5, 10, 15, -5, 10, 15, -5, 10, 15, -5, 10, 15, -5,
10,-5, 10, 15, -5, 10, 15, -5, 10, 15, -5, 10, 15, -5, 10, 15, -5, 10,-5, 10,
15, -5, 10, 15, -5, 10, 15, -5, 10, 15, -5, 10, 15, -5, 10,};
  auto b = std::ranges::begin(arr);
  auto e = std::ranges::end(arr);
  std::vector<int> dd(b, e);
  return dd;
}

What is the reason for calling `rep movsq` twice?

$ gcc -O3 -std=c++23
```
td():
        push    rbp
        mov     esi, OFFSET FLAT:.LC0
        mov     ecx, 55
        pxor    xmm0, xmm0
        push    rbx
        mov     rbx, rdi
        sub     rsp, 456
        mov     QWORD PTR [rbx+16], 0
        mov     rbp, rsp
        movups  XMMWORD PTR [rbx], xmm0
        mov     rdi, rbp
        rep movsq
        mov     eax, DWORD PTR [rsi]
        mov     DWORD PTR [rdi], eax
        mov     edi, 444
        call    operator new(unsigned long)
        lea     rdx, [rax+444]
        mov     QWORD PTR [rbx], rax
        lea     rdi, [rax+8]
        mov     rsi, rbp
        mov     QWORD PTR [rbx+16], rdx
        mov     rcx, QWORD PTR [rsp]
        and     rdi, -8
        mov     QWORD PTR [rax], rcx
        mov     rcx, QWORD PTR [rsp+436]
        mov     QWORD PTR [rax+436], rcx
        sub     rax, rdi
        sub     rsi, rax
        add     eax, 444
        shr     eax, 3
        mov     ecx, eax
        mov     rax, rbx
        rep movsq
        mov     QWORD PTR [rbx+8], rdx
        add     rsp, 456
        pop     rbx
        pop     rbp
        ret
        mov     rbp, rax
        jmp     .L2
td() [clone .cold]:
.L2:
        mov     rdi, QWORD PTR [rbx]
        mov     rsi, QWORD PTR [rbx+16]
        sub     rsi, rdi
        test    rdi, rdi
        je      .L3
        call    operator delete(void*, unsigned long)
.L3:
        mov     rdi, rbp
        call    _Unwind_Resume
```

https://godbolt.org/z/5333db8Px

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

end of thread, other threads:[~2024-03-19 17:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-14 23:25 [Bug c++/114342] New: suboptimal codegen of vector::vector(range) hiraditya at msn dot com
2024-03-14 23:32 ` [Bug middle-end/114342] " pinskia at gcc dot gnu.org
2024-03-14 23:37 ` pinskia at gcc dot gnu.org
2024-03-19 17:26 ` hiraditya at msn dot com

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