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: Richard Henderson <richard dot henderson at linaro dot org>
- To: Prathamesh Kulkarni <prathamesh dot kulkarni at linaro dot org>, "gcc at gcc dot gnu dot org" <gcc at gcc dot gnu dot org>, Wilco Dijkstra <Wilco dot Dijkstra at arm dot com>
- Date: Fri, 4 Aug 2017 11:17:57 -0700
- Subject: Re: help with PR78809 - inline strcmp for small constant strings
- Authentication-results: sourceware.org; auth=none
- References: <CAAgBjM=6ZNhfqUCnF4fhr18hen=ZKpO3wTGh2WAvqK+cY0uPsw@mail.gmail.com>
On 08/04/2017 05:59 AM, Prathamesh Kulkarni wrote:
> Hi,
> I was having a look at PR78809.
> For the test-case:
> int t1(const char *s) { return __builtin_strcmp (s, "a"); }
>
> for aarch64, trunk with -O2 generates:
> t1:
> adrp x1, .LANCHOR0
> add x1, x1, :lo12:.LANCHOR0
> b strcmp
>
> 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.
> 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];
> }
I don't know that it would be helpful to do that as early as gimple-fold.
Surely rtl-expand is early enough for this.
Indeed, if the gimple passes are able to transform
strcmp(s, "ab")
to
memcmp(s, "ab", 3)
when it can be shown that S has at least 3 bytes known to be allocated (e.g. s
is an array of known size). This might allow
if (memcmp(s, "ab", 3) != 0)
to be implemented with cmp+ccmp+ccmp and one branch.
r~