[PATCH] D82395: Strlen loop idiom recognition and folding
Muhammad Usman via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 23 10:43:13 PDT 2020
musman created this revision.
musman added reviewers: alexr, nemanjai, sanjoy, hfinkel.
Herald added subscribers: llvm-commits, jdoerfert, hiraditya.
Herald added a project: LLVM.
This adds strlen to LoopIdiomRecognize.cpp and also recognizes strlens with 16 bit chars. For these cases, a new intrinsic (strlen16) is used. If a strlen/strlen16 function call is only used for zero equality comparison then it is replaced with a load of the first element. If a strlen16 intrinsic cannot be folded, it is expanded back out to the canonical loop form.
Examples that this recognizes:
unsigned strlen1(char *Str) {
char *Src = Str;
if (!Src)
return 0;
for (; *Src;)
Src++;
return Src - Str;
}
unsigned strlen2(char *Str) {
unsigned Len = 0;
if (!Str)
return 0;
while(*Str) {
Len++;
Str++;
}
return Len;
}
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D82395
Files:
llvm/include/llvm/Analysis/ValueTracking.h
llvm/include/llvm/IR/Intrinsics.td
llvm/lib/Analysis/ValueTracking.cpp
llvm/lib/CodeGen/CodeGenPrepare.cpp
llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
llvm/test/Transforms/LoopIdiom/expand-strlen16.ll
llvm/test/Transforms/LoopIdiom/recognize-strlen.ll
llvm/test/Transforms/LoopIdiom/strlen-fold.ll
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D82395.272757.patch
Type: text/x-patch
Size: 32815 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200623/9831b639/attachment-0001.bin>
More information about the llvm-commits
mailing list