public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "fxue at os dot amperecomputing.com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/114814] Reduction sum of comparison should be better
Date: Fri, 21 Jun 2024 04:41:57 +0000	[thread overview]
Message-ID: <bug-114814-4-GikUCn79xn@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-114814-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #3 from Feng Xue <fxue at os dot amperecomputing.com> ---
The pattern to match the code belongs to a generic dot-product category, we
could consider mapping it to native dot-product instruction with a constant "1"
operand.

        movi    v29.16b, 0x1
.L4:
        ldr     q31, [x1], 16
        cmeq    v31.16b, v28.16b, v31.16b
        and     v31.16b, v29.16b, v31.16b
        udot    v30.4s, v31.16b, v29.16b
        cmp     x5, x1
        bne     .L4
        addv    s31, v30.4s
        fmov    w1, s31

And if value accumulation does not require widening, as in this case, then
REDUC_PLUS finds its usage, which could be seen as a special instance of
dot-product instruction. But here is one point to note: we should think this
kind of REDUC_PLUS touches whole vector register, modifying the 1st element and
clearing the rest part. Anyway, it would become an addv.

For SVE, since element count is variant, element type may not hold accumulation
result, only dot-product could be used.

Moreover, it is possible to extend the means to handle conditional accumulation
as:

   for (i) {
     if (cond)
       sum += a;   // => sum += cond * a;
   }

      parent reply	other threads:[~2024-06-21  4:41 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-22 22:15 [Bug tree-optimization/114814] New: " pinskia at gcc dot gnu.org
2024-06-20  9:52 ` [Bug tree-optimization/114814] " ktkachov at gcc dot gnu.org
2024-06-20 11:36 ` rguenth at gcc dot gnu.org
2024-06-21  4:41 ` fxue at os dot amperecomputing.com [this message]

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-114814-4-GikUCn79xn@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).