Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vector construction of trivial types using const iterator ranges are not optimized like non-const iterator ranges #36922

Closed
kjteske opened this issue May 24, 2018 · 2 comments
Labels
bugzilla Issues migrated from bugzilla libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.

Comments

@kjteske
Copy link

kjteske commented May 24, 2018

Bugzilla Link 37574
Resolution FIXED
Resolved on Jan 08, 2019 16:03
Version 6.0
OS All
CC @kjteske,@mclow,@vsapsai
Fixed by commit(s) 349676 350583

Extended Description

In https://reviews.llvm.org/D8109, vector construction is optimized for trivial types using an iterator range, i.e. std::vector(int* first, int* last). However, there is a bug so that const iterators are not optimized as expected, i.e. std::vector(const int* first, const int* last).

We're not hitting the memcpy overload of __construct_range_forward(). We're taking the slow overload instead, I believe because 'is_same<allocator_type, allocator<_Tp> >::value' check on the fast overload passes when _Tp is 'int', but fails when _Tp is 'const int'.

libstdc++ does optimize the const int* version.

Workaround is to const_cast<> away the const before calling the vector constructor.

In our application, the workaround improves performance by 4-5x.

@vsapsai
Copy link
Collaborator

vsapsai commented Jun 20, 2018

Fix for this issue is published for review at https://reviews.llvm.org/D48342

@vsapsai
Copy link
Collaborator

vsapsai commented Jan 9, 2019

Fixed in r349676 and r350583.

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Projects
None yet
Development

No branches or pull requests

2 participants