[PATCH v3] Optimize strchr to strlen

Richard Biener richard.guenther@gmail.com
Tue Sep 27 09:07:00 GMT 2016


On Fri, Sep 23, 2016 at 4:10 PM, Oleg Endo <oleg.endo@t-online.de> wrote:
> On Fri, 2016-09-23 at 14:07 +0000, Wilco Dijkstra wrote:
>> After discussion (https://gcc.gnu.org/ml/gcc-patches/2016-09/msg00718
>> .html)
>> here is the latest version of the strchr patch.  This uses a gimple
>> statement for
>> the pointer addition so the gsi_prev always points at the strlen
>> call.
>>
>> Optimize strchr (s, 0) to s + strlen (s).  strchr (s, 0) appears a
>> common
>> idiom for finding the end of a string, however it is not a very
>> efficient
>> way of doing so.  Strlen is a much simpler operation which is
>> significantly
>> faster (eg. on x86 strlen is 50% faster for strings of 8 bytes and
>> about
>> twice as fast as strchr on strings of 1KB).
>>
>> OK for commit?
>
> Please add PR tree-optimization/61056 to the changelog so that it gets
> linked in bugzilla.

Yes.  Also you should strip gcc/  and gcc/testsuite from the filenames
in the changelog entry
as this entries are for gcc/ChangeLog and gcc/testsuite/ChangeLog.

Ok with that changelog changes.

Thanks,
Richard.

> Cheers,
> Oleg



More information about the Gcc-patches mailing list