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 via email to