[llvm-bugs] [Bug 45287] New: [missed optimization] failure to drop unused libstdc++ std::string
via llvm-bugs
llvm-bugs at lists.llvm.org
Mon Mar 23 15:22:33 PDT 2020
https://bugs.llvm.org/show_bug.cgi?id=45287
Bug ID: 45287
Summary: [missed optimization] failure to drop unused libstdc++
std::string
Product: clang
Version: trunk
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
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/rbkRSJ)
Consider the following program:
#include <string>
void foo() {
std::string s { "This is not a small string" };
}
If we compile this with clang++ and libc++, we get:
foo():
ret
but if we use libstdc++, we get:
foo():
sub rsp, 40
lea rax, [rsp + 24]
mov qword ptr [rsp + 8], rax
mov edi, 27
call operator new(unsigned long)
mov qword ptr [rsp + 8], rax
mov qword ptr [rsp + 24], 26
movups xmm0, xmmword ptr [rip + .L.str+10]
movups xmmword ptr [rax + 10], xmm0
movups xmm0, xmmword ptr [rip + .L.str]
movups xmmword ptr [rax], xmm0
mov qword ptr [rsp + 16], 26
mov byte ptr [rax + 26], 0
mov rdi, rax
call operator delete(void*)
add rsp, 40
ret
mov rdi, rax
call _Unwind_Resume
.L.str:
.asciz "This is not a small string"
Yikes! What's going on here? Can't clang++/LLVM notice an unused string without
some libc++ special sauce? Is it the new/delete pair that's exotic somehow?
It seems that the hint is at the bottom "call _Unwind_Resume". James Garret
notes (in comments on this related SO answer:
https://stackoverflow.com/a/60820696/1593077) that libstdc++'s std::string code
apparently has some try/catch somewhere which LLVM can't optimize away, because
of bug 35052. So, marking this as dependent on that one - and pinging you LLVM
devs to give it some much needed attention...
--
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/2b876b97/attachment.html>
More information about the llvm-bugs
mailing list