mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-26 23:24:34 +00:00
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:
@ -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");
|
||||
}
|
||||
};
|
||||
|
Reference in New Issue
Block a user