public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "npiggin at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/102062] New: powerpc suboptimal unrolling simple array sum
Date: Wed, 25 Aug 2021 11:27:40 +0000	[thread overview]
Message-ID: <bug-102062-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 102062
           Summary: powerpc suboptimal unrolling simple array sum
           Product: gcc
           Version: 11.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: npiggin at gmail dot com
  Target Milestone: ---
            Target: powerpc64le-linux-gnu

--- test.c ---
int test(int *arr, int sz)
{
        int ret = 0;
        int i;

        if (sz < 1)
                __builtin_unreachable();

        for (i = 0; i < sz*2; i++)
                ret += arr[i];

        return ret;
}
---

gcc-11 compiles this to:
test:
        rldic 4,4,1,32
        addi 10,3,-4
        rldicl 9,4,63,33
        li 3,0
        mtctr 9
.L2:
        addi 8,10,4
        lwz 9,4(10)
        addi 10,10,8
        lwz 8,4(8)
        add 9,9,3
        add 9,9,8
        extsw 3,9
        bdnz .L2
        blr

I may be unaware of a constraint of C standard here, but maintaining the two
base addresses seems pointless, so is beginning the first at offset -4.

The bigger problem is keeping a single sum. Keeping two sums and adding them at
the end reduces critical latency of the loop from 6 to 2, which brings
throughput on large loops from 6 cycles per iteration down to about 2.2 on
POWER9 without harming short loops:

test:
        rldic 4,4,1,32
        rldicl 9,4,63,33
        mtctr 9
        li 8,0
        li 9,0
.L2:
        lwz 6,0(3)
        lwz 7,4(3)
        addi 3,3,8
        add  8,8,6
        add  9,9,7
        bdnz .L2
        add 9,9,8
        extsw 3,9
        blr

Any reason this can't be done?

             reply	other threads:[~2021-08-25 11:27 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-25 11:27 npiggin at gmail dot com [this message]
2021-08-25 11:52 ` [Bug c/102062] " wschmidt at gcc dot gnu.org
2021-08-25 11:55 ` wschmidt at gcc dot gnu.org
2021-08-25 12:43 ` npiggin at gmail dot com
2021-08-25 12:50 ` wschmidt at gcc dot gnu.org
2021-08-25 13:01 ` npiggin at gmail dot com
2021-08-25 14:05 ` segher at gcc dot gnu.org
2021-08-25 14:10 ` segher at gcc dot gnu.org
2021-08-25 15:31 ` linkw at gcc dot gnu.org
2021-08-25 17:07 ` segher at gcc dot gnu.org
2021-08-25 18:01 ` wschmidt at gcc dot gnu.org
2021-08-25 18:03 ` dje at gcc dot gnu.org
2021-08-25 22:43 ` segher at gcc dot gnu.org
2021-08-25 23:29 ` [Bug rtl-optimization/102062] " dje at gcc dot gnu.org
2021-08-26  0:17 ` npiggin at gmail dot com
2021-08-30 17:34 ` segher at gcc dot gnu.org
2021-09-22 13:53 ` npiggin at gmail dot com

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-102062-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).