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, 14 Sep 2016 15:45:06 +0200
- Subject: Re: [PATCH] Optimize strchr (s, 0) to strlen
- Authentication-results: sourceware.org; auth=none
- References: <CAFiYyc1rGd2KWOaN4RTG45Y1uUp6O0A5qOm=i5ma0BZSK5CrXw@mail.gmail.com> <AM3PR08MB00881BE3867DF3FC5B5B7530836C0@AM3PR08MB0088.eurprd08.prod.outlook.com> <CAFiYyc0cUOs19FV-2PnYxfba4_N8Qwox2tkgXZJEw2obe20zgg@mail.gmail.com> <AM3PR08MB008870D1CDEE9E149F657561836D0@AM3PR08MB0088.eurprd08.prod.outlook.com> <CAFiYyc0us3xEAbJUtwC+Gp4U6CgAjC+Gxre59PiTARf=AYfnpg@mail.gmail.com> <AM3PR08MB0088BB9EBAD6AC1489BFA9B9837B0@AM3PR08MB0088.eurprd08.prod.outlook.com> <AM3PR08MB008897E76957E408CA75B51783490@AM3PR08MB0088.eurprd08.prod.outlook.com> <CAFiYyc2kTZDd9aPo6v-1+6ufH8x4F1FaNMcq=nDpGgnXmqwc-Q@mail.gmail.com> <DB3PR08MB0089E3481502F6009D642E4283590@DB3PR08MB0089.eurprd08.prod.outlook.com> <CAFiYyc38DTZBCAsWWK-+4J_78gRx7+VCnyBDEYhhpXc7En=KPg@mail.gmail.com>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
On Wed, Sep 14, 2016 at 03:41:33PM +0200, Richard Biener wrote:
> > We've seen several different proposals for where/how to do this simplification, why did you
> > say strlenopt is best? It would be an unconditional strchr (a, 0) -> a + strlen (a) rewrite,
> > ie. completely unrelated to what strlenopt does. We do all the other simplifications based
> > on constant arguments in builtins.c and gimple-fold.c, why is strchr (s, 0) different?
>
> I was thinking about the case where strlen opt already knows strlen
> (a). But sure, gimple-fold.c
> works as well.
I think for the middle-end, using strchr (a, 0) as canonical instead of a + strlen (a)
is better, and at expansion time we can decide what to use (a + strlen (a)
if you'd expand strlen inline, rather than as a function call, or
__rawmemchr (which if libc is sane should be fastest), or strchr, or a + strlen (a)).
Jakub