This recognizer finds loops of the form:
for (const char *ptr = p; *ptr; ++ptr, ++len) /*empty*/ ;
and converts them into calls to strlen().
Differential D12139
Add 'strlen' formation to LoopIdiomRecognize nlewycky on Aug 18 2015, 11:56 PM. Authored by
Details
This recognizer finds loops of the form: for (const char *ptr = p; *ptr; ++ptr, ++len) /*empty*/ ; and converts them into calls to strlen().
Diff Detail
Event TimelineComment Actions I don't think I have enough power to say LGTM, but looks legit to me.
Comment Actions This makes me very nervous. We have fielded a lot of user complaints about canonicalizing loops into memcpy calls. strlen feels like a more dubious choice. My past experience writing SIMD versions of string functions tells me that the typical string length that strlen is tuned for may be very different from the amount of data an open-coded loop is intended to handle. I would want to see very tuned lowering code to go with this. I'd also very much like to see the lowering code pay attention to target-specific cost information such as the possible cost to cross a dynamic library boundary when weighing the lowering of a call vs expanding inline. |
I'd open the namespace in just the one function that uses it.