[PATCH] D83392: Strlen loop idiom recognition

Muhammad Usman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 8 06:35:05 PDT 2020


musman created this revision.
musman added reviewers: lebedev.ri, nemanjai, hfinkel, sanjoy.
musman added a project: LLVM.
Herald added subscribers: llvm-commits, hiraditya.

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)

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/D83392

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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D83392.276403.patch
Type: text/x-patch
Size: 14908 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200708/2ed86b2e/attachment.bin>


More information about the llvm-commits mailing list