diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2010-09-29 22:29:12 +0000 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2010-09-29 22:29:12 +0000 |
commit | e260990fa19e3f5f2935a922868e80b83fb87524 (patch) | |
tree | 8779ac3b6fe0df1a5dc220215c6a1a16eeea387c /lib/Transforms/Scalar/SimplifyLibCalls.cpp | |
parent | 8cf6c60710c7924bcd0235f37e4d613f9abf7dc6 (diff) |
Simplify the loop in StrChrOptimizer. FileCheckize test.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@115095 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Scalar/SimplifyLibCalls.cpp')
-rw-r--r-- | lib/Transforms/Scalar/SimplifyLibCalls.cpp | 15 |
1 files changed, 4 insertions, 11 deletions
diff --git a/lib/Transforms/Scalar/SimplifyLibCalls.cpp b/lib/Transforms/Scalar/SimplifyLibCalls.cpp index fffd325073..75754a5585 100644 --- a/lib/Transforms/Scalar/SimplifyLibCalls.cpp +++ b/lib/Transforms/Scalar/SimplifyLibCalls.cpp @@ -252,21 +252,14 @@ struct StrChrOpt : public LibCallOptimization { // strchr can find the nul character. Str += '\0'; - char CharValue = CharC->getSExtValue(); // Compute the offset. - uint64_t i = 0; - while (1) { - if (i == Str.size()) // Didn't find the char. strchr returns null. - return Constant::getNullValue(CI->getType()); - // Did we find our match? - if (Str[i] == CharValue) - break; - ++i; - } + size_t I = Str.find(CharC->getSExtValue()); + if (I == std::string::npos) // Didn't find the char. strchr returns null. + return Constant::getNullValue(CI->getType()); // strchr(s+n,c) -> gep(s+n+i,c) - Value *Idx = ConstantInt::get(Type::getInt64Ty(*Context), i); + Value *Idx = ConstantInt::get(Type::getInt64Ty(*Context), I); return B.CreateGEP(SrcStr, Idx, "strchr"); } }; |