[PATCH] D88460: Strlen loop idiom recognition

Anjan Kumar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 28 18:19:32 PDT 2020


anjankgk created this revision.
anjankgk added reviewers: efriedma, baziotis, shawnl, xbolva00, hiraditya.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
anjankgk requested review of this revision.

(Original patch by musman under D83392 <https://reviews.llvm.org/D83392>. I am planning to commit this in his absence, with his consent.)
This patch adds strlen to LoopIdiomRecognize.cpp. It is the first part of 3 patches:

1. Strlen loop idiom recognition
2. Strlen16 recognition and creation of new strlen16 intrinsic
3. Folding of strlen/strlen16 call if they are only used for zero equality comparison (replace with load of first char)

Example that this recognizes:

unsigned strlen(char *Str) {

  char *Src = Str;
  if (!Src)
    return 0;
  for (; *Src;)
    Src++;
  return Src - Str;

}


https://reviews.llvm.org/D88460

Files:
  llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
  llvm/test/Transforms/LoopIdiom/recognize-strlen.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D88460.294847.patch
Type: text/x-patch
Size: 8491 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200929/09724080/attachment.bin>


More information about the llvm-commits mailing list