On 9/4/23 14:58, Hamza Mahfooz wrote:
Currently, we give up in fold_strstr_to_strncmp() if the length of the
the second argument to strstr() isn't known to us by the time we hit
that function. However, we can instead insert a strlen() in ourselves
and continue trying to fold strstr() into strlen()+strncmp().
PR tree-optimization/96601
gcc/ChangeLog:
* tree-ssa-strlen.cc (fold_strstr_to_strncmp): If arg1_len == NULL,
insert a strlen() for strstr()'s arg1 and use it as arg1_len.
gcc/testsuite/ChangeLog:
* gcc.dg/strlenopt-30.c: Modify test.
I'm not sure it's necessarily a win to convert to strncmp as
aggressively as this patch would do. Essentially when you have large
needles that are partially matched repeatedly, performance can
significantly suffer.
If we're going to seriously consider this path, then I'd like to see how
it performs in general. The glibc testsuite I think has some
performance coverage for strstr.
jeff