LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 37574 - Vector construction of trivial types using const iterator ranges are not optimized like non-const iterator ranges
Summary: Vector construction of trivial types using const iterator ranges are not opti...
Status: RESOLVED FIXED
Alias: None
Product: libc++
Classification: Unclassified
Component: All Bugs (show other bugs)
Version: 6.0
Hardware: PC All
: P normal
Assignee: Unassigned Clang Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-05-23 19:11 PDT by Kyle Teske
Modified: 2019-01-08 16:03 PST (History)
5 users (show)

See Also:
Fixed By Commit(s): 349676 350583


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Kyle Teske 2018-05-23 19:11:57 PDT
In https://reviews.llvm.org/D8109, vector construction is optimized for trivial types using an iterator range, i.e. std::vector<int>(int* first, int* last). However, there is a bug so that const iterators are not optimized as expected, i.e. std::vector<int>(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.
Comment 1 Volodymyr Sapsai 2018-06-19 17:36:38 PDT
Fix for this issue is published for review at https://reviews.llvm.org/D48342
Comment 2 Volodymyr Sapsai 2019-01-08 16:03:38 PST
Fixed in r349676 and r350583.