Open firewave opened 2 years ago
Could you please clarify which standard C++ library was used?
I am using libstdc++
.
From a first glance, it seems like the std::vector
case is optimized away because LLVM is able the inline the full std::vector
constructor and the ::push
calls. That appears to not be the case for the std::deque
case
I am confused, how is this different to #53268?
@llvm/issue-subscribers-clang-codegen
I am confused, how is this different to #53268?
This is about the std::deque
constructor being more expensive than GCC. The other one is about dead code elimination with std::deque
which neither compiler does. So it seems like two different things possibly depending on the same underlying behavior.
This is about the std::deque constructor being more expensive than GCC. The other one is about dead code elimination with std::deque which neither compiler does. So it seems like two different things possibly depending on the same underlying behavior.
Right, but the reason it is more expensive (_M_initialize_map
call not eliminated) is also the reason the code cannot be eliminated.
Right, but the reason it is more expensive (
_M_initialize_map
call not eliminated) is also the reason the code cannot be eliminated.
If that is the case feel free to close one of them as a duplicate.
I came across this while working on https://github.com/danmar/cppcheck/pull/3716.
Using
std::stack
in Clang with the defaultstd::deque
backend is more expensive than doing so in GCC. It's about 10% slower. In the case I came across this I was able to speed this up usingstd::vector
instead. That actually helped both compilers but Clang profited more from that.The problem is the
std::_Deque_base<void*, std::allocator<void*> >::_M_initialize_map(unsigned long)
which GCC does not generate in the code - see https://godbolt.org/z/v1d9GsGnW.Here's some sample code I used for profiling with
-O2
andcallgrind
:Total Ir: Clang
43,790,737
GCC39,794,842