[libcxx-commits] [PATCH] D131395: [libc++] Implement `lexicographical_compare_three_way`
Adrian Vogelsgesang via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Aug 8 09:00:22 PDT 2022
avogelsgesang added a comment.
> I am not sure I follow the bit about the implementation not being as efficient as could be. Are you essentially suggesting that the 3rd implementation in https://godbolt.org/z/6sTfePhPq would be more efficient but more complicated?
Yes. In the 3rd implementation, the actual loop over the entries (basic block `LBB0_2`) consists of 6 instructions, all of them seem indeed necessary.
In contrast, the loops in the other two implementations (basic block `LBB0_3`) are more bloated.
The 3rd implementation is also not perfect. E.g., `cmp rdx, rcx` is duplicated both in lines 16 and 21. It should be possible for clang to reuse the comparison result instead.
Afaict, we could use implementation 3 in libc++ behind an `if constexpr (is_same_v<iterator_traits<_InputIter>::iterator_category, random_access_iterator_tag>)` (or similar).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D131395/new/
https://reviews.llvm.org/D131395
More information about the libcxx-commits
mailing list