<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div><div>Hi all,</div><div><br></div><div>We'd like to suggest <b>adding a -memeq-lib-function</b> flag to allow the user to specify a `<b>memeq()</b>` function to improve string equality check performance. </div><div><br></div><div>Right now, when llvm encounters a <b>string equality check</b>, e.g. `if (memcmp(a, b, s) == 0)`, it tries  to expand to an equality comparison if `s` is a small compile-time constant, and falls back on calling `memcmp()` else.</div><div><br></div><div>This is sub-optimal because memcmp has to compute much more than equality.</div><div>    </div><div>We propose adding a way for the user to specify a `memeq` library function (e.g. `-memeq-lib-function=user_memeq`) which will be called instead of `memcmp()` when the result of the memcmp call is only used for equality comparison.</div><div><br></div><div>`memeq` can be made much more efficient than `memcmp` because equality comparison is trivially parallel while lexicographic ordering has a chain dependency.</div></div><div><br></div><div>We measured an very large improvement of this approach on our internal codebase. A significant portion of this improvement comes from the stl, typically `std::string::operator==()`.</div><div><br></div><div>Note that this is a <b>backend-only change</b>. Because the c family of languages do not have a standard `memeq()` (posix used to have `bcmp()` but it was removed in 2001), c/c++ code cannot communicate the equality comparison semantics to the compiler.</div><div><br></div><div>We did not add an RTLIB entry for memeq because the user environment is not guaranteed to contain a `memeq()` function as the libc has no such concept.</div><div><br></div><div>If there is interest, we could also contribute our optimized `memeq` to compiler-rt.</div><div><br></div><div><div>A proof of concept patch for this for this RFC can be found here: <a href="https://reviews.llvm.org/D56248">https://reviews.llvm.org/D56248</a></div></div><div><br></div><div>Comments & suggestions welcome !</div><div>Thanks,</div><div><br></div><div>Clement</div></div></div></div></div>