[llvm-bugs] [Bug 45288] New: [missed optimization] failure to drop unused string if initialized after construction

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Mar 23 15:45:21 PDT 2020


https://bugs.llvm.org/show_bug.cgi?id=45288

            Bug ID: 45288
           Summary: [missed optimization] failure to drop unused string if
                    initialized after construction
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: eyalroz at technion.ac.il
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk

(GodBolt example: https://godbolt.org/z/tYM3kS )

Consider the following two functions:

  void foo() {
      std::string s { "This is not a small string" };
  }

  void bar() {
      std::string s;
      s = "This is not a small string";
  }

clang++ is allowed, and should, optimize away the local string, and just have
these functions do nothing, compiling to :

  foo():
          ret
  bar():
          ret

but in fact (and with libc++), the string is dropped only for the first
function, not the second one:

foo():                                # @foo()
        ret
bar():                                # @bar()
        push    rbx
        sub     rsp, 32
        xorps   xmm0, xmm0
        movaps  xmmword ptr [rsp], xmm0
        mov     qword ptr [rsp + 16], 0
        mov     rdi, rsp
        mov     esi, offset .L.str
        call    std::__1::basic_string<char, std::__1::char_traits<char>,
std::__1::allocator<char> >::assign(char const*)
        test    byte ptr [rsp], 1
        je      .LBB1_3
        mov     rdi, qword ptr [rsp + 16]
        call    operator delete(void*)
.LBB1_3:
        add     rsp, 32
        pop     rbx
        ret
        mov     rbx, rax
        test    byte ptr [rsp], 1
        je      .LBB1_6
        mov     rdi, qword ptr [rsp + 16]
        call    operator delete(void*)
.LBB1_6:
        mov     rdi, rbx
        call    _Unwind_Resume
.L.str:
        .asciz  "This is not a small string"

This bug seems very much related to 45287, although here it's all libc++ code,
no libstdc++ involved. Still, I'm seeing exception code, which makes me assume
this also depends on 35052.

-- 
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/20200323/fd176a79/attachment.html>


More information about the llvm-bugs mailing list