[llvm-bugs] [Bug 37574] New: Vector construction of trivial types using const iterator ranges are not optimized like non-const iterator ranges

via llvm-bugs llvm-bugs at lists.llvm.org
Wed May 23 19:11:57 PDT 2018


https://bugs.llvm.org/show_bug.cgi?id=37574

            Bug ID: 37574
           Summary: Vector construction of trivial types using const
                    iterator ranges are not optimized like non-const
                    iterator ranges
           Product: libc++
           Version: 6.0
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: All Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: kjteske at gmail.com
                CC: llvm-bugs at lists.llvm.org, mclow.lists at gmail.com

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.

-- 
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/20180524/fc520361/attachment.html>


More information about the llvm-bugs mailing list