public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "elrodc at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug middle-end/95899] -funroll-loops does not duplicate accumulators when calculating reductions, failing to break up dependency chains
Date: Thu, 25 Jun 2020 15:45:58 +0000	[thread overview]
Message-ID: <bug-95899-4-I3GDgiv5xP@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-95899-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #2 from Chris Elrod <elrodc at gmail dot com> ---
Interesting. Compiling with:

gcc -march=native -fvariable-expansion-in-unroller -Ofast -funroll-loops -S
dot.c -o dot.s

Yields:

```
.L4:
        vmovupd (%rdi,%r11), %zmm9
        vmovupd 64(%rdi,%r11), %zmm10
        vfmadd231pd     (%rsi,%r11), %zmm9, %zmm0
        vfmadd231pd     64(%rsi,%r11), %zmm10, %zmm1
        vmovupd 128(%rdi,%r11), %zmm11
        vmovupd 192(%rdi,%r11), %zmm12
        vmovupd 256(%rdi,%r11), %zmm13
        vfmadd231pd     128(%rsi,%r11), %zmm11, %zmm0
        vfmadd231pd     192(%rsi,%r11), %zmm12, %zmm1
        vmovupd 320(%rdi,%r11), %zmm14
        vmovupd 384(%rdi,%r11), %zmm15
        vmovupd 448(%rdi,%r11), %zmm4
        vfmadd231pd     256(%rsi,%r11), %zmm13, %zmm0
        vfmadd231pd     320(%rsi,%r11), %zmm14, %zmm1
        vfmadd231pd     384(%rsi,%r11), %zmm15, %zmm0
        vfmadd231pd     448(%rsi,%r11), %zmm4, %zmm1
        addq    $512, %r11
        cmpq    %r8, %r11
        jne     .L4
```

So the dependency chain has now been split in 2.
4 would be ideal. I'll try running benchmarks later to see how it does.
FWIW, the original ran at between 20 and 25 GFLOPS from roughly N = 80 through
N = 1024.
The fastest versions I benchmarked climbed from around 20 to 50 GFLOPS over
this range. So perhaps just splitting the dependency once can get it much of
the way there.

Out of curiosity, what's the reason for this being off by default for
everything but ppc?
Seems like it should turned on with `-funroll-loops`, given that breaking
dependency chains are one of the primary ways unrolling can actually help
performance.

  parent reply	other threads:[~2020-06-25 15:45 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-25 15:10 [Bug middle-end/95899] New: " elrodc at gmail dot com
2020-06-25 15:22 ` [Bug middle-end/95899] " ktkachov at gcc dot gnu.org
2020-06-25 15:45 ` elrodc at gmail dot com [this message]
2020-06-26  6:47 ` 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-95899-4-I3GDgiv5xP@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).