[libcxx-commits] [PATCH] D131395: [libc++] Implement `lexicographical_compare_three_way`

Mark de Wever via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Mon Aug 8 10:33:31 PDT 2022


Mordante added a comment.

In D131395#3706881 <https://reviews.llvm.org/D131395#3706881>, @avogelsgesang wrote:

>> 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).

I'm perfectly fine with having it work and optimize later. Can you add a TODO and a link to the comment above in the source? That way it's clear what we can improve.

(I haven't looked at the patch itself.)


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