[SelectionDAG] Allow the user to specify a memeq function.
authorClement Courbet <courbet@google.com>
Fri, 8 Mar 2019 09:07:45 +0000 (09:07 +0000)
committerClement Courbet <courbet@google.com>
Fri, 8 Mar 2019 09:07:45 +0000 (09:07 +0000)
commit8e16d73346f8091461319a7dfc4ddd18eedcff13
tree834ddc2069d1bcdb9214a794b89c7570156a6046
parent1a98dc184044768dd672c54b3b9557a05dd082f1
[SelectionDAG] Allow the user to specify a memeq function.

Summary:
Right now, when we encounter a string equality check,
e.g. `if (memcmp(a, b, s) == 0)`, we try to expand to a comparison if `s` is a
small compile-time constant, and fall back on calling `memcmp()` else.

This is sub-optimal because memcmp has to compute much more than
equality.

This patch replaces `memcmp(a, b, s) == 0` by `bcmp(a, b, s) == 0` on platforms
that support `bcmp`.

`bcmp` can be made much more efficient than `memcmp` because equality
compare is trivially parallel while lexicographic ordering has a chain
dependency.

Subscribers: fedor.sergeev, jyknight, ckennelly, gchatelet, llvm-commits

Differential Revision: https://reviews.llvm.org/D56593

llvm-svn: 355672
llvm/docs/ReleaseNotes.rst
llvm/include/llvm/Transforms/Utils/BuildLibCalls.h
llvm/lib/Analysis/TargetLibraryInfo.cpp
llvm/lib/Transforms/Utils/BuildLibCalls.cpp
llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
llvm/test/CodeGen/X86/memcmp.ll
llvm/test/Transforms/InferFunctionAttrs/annotate.ll
llvm/test/Transforms/InstCombine/memcmp-1.ll
llvm/test/Transforms/InstCombine/strcmp-1.ll