summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorBenjamin Kramer <benny.kra@googlemail.com>2010-09-29 22:29:12 +0000
committerBenjamin Kramer <benny.kra@googlemail.com>2010-09-29 22:29:12 +0000
commit8e861d7eee63276b71e2bf72ee7c9b4cd328d6c5 (patch)
tree08fb295cb05ccb5d6391d2b7db4e3ba9c86c76a1 /llvm/lib/Transforms
parentb024be3162edbf7deb18d7a991fd8a0f2eea0506 (diff)
downloadbcm5719-llvm-8e861d7eee63276b71e2bf72ee7c9b4cd328d6c5.tar.gz
bcm5719-llvm-8e861d7eee63276b71e2bf72ee7c9b4cd328d6c5.zip
Simplify the loop in StrChrOptimizer. FileCheckize test.
llvm-svn: 115095
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/Scalar/SimplifyLibCalls.cpp15
1 files changed, 4 insertions, 11 deletions
diff --git a/llvm/lib/Transforms/Scalar/SimplifyLibCalls.cpp b/llvm/lib/Transforms/Scalar/SimplifyLibCalls.cpp
index fffd3250738..75754a55854 100644
--- a/llvm/lib/Transforms/Scalar/SimplifyLibCalls.cpp
+++ b/llvm/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");
}
};
OpenPOWER on IntegriCloud