[PATCH] D18230: [SimplifyLibCalls] Simplify strlen to a subtraction for certain cases
Daniel Berlin via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 5 17:42:41 PDT 2016
So, uh, why not make getConstantStringInfo work for this case too, rather
than duplicate it?
On Tue, Apr 5, 2016 at 12:18 PM, Li Huang via llvm-commits <
llvm-commits at lists.llvm.org> wrote:
> lihuang added a comment.
>
> Sure, I will rebase the patch after 265431.
>
>
> ================
> Comment at: lib/Transforms/Utils/SimplifyLibCalls.cpp:541-558
> @@ +540,20 @@
> + // [0, strlen(s)] or the string has a single null terminator '\0' at
> the end.
> + if (GEPOperator *GEP = dyn_cast<GEPOperator>(Src)) {
> + if (GEP->getNumOperands() != 3)
> + return nullptr;
> +
> + // We only try to simplify strlen when the pointer s points to an
> array
> + // of i8. Otherwise, we would need to scale the offset x before doing
> the
> + // subtraction. This will make the optimization more complex, and
> it's not
> + // very useful because calling strlen for a pointer of other types is
> + // very uncommon.
> + PointerType *PT = cast<PointerType>(GEP->getOperand(0)->getType());
> + ArrayType *AT = dyn_cast<ArrayType>(PT->getElementType());
> + if (!AT || !AT->getElementType()->isIntegerTy(8))
> + return nullptr;
> +
> + // First index should be 0.
> + const ConstantInt *FirstIdx =
> dyn_cast<ConstantInt>(GEP->getOperand(1));
> + if (!FirstIdx || !FirstIdx->isZero())
> + return nullptr;
> +
> ----------------
> spatel wrote:
> > These checks are included in getConstantStringInfo(). You do not need to
> repeat them here?
> Yes these lines are the same lines in getConstantStringInfo(). The reason
> I didn't use getConstantStringInfo() here is it only works for GEP with a
> constant offset. In this case, the offset is a variable, and we need the
> same checks.
>
>
> http://reviews.llvm.org/D18230
>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160405/ae11e1da/attachment.html>
More information about the llvm-commits
mailing list