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

Reply via email to