This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: help with PR78809 - inline strcmp for small constant strings
- From: Segher Boessenkool <segher at kernel dot crashing dot org>
- To: Wilco Dijkstra <Wilco dot Dijkstra at arm dot com>
- Cc: Richard Henderson <richard dot henderson at linaro dot org>, Prathamesh Kulkarni <prathamesh dot kulkarni at linaro dot org>, "gcc at gcc dot gnu dot org" <gcc at gcc dot gnu dot org>, nd <nd at arm dot com>, Aaron Sawdey <acsawdey at linux dot vnet dot ibm dot com>
- Date: Fri, 4 Aug 2017 17:30:15 -0500
- Subject: Re: help with PR78809 - inline strcmp for small constant strings
- Authentication-results: sourceware.org; auth=none
- References: <b7d5b6e2-7b7f-2e48-8388-6b3267563812@linaro.org> <DB6PR0801MB205327474C52E6FCA824262E83B60@DB6PR0801MB2053.eurprd08.prod.outlook.com>
On Fri, Aug 04, 2017 at 08:38:11PM +0000, Wilco Dijkstra wrote:
> Richard Henderson wrote:
> > On 08/04/2017 05:59 AM, Prathamesh Kulkarni wrote:
>
> > > For i386, it seems strcmp is expanded inline via cmpstr optab by
> > > expand_builtin_strcmp if one of the strings is constant. Could we similarly
> > > define cmpstr pattern for AArch64?
> >
> > Certainly that's possible.
>
> I'd suggest to do it as a target independent way, this is not a target specific
> optimization and shouldn't be done in the target unless there are special
> strcmp instructions.
See rs6000-string.c; cc:ing Aaron.
> > For constant strings of small length (upto 3?), I was wondering if it'd be a
> > good idea to manually unroll strcmp loop, similar to __strcmp_* macros in
> > bits/string.h?>
> > For eg in gimple-fold, transform
> > x = __builtin_strcmp(s, "ab")
> > to
> > x = s[0] - 'a';
> > if (x == 0)
> > {
> > x = s[1] - 'b';
> > if (x == 0)
> > x = s[2];
> > }
>
> If there is already code that does something similar (see comment #1 in PR78809),
> it could be easily adapted to handle more cases.
>
> > if (memcmp(s, "ab", 3) != 0)
> >
> > to be implemented with cmp+ccmp+ccmp and one branch.
>
> Even better would be wider loads if you either know the alignment of s or it's max size
> (although given the overhead of creating the return value that works best for equality).
All those things are handled there, too. Most things that can really help
are quite target-specific, I think.
Segher