[all-commits] [llvm/llvm-project] 38595f: [libc++] Remove a few unnecessary branches from ba...

Nikolas Klauser via All-commits all-commits at lists.llvm.org
Wed May 7 07:54:55 PDT 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 38595fb257fee32aaa3b45ff73c3ceaac86e9143
      https://github.com/llvm/llvm-project/commit/38595fb257fee32aaa3b45ff73c3ceaac86e9143
  Author: Nikolas Klauser <nikolasklauser at berlin.de>
  Date:   2025-05-07 (Wed, 07 May 2025)

  Changed paths:
    M libcxx/include/__string/char_traits.h

  Log Message:
  -----------
  [libc++] Remove a few unnecessary branches from basic_string::find (#137266)

I've recently looked at the assembly for `basic_string::find()` and
realized that there were a few branches I didn't expect. It turns out
that we check for null before calling `__constexpr_memchr` in some
cases, which the compiler doesn't optimize away. This is a really
uncommon case though, so I'm not convinced it makes a ton of sense to
optimize for that.

The second case is where `__pos >= __sz`. There, we can instead check
`__pos > __sz`, which the optimizer is able to remove if `__pos == 0`,
which is also a quite common case (basic_string::find(CharT), without an
explicit size parameter).



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list