From 6840e895c1e77c5862c1d3f46747ae7f654476d4 Mon Sep 17 00:00:00 2001 From: Kai Nacke Date: Tue, 4 Feb 2014 05:55:16 +0000 Subject: Add strchr(p, 0) -> p + strlen(p) to SimplifyLibCalls Add the missing transformation strchr(p, 0) -> p + strlen(p) to SimplifyLibCalls and remove the ToDo comment. Reviewer: Duncan P.N. Exan Smith git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@200736 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Utils/SimplifyLibCalls.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/Transforms/Utils/SimplifyLibCalls.cpp b/lib/Transforms/Utils/SimplifyLibCalls.cpp index 36d24624f9..1ef8115945 100644 --- a/lib/Transforms/Utils/SimplifyLibCalls.cpp +++ b/lib/Transforms/Utils/SimplifyLibCalls.cpp @@ -493,8 +493,11 @@ struct StrChrOpt : public LibCallOptimization { // Otherwise, the character is a constant, see if the first argument is // a string literal. If so, we can constant fold. StringRef Str; - if (!getConstantStringInfo(SrcStr, Str)) + if (!getConstantStringInfo(SrcStr, Str)) { + if (TD && CharC->isZero()) // strchr(p, 0) -> p + strlen(p) + return B.CreateGEP(SrcStr, EmitStrLen(SrcStr, B, TD, TLI), "strchr"); return 0; + } // Compute the offset, make sure to handle the case when we're searching for // zero (a weird way to spell strlen). @@ -2297,8 +2300,6 @@ void LibCallSimplifier::replaceAllUsesWith(Instruction *I, Value *With) const { // * sqrt(Nroot(x)) -> pow(x,1/(2*N)) // * sqrt(pow(x,y)) -> pow(|x|,y*0.5) // -// strchr: -// * strchr(p, 0) -> strlen(p) // tan, tanf, tanl: // * tan(atan(x)) -> x // -- cgit v1.2.3