SimplifyLibCalls: Add basic optimization of memchr calls.

This is just memchr(x, y, 0) -> nullptr and constant folding.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@232896 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Benjamin Kramer
2015-03-21 15:36:21 +00:00
parent 046c58a3ee
commit 4b74df7229
4 changed files with 168 additions and 3 deletions

View File

@@ -238,9 +238,12 @@ namespace llvm {
/// \returns The index of the first occurrence of \p C, or npos if not
/// found.
size_t find(char C, size_t From = 0) const {
for (size_t i = std::min(From, Length), e = Length; i != e; ++i)
if (Data[i] == C)
return i;
if (Length != 0) {
size_t FindBegin = std::min(From, Length);
if (const void *Found =
std::memchr(Data + FindBegin, C, Length - FindBegin))
return static_cast<const char *>(Found) - Data;
}
return npos;
}