public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "juzhe.zhong at rivai dot ai" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/112457] New: Possible better vectorization of different reduction min/max reduction
Date: Thu, 09 Nov 2023 12:27:50 +0000	[thread overview]
Message-ID: <bug-112457-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 112457
           Summary: Possible better vectorization of different reduction
                    min/max reduction
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: juzhe.zhong at rivai dot ai
  Target Milestone: ---

Hi, Richard.

GCC-14 almost has all features of RVV.

I am planning to participate on improving GCC loop vectorizer in GCC-15.

Fix FAILs of TSVC is one of my plan.

Currently we can vectorize this following case:

int idx = 0;
int max = 0;
void foo (int n, int * __restrict a){
for (int i = 0; i < n; ++i) {
  max = max < a[i] ? a[i] : max;
}
}

However, if we change this case it failed:

void foo2 (int n, int * __restrict a){
for (int i = 0; i < n; ++i) {
  if (max < a[i]) {
    max = a[i];
  } else
    max = max;
}
}

Now, I notice another interesting and possible vectorization enhancement which
inspired by this patch of LLVM:
https://reviews.llvm.org/D143465

And more advance case is which is case from LLVM patch:
which is vectorization reduction with index:

void foo3 (int n, int * __restrict a){
for (int i = 0; i < n; ++i) {
  if (max < a[i]) {
    idx = i;
    max = a[i];
  }
}
}

I wonder it is a valuable optimization ? If yes, it would be one of my TODO
list.

Thanks.

             reply	other threads:[~2023-11-09 12:27 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-09 12:27 juzhe.zhong at rivai dot ai [this message]
2023-11-09 12:29 ` [Bug c/112457] " juzhe.zhong at rivai dot ai
2023-11-09 12:45 ` [Bug tree-optimization/112457] " rguenth at gcc dot gnu.org
2024-01-02  8:58 ` juzhe.zhong at rivai dot ai
2024-01-02 16:03 ` xry111 at gcc dot gnu.org
2024-01-08  9:00 ` 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-112457-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).