[libc++] Add __default_init_tag to basic_string constructors
authorEric Fiselier <eric@efcs.ca>
Tue, 17 Dec 2019 00:03:23 +0000 (19:03 -0500)
committerEric Fiselier <eric@efcs.ca>
Tue, 17 Dec 2019 00:04:09 +0000 (19:04 -0500)
commita53534a9f6404d1727fd6e9b13b6dc3089523e10
tree32fafb745b7252fe2bb0cfecc909b6a3c240c891
parent204dfabfe68a978620258baaa0bacb55cbd6859d
[libc++] Add __default_init_tag to basic_string constructors

This removes unneeded zero initialization of string data.

For example, given the below code:

void Init(void *mem) {
    new (mem) std::string("Hello World");
}

Assembly before:

Init(void*):
        xorps   xmm0, xmm0
        movups  xmmword ptr [rdi], xmm0
        mov     qword ptr [rdi + 16], 0
        mov     byte ptr [rdi], 22
        movabs  rax, 8022916924116329800
        mov     qword ptr [rdi + 1], rax
        mov     dword ptr [rdi + 8], 1684828783
        mov     byte ptr [rdi + 12], 0
        ret

Assembly after:

Init():
        mov     byte ptr [rdi], 22
        movabs  rax, 8022916924116329800
        mov     qword ptr [rdi + 1], rax
        mov     dword ptr [rdi + 8], 1684828783
        mov     byte ptr [rdi + 12], 0
        ret

Patch by Martijn Vels (mvels@google.com)
Reviewed as https://reviews.llvm.org/D70621
libcxx/include/string