Simplify the loop in StrChrOptimizer. FileCheckize test.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@115095 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Benjamin Kramer
2010-09-29 22:29:12 +00:00
parent 8cf6c60710
commit e260990fa1
2 changed files with 18 additions and 25 deletions

View File

@ -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");
}
};