[LLVMbugs] [Bug 19092] New: X() = default has poor code generation

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Sun Mar 9 17:17:30 PDT 2014


http://llvm.org/bugs/show_bug.cgi?id=19092

            Bug ID: 19092
           Summary: X() = default has poor code generation
           Product: clang
           Version: trunk
          Hardware: Macintosh
                OS: MacOS X
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++11
          Assignee: unassignedclangbugs at nondot.org
          Reporter: howard.hinnant at gmail.com
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified

Consider this code:

#include <vector>
#include <string>

class X
{
    std::vector<int> v_;
    std::string      s_;
    bool             q_ = false;
public:
#if 0
    X() {}
#elif 1
    X() = default;
#endif
};

X
test_default()
{
    return X{};
}

With a user-defined default constructor, test_default() (at -O3) generates:

__Z12test_defaultv:                     ## @_Z12test_defaultv
    .cfi_startproc
## BB#0:
    pushq    %rbp
Ltmp11:
    .cfi_def_cfa_offset 16
Ltmp12:
    .cfi_offset %rbp, -16
    movq    %rsp, %rbp
Ltmp13:
    .cfi_def_cfa_register %rbp
    movb    $0, 48(%rdi)
    movq    $0, 40(%rdi)
    movq    $0, 32(%rdi)
    movq    $0, 24(%rdi)
    movq    $0, 16(%rdi)
    movq    $0, 8(%rdi)
    movq    $0, (%rdi)
    movq    %rdi, %rax
    popq    %rbp
    ret
    .cfi_endproc

But if I instead use the presumably preferred X() = default technique to
generate the default constructor, I am severely penalized (by a factor of 2):

    .section    __TEXT,__text,regular,pure_instructions
    .globl    __Z12test_defaultv
    .align    4, 0x90
__Z12test_defaultv:                     ## @_Z12test_defaultv
    .cfi_startproc
## BB#0:                                ## %entry
    pushq    %rbp
Ltmp0:
    .cfi_def_cfa_offset 16
Ltmp1:
    .cfi_offset %rbp, -16
    movq    %rsp, %rbp
Ltmp2:
    .cfi_def_cfa_register %rbp
    movq    $0, 48(%rdi)
    movq    $0, 40(%rdi)
    movq    $0, 32(%rdi)
    movq    $0, 24(%rdi)
    movq    $0, 16(%rdi)
    movq    $0, 8(%rdi)
    movq    $0, (%rdi)
    movb    $0, 48(%rdi)
    movq    $0, 40(%rdi)
    movq    $0, 32(%rdi)
    movq    $0, 24(%rdi)
    movq    $0, 16(%rdi)
    movq    $0, 8(%rdi)
    movq    $0, (%rdi)
    movq    %rdi, %rax
    popq    %rbp
    retq
    .cfi_endproc


.subsections_via_symbols

This makes me hesitate to recommend "= default".  It doesn't look ready for
prime time.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20140310/f1805849/attachment.html>


More information about the llvm-bugs mailing list