help with PR78809 - inline strcmp for small constant strings

Prathamesh Kulkarni prathamesh.kulkarni@linaro.org
Fri Aug 4 12:59:00 GMT 2017


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 ?

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];
}

Thanks,
Prathamesh



More information about the Gcc mailing list