public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "tnfchris at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/114061] New: GCC fails vectorization when using __builtin_prefetch
Date: Thu, 22 Feb 2024 19:04:51 +0000	[thread overview]
Message-ID: <bug-114061-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 114061
           Summary: GCC fails vectorization when using __builtin_prefetch
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: tnfchris at gcc dot gnu.org
  Target Milestone: ---

The following example:

void foo(double * restrict a, double * restrict b, int n){
  int i;
  for(i=0; i<n; ++i){
    a[i] = a[i] + b[i];
    __builtin_prefetch(&(b[i+8]));
  }
}

fails to vectorize because of the __builtin_prefetch.

/app/example.c:5:5: missed:  statement clobbers memory: __builtin_prefetch
(_10);
/app/example.c:3:13: missed:  not vectorized: loop contains function calls or
data references that cannot be analyzed

However two things:

1. prefetching are usually hints anyway and not a correctness thing.  It should
be safe to elide the call and vectorizer as normal.
2. SVE has prefetched vector operations which we can use here.  The vector
prefetches are also predicated so they need to be actually codegened.

Perhaps one solution here would be to have a vect-pattern which checks for
COND_PREFETCH support if supported, and if not just elides the prefetch?

             reply	other threads:[~2024-02-22 19:04 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-22 19:04 tnfchris at gcc dot gnu.org [this message]
2024-02-22 19:07 ` [Bug tree-optimization/114061] " pinskia at gcc dot gnu.org
2024-02-22 19:09 ` tnfchris at gcc dot gnu.org
2024-02-22 19:11 ` pinskia at gcc dot gnu.org
2024-02-22 19:21 ` tnfchris at gcc dot gnu.org
2024-02-23  7:01 ` rguenth at gcc dot gnu.org
2024-04-08 14:01 ` victorldn at gcc dot gnu.org
2024-06-12 13:39 ` cvs-commit at gcc dot gnu.org
2024-06-12 17:15 ` pinskia 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-114061-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).