[libcxx-commits] [PATCH] D59999: Allow the compiler to optimize `string == "literal string"`.

Chris Kennelly via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Wed May 8 11:32:03 PDT 2019


ckennelly added a comment.

> I can go through the char_traits, but `char_traits::compare()` has an extra branch that is unnecessary here. `compare` checks that the size is not 0, which is useful to avoid calling `memcmp` with null pointers. But there is no possiblity of null pointers here. The `.data()` will never return null, and the `char*` can't be null either (there is an assertion for that, and we passed it to `strlen`).

Would applying some `__builtin_assume`'s in strategic locations let us promise to the optimizer that the inputs to `compare` are non-null and the length is non-zero?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D59999/new/

https://reviews.llvm.org/D59999





More information about the libcxx-commits mailing list