public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/95151] New: Add cmpmemM pattern for -minline-all-stringops
@ 2020-05-15 12:32 hjl.tools at gmail dot com
  2020-05-19 12:11 ` [Bug target/95151] [9/10/11 Regression] " hjl.tools at gmail dot com
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: hjl.tools at gmail dot com @ 2020-05-15 12:32 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 95151
           Summary: Add cmpmemM pattern for -minline-all-stringops
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: hjl.tools at gmail dot com
                CC: crazylht at gmail dot com
  Target Milestone: ---
            Target: i386,x86-64

'cmpmemM'
     Block compare instruction, with five operands like the operands of
     'cmpstrM'.  The two memory blocks specified are compared byte by
     byte in lexicographic order starting at the beginning of each
     block.  Unlike 'cmpstrM' the instruction can prefetch any bytes in
     the two memory blocks.  Also unlike 'cmpstrM' the comparison will
     not stop if both bytes are zero.  The effect of the instruction is
     to store a value in operand 0 whose sign indicates the result of
     the comparison.

We should add

(define_expand "cmpmemsi"
  [(set (match_operand:SI 0 "register_operand" "")
        (compare:SI (match_operand:BLK 1 "memory_operand" "")
                    (match_operand:BLK 2 "memory_operand" "") ) )
   (use (match_operand 3 "general_operand"))
   (use (match_operand 4 "immediate_operand"))]
  ""
{
  if (ix86_expand_cmpmem (operands[0], operands[1], operands[2],
                          operands[3]))
    DONE; 
  else
    FAIL; 
})

which can be expanded to sysdeps/i386/memcmp.S in glibc:

        movl BLK1(%esp), %esi
        cfi_rel_offset (esi, 0)
        movl BLK2(%esp), %edi
        movl LEN(%esp), %ecx

        cld                     /* Set direction of comparison.  */

        xorl %eax, %eax         /* Default result.  */

        repe                    /* Compare at most %ecx bytes.  */
        cmpsb
        jz L(1)                 /* If even last byte was equal we return 0.  */

        /* The memory blocks are not equal.  So result of the last
           subtraction is present in the carry flag.  It is set when
           the byte in block #2 is bigger.  In this case we have to
           return -1 (=0xffffffff), else 1.  */
        sbbl %eax, %eax         /* This is tricky.  %eax == 0 and carry is set
                                   or not depending on last subtraction.  */

        /* At this point %eax == 0, if the byte of block #1 was bigger, and
           0xffffffff if the last byte of block #2 was bigger.  The latter
           case is already correct but the former needs a little adjustment.
           Note that the following operation does not change 0xffffffff.  */
        orb $1, %al             /* Change 0 to 1.  */

L(1):

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug target/95151] [9/10/11 Regression] Add cmpmemM pattern for -minline-all-stringops
  2020-05-15 12:32 [Bug target/95151] New: Add cmpmemM pattern for -minline-all-stringops hjl.tools at gmail dot com
@ 2020-05-19 12:11 ` hjl.tools at gmail dot com
  2020-05-30 12:14 ` hjl.tools at gmail dot com
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: hjl.tools at gmail dot com @ 2020-05-19 12:11 UTC (permalink / raw)
  To: gcc-bugs

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

H.J. Lu <hjl.tools at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|Add cmpmemM pattern for     |[9/10/11 Regression] Add
                   |-minline-all-stringops      |cmpmemM pattern for
                   |                            |-minline-all-stringops
   Target Milestone|---                         |11.0
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2020-05-19

--- Comment #1 from H.J. Lu <hjl.tools at gmail dot com> ---
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.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug target/95151] [9/10/11 Regression] Add cmpmemM pattern for -minline-all-stringops
  2020-05-15 12:32 [Bug target/95151] New: Add cmpmemM pattern for -minline-all-stringops hjl.tools at gmail dot com
  2020-05-19 12:11 ` [Bug target/95151] [9/10/11 Regression] " hjl.tools at gmail dot com
@ 2020-05-30 12:14 ` hjl.tools at gmail dot com
  2020-05-31  1:40 ` hjl.tools at gmail dot com
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: hjl.tools at gmail dot com @ 2020-05-30 12:14 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from H.J. Lu <hjl.tools at gmail dot com> ---
Initial attempt failed on

[hjl@gnu-cfl-2 pr95151]$ cat saved.c 
#include <stdint.h>
#include <string.h>
#include <sys/mman.h>
#include <unistd.h>

unsigned char *buf1, *buf2;
int ret;
size_t page_size;

static void
do_one_test (char *dst, char *src, const char *orig_src, size_t len)
{
  memcpy (src, orig_src, len);
  memmove (dst, src, len);

  if (memcmp (dst, orig_src, len) != 0)
    {
      ret = 1;
      return;
    }
}

void
__attribute__ ((noclone, noinline))
do_test (char *s1, char *s2, int n, size_t len)
{
  int i;
  for (i = 0; i < n; i++)
    do_one_test (s2, s2, s1, len);
}

int
main (void)
{
  page_size = 2 * getpagesize ();
  buf1 = mmap (0, (1 + 1) * page_size, PROT_READ | PROT_WRITE,
               MAP_PRIVATE | MAP_ANON, -1, 0);
  if (buf1 == MAP_FAILED)
    return -1;
  if (mprotect (buf1 + 1 * page_size, page_size, PROT_NONE))
    return -1;
  buf2 = mmap (0, 2 * page_size, PROT_READ | PROT_WRITE,
               MAP_PRIVATE | MAP_ANON, -1, 0);
  if (buf2 == MAP_FAILED)
    return -1;
  if (mprotect (buf2 + page_size, page_size, PROT_NONE))
    return -1;

  memset (buf1, 0xa5, 1 * page_size);
  memset (buf2, 0x5a, page_size);

  char *s1 = (char *) buf1;
  char *s2 = (char *) buf2;

  size_t len;
  size_t i, j;
  len = 1 << 2;
  for (i = 0, j = 1; i < len; i++, j += 23)
    s1[i] = j;

  do_test (s1, s2, 10, 1 << 2);

  len = 1 << 4;
  for (i = 0, j = 1; i < len; i++, j += 23)
    s1[i] = j;

  do_test (s1, s2, 10, 1 << 4);

  return ret;
}
[hjl@gnu-cfl-2 pr95151]$ make saved
/export/build/gnu/tools-build/gcc-gitlab-release-debug/build-x86_64-linux/gcc/xgcc
-B/export/build/gnu/tools-build/gcc-gitlab-release-debug/build-x86_64-linux/gcc/
-O2 -minline-all-stringops    saved.c   -o saved
[hjl@gnu-cfl-2 pr95151]$ ./saved 
Segmentation fault (core dumped)
[hjl@gnu-cfl-2 pr95151]$

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug target/95151] [9/10/11 Regression] Add cmpmemM pattern for -minline-all-stringops
  2020-05-15 12:32 [Bug target/95151] New: Add cmpmemM pattern for -minline-all-stringops hjl.tools at gmail dot com
  2020-05-19 12:11 ` [Bug target/95151] [9/10/11 Regression] " hjl.tools at gmail dot com
  2020-05-30 12:14 ` hjl.tools at gmail dot com
@ 2020-05-31  1:40 ` hjl.tools at gmail dot com
  2020-05-31 23:13 ` hjl.tools at gmail dot com
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: hjl.tools at gmail dot com @ 2020-05-31  1:40 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95151
Bug 95151 depends on bug 95439, which changed state.

Bug 95439 Summary: Incorrect zero count check in cmpstrnsi
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95439

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |INVALID

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug target/95151] [9/10/11 Regression] Add cmpmemM pattern for -minline-all-stringops
  2020-05-15 12:32 [Bug target/95151] New: Add cmpmemM pattern for -minline-all-stringops hjl.tools at gmail dot com
                   ` (2 preceding siblings ...)
  2020-05-31  1:40 ` hjl.tools at gmail dot com
@ 2020-05-31 23:13 ` hjl.tools at gmail dot com
  2020-05-31 23:14 ` hjl.tools at gmail dot com
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: hjl.tools at gmail dot com @ 2020-05-31 23:13 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95151
Bug 95151 depends on bug 95444, which changed state.

Bug 95444 Summary: Incorrect constraints on length operand in cmpstrnqi patterns
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95444

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |INVALID

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug target/95151] [9/10/11 Regression] Add cmpmemM pattern for -minline-all-stringops
  2020-05-15 12:32 [Bug target/95151] New: Add cmpmemM pattern for -minline-all-stringops hjl.tools at gmail dot com
                   ` (3 preceding siblings ...)
  2020-05-31 23:13 ` hjl.tools at gmail dot com
@ 2020-05-31 23:14 ` hjl.tools at gmail dot com
  2020-07-13 17:35 ` hjl.tools at gmail dot com
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: hjl.tools at gmail dot com @ 2020-05-31 23:14 UTC (permalink / raw)
  To: gcc-bugs

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

H.J. Lu <hjl.tools at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch
                URL|                            |https://gcc.gnu.org/piperma
                   |                            |il/gcc-patches/2020-May/546
                   |                            |919.html
         Depends on|95444                       |

--- Comment #3 from H.J. Lu <hjl.tools at gmail dot com> ---
A patch is posted at

https://gcc.gnu.org/pipermail/gcc-patches/2020-May/546919.html


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95444
[Bug 95444] Incorrect constraints on length operand in cmpstrnqi patterns

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug target/95151] [9/10/11 Regression] Add cmpmemM pattern for -minline-all-stringops
  2020-05-15 12:32 [Bug target/95151] New: Add cmpmemM pattern for -minline-all-stringops hjl.tools at gmail dot com
                   ` (4 preceding siblings ...)
  2020-05-31 23:14 ` hjl.tools at gmail dot com
@ 2020-07-13 17:35 ` hjl.tools at gmail dot com
  2020-07-14 19:10 ` ro at gcc dot gnu.org
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: hjl.tools at gmail dot com @ 2020-07-13 17:35 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95151
Bug 95151 depends on bug 95443, which changed state.

Bug 95443 Summary: cmpstrnqi patterns update string length
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95443

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |FIXED

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug target/95151] [9/10/11 Regression] Add cmpmemM pattern for -minline-all-stringops
  2020-05-15 12:32 [Bug target/95151] New: Add cmpmemM pattern for -minline-all-stringops hjl.tools at gmail dot com
                   ` (5 preceding siblings ...)
  2020-07-13 17:35 ` hjl.tools at gmail dot com
@ 2020-07-14 19:10 ` ro at gcc dot gnu.org
  2020-07-14 21:08 ` hjl.tools at gmail dot com
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: ro at gcc dot gnu.org @ 2020-07-14 19:10 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95151
Bug 95151 depends on bug 95443, which changed state.

Bug 95443 Summary: cmpstrnqi patterns update string length
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95443

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|FIXED                       |---

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug target/95151] [9/10/11 Regression] Add cmpmemM pattern for -minline-all-stringops
  2020-05-15 12:32 [Bug target/95151] New: Add cmpmemM pattern for -minline-all-stringops hjl.tools at gmail dot com
                   ` (6 preceding siblings ...)
  2020-07-14 19:10 ` ro at gcc dot gnu.org
@ 2020-07-14 21:08 ` hjl.tools at gmail dot com
  2020-10-16 11:43 ` rguenth at gcc dot gnu.org
  2020-10-26 11:19 ` hjl.tools at gmail dot com
  9 siblings, 0 replies; 11+ messages in thread
From: hjl.tools at gmail dot com @ 2020-07-14 21:08 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95151
Bug 95151 depends on bug 95443, which changed state.

Bug 95443 Summary: cmpstrnqi patterns update string length
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95443

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |RESOLVED
         Resolution|---                         |FIXED

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug target/95151] [9/10/11 Regression] Add cmpmemM pattern for -minline-all-stringops
  2020-05-15 12:32 [Bug target/95151] New: Add cmpmemM pattern for -minline-all-stringops hjl.tools at gmail dot com
                   ` (7 preceding siblings ...)
  2020-07-14 21:08 ` hjl.tools at gmail dot com
@ 2020-10-16 11:43 ` rguenth at gcc dot gnu.org
  2020-10-26 11:19 ` hjl.tools at gmail dot com
  9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu.org @ 2020-10-16 11:43 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P2

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug target/95151] [9/10/11 Regression] Add cmpmemM pattern for -minline-all-stringops
  2020-05-15 12:32 [Bug target/95151] New: Add cmpmemM pattern for -minline-all-stringops hjl.tools at gmail dot com
                   ` (8 preceding siblings ...)
  2020-10-16 11:43 ` rguenth at gcc dot gnu.org
@ 2020-10-26 11:19 ` hjl.tools at gmail dot com
  9 siblings, 0 replies; 11+ messages in thread
From: hjl.tools at gmail dot com @ 2020-10-26 11:19 UTC (permalink / raw)
  To: gcc-bugs

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

H.J. Lu <hjl.tools at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #4 from H.J. Lu <hjl.tools at gmail dot com> ---
Fixed for GCC 11 by

commit 3edc21af5272194794fbf24b2c5f0981c632e866
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Thu May 14 13:06:23 2020 -0700

    x86: Add cmpmemsi for -minline-all-stringops

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2020-10-26 11:19 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-15 12:32 [Bug target/95151] New: Add cmpmemM pattern for -minline-all-stringops hjl.tools at gmail dot com
2020-05-19 12:11 ` [Bug target/95151] [9/10/11 Regression] " hjl.tools at gmail dot com
2020-05-30 12:14 ` hjl.tools at gmail dot com
2020-05-31  1:40 ` hjl.tools at gmail dot com
2020-05-31 23:13 ` hjl.tools at gmail dot com
2020-05-31 23:14 ` hjl.tools at gmail dot com
2020-07-13 17:35 ` hjl.tools at gmail dot com
2020-07-14 19:10 ` ro at gcc dot gnu.org
2020-07-14 21:08 ` hjl.tools at gmail dot com
2020-10-16 11:43 ` rguenth at gcc dot gnu.org
2020-10-26 11:19 ` hjl.tools at gmail dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).