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: unassignedclangb...@nondot.org
Reporter: eyal...@technion.ac.il
CC: blitzrak...@gmail.com, dgre...@apple.com,
erik.pilking...@gmail.com, llvm-bugs@lists.llvm.org,
richard-l...@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.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs