public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/114061] New: GCC fails vectorization when using __builtin_prefetch
@ 2024-02-22 19:04 tnfchris at gcc dot gnu.org
  2024-02-22 19:07 ` [Bug tree-optimization/114061] " pinskia at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: tnfchris at gcc dot gnu.org @ 2024-02-22 19:04 UTC (permalink / raw)
  To: gcc-bugs

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?

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug tree-optimization/114061] GCC fails vectorization when using __builtin_prefetch
  2024-02-22 19:04 [Bug tree-optimization/114061] New: GCC fails vectorization when using __builtin_prefetch tnfchris at gcc dot gnu.org
@ 2024-02-22 19:07 ` pinskia at gcc dot gnu.org
  2024-02-22 19:09 ` tnfchris at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-02-22 19:07 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I thought there was already one recorded about this.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug tree-optimization/114061] GCC fails vectorization when using __builtin_prefetch
  2024-02-22 19:04 [Bug tree-optimization/114061] New: GCC fails vectorization when using __builtin_prefetch tnfchris at gcc dot gnu.org
  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
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: tnfchris at gcc dot gnu.org @ 2024-02-22 19:09 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Tamar Christina <tnfchris at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #1)
> I thought there was already one recorded about this.

I could only find https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103938 about an
ICE when prefetching a vector address.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug tree-optimization/114061] GCC fails vectorization when using __builtin_prefetch
  2024-02-22 19:04 [Bug tree-optimization/114061] New: GCC fails vectorization when using __builtin_prefetch tnfchris at gcc dot gnu.org
  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
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-02-22 19:11 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2024-02-22
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW
           Severity|normal                      |enhancement

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.

Though maybe we should drop them in the vectorized version of the loop. HW
prefetchers usually do a decent job and sometimes (maybe most) SW hinted
prefetches interfere with the HW prefetchers.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug tree-optimization/114061] GCC fails vectorization when using __builtin_prefetch
  2024-02-22 19:04 [Bug tree-optimization/114061] New: GCC fails vectorization when using __builtin_prefetch tnfchris at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  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
  5 siblings, 0 replies; 7+ messages in thread
From: tnfchris at gcc dot gnu.org @ 2024-02-22 19:21 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Tamar Christina <tnfchris at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #3)
> Confirmed.
> 
> Though maybe we should drop them in the vectorized version of the loop. HW
> prefetchers usually do a decent job and sometimes (maybe most) SW hinted
> prefetches interfere with the HW prefetchers.

definitely agree that I'm not sure how useful they are, but some customers
definitely seem to want them.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug tree-optimization/114061] GCC fails vectorization when using __builtin_prefetch
  2024-02-22 19:04 [Bug tree-optimization/114061] New: GCC fails vectorization when using __builtin_prefetch tnfchris at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  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
  5 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-02-23  7:01 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |rguenth at gcc dot gnu.org

--- Comment #5 from Richard Biener <rguenth at gcc dot gnu.org> ---
I think we could try to "vectorize" them by only updating the address (the
builtin doesn't specify a size) when that evolves in the scalar loop, updating
the step with the chosen VF.

Dependence shouldn't be a concern here.

The main issue is a representational - how to handle this in data-ref and
dependence analysis (or whether to just "skip" them in the vectorizer).

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug tree-optimization/114061] GCC fails vectorization when using __builtin_prefetch
  2024-02-22 19:04 [Bug tree-optimization/114061] New: GCC fails vectorization when using __builtin_prefetch tnfchris at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2024-02-23  7:01 ` rguenth at gcc dot gnu.org
@ 2024-04-08 14:01 ` victorldn at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: victorldn at gcc dot gnu.org @ 2024-04-08 14:01 UTC (permalink / raw)
  To: gcc-bugs

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

Victor Do Nascimento <victorldn at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |victorldn at gcc dot gnu.org
             Status|NEW                         |ASSIGNED
                 CC|                            |victorldn at gcc dot gnu.org

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-04-08 14:01 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-22 19:04 [Bug tree-optimization/114061] New: GCC fails vectorization when using __builtin_prefetch tnfchris at gcc dot gnu.org
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

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