(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;
}
getPointerBase() isn't right; it strips all offsets from the pointer.
I'd like to see more regression test coverage of different variations on the values produced by the loop.