(Original patch by musman under 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:
- Strlen loop idiom recognition
- Strlen16 recognition and creation of new strlen16 intrinsic
- 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;
}
If the passed pointer has the "nonnull" attribute then this condition need not be present.