public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "pdimov at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/109985] New: __builtin_prefetch ignored by GCC 12/13
Date: Fri, 26 May 2023 11:38:32 +0000	[thread overview]
Message-ID: <bug-109985-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 109985
           Summary: __builtin_prefetch ignored by GCC 12/13
           Product: gcc
           Version: 13.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pdimov at gmail dot com
  Target Milestone: ---

We are investigating a Boost.Unordered performance regression with GCC 12,
on the following benchmark:

https://github.com/boostorg/boost_unordered_benchmarks/blob/4c717baac1bff8d3e51cb8485b72bbb63d533265/scattered_lookup.cpp

and it looks like the reason is that GCC 12 (and 13) ignore a call to
`__builtin_prefetch`.

While GCC 11 generates this:

```
.L108:
        mov     r8, r12
        movdqa  xmm0, xmm1
        sal     r8, 4
        lea     r14, [r10+r8]
        pcmpeqb xmm0, XMMWORD PTR [r14]
        pmovmskb        edx, xmm0
        and     edx, 32767
        je      .L104
        sub     r8, r12
        sal     r8, 4
        add     r8, QWORD PTR [rbx+32]
        prefetcht0      [r8]
.L106:
        xor     r15d, r15d
        rep bsf r15d, edx
        movsx   r15, r15d
        sal     r15, 4
        add     r15, r8
        cmp     rsi, QWORD PTR [r15]
        jne     .L144
        add     r9, QWORD PTR [r15+8]
        mov     rax, rdi
        cmp     r11, rdi
        jne     .L145
```
(https://godbolt.org/z/d663fdM16 - prefetcht0 [r8] right before L106)

GCC 12 generates this in the same function:
```
.L108:
        mov     r8, r10
        movdqa  xmm0, xmm1
        sal     r8, 4
        lea     r9, [rbp+0+r8]
        pcmpeqb xmm0, XMMWORD PTR [r9]
        pmovmskb        edx, xmm0
        and     edx, 32767
        je      .L104
        mov     rdi, QWORD PTR [rsp+16]
        sub     r8, r10
        mov     QWORD PTR [rsp+24], rax
        sal     r8, 4
        mov     rdi, QWORD PTR [rdi+32]
        mov     QWORD PTR [rsp+8], rdi
        mov     rax, rdi
.L106:
        xor     edi, edi
        rep bsf edi, edx
        movsx   rdi, edi
        sal     rdi, 4
        add     rdi, r8
        add     rdi, rax
        cmp     r11, QWORD PTR [rdi]
        jne     .L143
        add     rsi, 8
        add     rbx, QWORD PTR [rdi+8]
        cmp     r12, rsi
        jne     .L109
```
(https://godbolt.org/z/T7csq7TPz - no prefetcht0 instruction before L106)

Simplifying this code unfortunately leads to the prefetcht0 being generated.

             reply	other threads:[~2023-05-26 11:38 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-26 11:38 pdimov at gmail dot com [this message]
2023-05-26 16:36 ` [Bug tree-optimization/109985] " pinskia at gcc dot gnu.org
2023-05-26 17:15 ` christian.mazakas at gmail dot com
2023-05-26 17:17 ` pinskia at gcc dot gnu.org
2023-05-26 17:38 ` jakub at gcc dot gnu.org
2023-05-26 22:28 ` pinskia at gcc dot gnu.org
2023-05-28 20:33 ` hubicka at gcc dot gnu.org
2023-05-28 20:40 ` hubicka at gcc dot gnu.org
2023-05-30  7:31 ` rguenth at gcc dot gnu.org
2023-05-30  7:32 ` [Bug tree-optimization/109985] [12/13/14 Regression] " rguenth at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-109985-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).