x86: Add cmpmemsi for -minline-all-stringops
authorH.J. Lu <hjl.tools@gmail.com>
Thu, 14 May 2020 20:06:23 +0000 (13:06 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Mon, 26 Oct 2020 11:06:32 +0000 (04:06 -0700)
commit3edc21af5272194794fbf24b2c5f0981c632e866
tree23b6727ef2438fb38d4043d62fef5a7066e0d897
parent19534269d899c4810b7b12e00cc4b1deb9e7b495
x86: Add cmpmemsi for -minline-all-stringops

We used to expand memcmp to "repz cmpsb" via cmpstrnsi.  It was changed
by

commit 9b0f6f5e511ca512e4faeabc81d2fd3abad9b02f
Author: Nick Clifton <nickc@redhat.com>
Date:   Fri Aug 12 16:26:11 2011 +0000

    builtins.c (expand_builtin_memcmp): Do not use cmpstrnsi pattern.

            * builtins.c (expand_builtin_memcmp): Do not use cmpstrnsi
            pattern.
            * doc/md.texi (cmpstrn): Note that the comparison stops if both
            fetched bytes are zero.
            (cmpstr): Likewise.
            (cmpmem): Note that the comparison does not stop if both of the
            fetched bytes are zero.

Duplicate the cmpstrn pattern for cmpmem.  The only difference is that
the length argument of cmpmem is guaranteed to be less than or equal to
lengths of 2 memory areas.  Since "repz cmpsb" can be much slower than
memcmp function implemented with vector instruction, see

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43052

expand cmpmem to "repz cmpsb" only for -minline-all-stringops.

gcc/

PR target/95151
* config/i386/i386-expand.c (ix86_expand_cmpstrn_or_cmpmem): New
function.
* config/i386/i386-protos.h (ix86_expand_cmpstrn_or_cmpmem): New
prototype.
* config/i386/i386.md (cmpmemsi): New pattern.

gcc/testsuite/

PR target/95151
* gcc.target/i386/pr95151-1.c: New test.
* gcc.target/i386/pr95151-2.c: Likewise.
* gcc.target/i386/pr95151-3.c: Likewise.
* gcc.target/i386/pr95151-4.c: Likewise.
gcc/config/i386/i386-expand.c
gcc/config/i386/i386-protos.h
gcc/config/i386/i386.md
gcc/testsuite/gcc.target/i386/pr95151-1.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/pr95151-2.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/pr95151-3.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/pr95151-4.c [new file with mode: 0644]