[libcxx-commits] [libcxx] [libc++] Optimize string operator[] for known large inputs (PR #69500)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Fri Oct 20 17:49:27 PDT 2023


https://github.com/ldionne approved this pull request.

This LGTM. I tried finding a downside and I couldn't. In general I'm not a huge fan of adding complexity like this, but in this case we're basically leveraging information known at compile-time (when it is known) to generate better code, and we do that in one of the most important types in the library. So I feel like anything reasonable that improves performance here is welcome.

In particular, I suspect this might make it easier for the compiler to vectorize code in case we have multiple constant accesses side by side because we'd remove branches, but TBH I don't know. At least this optimization can't generate *worst* code, so that's really comforting.

@EricWF I'll wait until like the middle of next week before merging this to give you time to react in case you had any concerns (as suggested by your question).

https://github.com/llvm/llvm-project/pull/69500


More information about the libcxx-commits mailing list