[llvm-commits] [PATCH] simplify-libcalls: fold strstr(a, b) == a -> strncmp(a, b, strlen(b)) == 0
John McCall
rjmccall at apple.com
Tue Jun 15 14:23:45 PDT 2010
On Jun 15, 2010, at 12:03 PM, Chris Lattner wrote:
>
> On Jun 15, 2010, at 11:50 AM, Benjamin Kramer wrote:
>
>> This seems to be a common idiom to check the prefix of a string (lldb uses it) and it triggers O(n*m) behavior in most libc implementations. strncmp brings it down to O(m).
>>
>> I'm not sure if simplify-libcalls is the right place for this. The code basically works around the pass's infrastructure (skipping statistics etc.)
>
> This looks great to me. As a micro-micro-optimization, you could check to see if 'a' has a known length. If so, you could use strlen(a) instead since using strlen(a) or strlen(b) both work.
It needs to be strlen(b). strstr("foo", "food") != "foo".
John.
More information about the llvm-commits
mailing list