https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81657
--- Comment #18 from H.J. Lu <hjl.tools at gmail dot com> --- (In reply to Wilco from comment #17) > (In reply to Jakub Jelinek from comment #16) > > (In reply to Wilco from comment #15) > > > I don't think it's safe to compare different benchmark results like that. > > > But yes the kernel for both should be very similar. The key difference is > > > that strchr needs 2x the number of comparisons, which is why an optimized > > > strlen will always be faster than strchr. > > > > That is of course not true, it can do e.g. just the number of comparisons > > strlen needs + 1. > > No, strchr searches for 2 characters, strlen for just 1. Of course if you > want to special case strchr (p, 0) to use strlen because that is faster then > I guess we agree that is the right transformation. This is true for strchr vs strlen. But it isn't true for memcpy vs mempcpy. x86 doesn't want mempcpy -> memcpy conversion.