This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Optimize strchr (s, 0) to strlen
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Richard Biener <richard dot guenther at gmail dot com>
- Cc: Wilco Dijkstra <Wilco dot Dijkstra at arm dot com>, "gcc-patches at gcc dot gnu dot org" <gcc-patches at gcc dot gnu dot org>, nd <nd at arm dot com>
- Date: Wed, 20 Apr 2016 12:33:25 +0200
- Subject: Re: [PATCH] Optimize strchr (s, 0) to strlen
- Authentication-results: sourceware.org; auth=none
- References: <AM3PR08MB0088CA61259F65FAAB4D8196836B0 at AM3PR08MB0088 dot eurprd08 dot prod dot outlook dot com> <CAFiYyc1rGd2KWOaN4RTG45Y1uUp6O0A5qOm=i5ma0BZSK5CrXw at mail dot gmail dot com> <AM3PR08MB00881BE3867DF3FC5B5B7530836C0 at AM3PR08MB0088 dot eurprd08 dot prod dot outlook dot com> <CAFiYyc0cUOs19FV-2PnYxfba4_N8Qwox2tkgXZJEw2obe20zgg at mail dot gmail dot com> <CAFiYyc0FvFEUibja6ObDWw9rYf5Cu6puU3gaRrneNzpgkcEgtg at mail dot gmail dot com>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
On Wed, Apr 20, 2016 at 11:44:08AM +0200, Richard Biener wrote:
> (simplify
> (BUILT_IN_STRCHR @0 integer_zerop)
> (pointer_plus @0 (BUILT_IN_STRLEN:size_type_node @0)))
I still don't like this transformation and would very much prefer to see
using rawmemchr instead on targets that provide it, and also this is
something that IMHO should be done in the tree-ssa-strlen.c pass together
with the other optimizations in there. Similarly to stpcpy, which is also
non-standard (in POSIX, but not in C), we should just look at headers if
rawmemchr is defined with compatible prototype.
Also, strrchr (s, 0) should be folded to strchr (s, 0) or handled the same
like that one.
And, while x = strchr (s, 0) to x = rawmemchr (s, 0) is a reasonable -Os
transformation, x = s + strlen (s) is not, it makes code usually larger
(especially because it increases register pressure across the call).
Jakub