https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120164
Bug ID: 120164
Summary: GCC fails vectorization when using conditional
__builtin_prefetch
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Keywords: missed-optimization
Severity: enhancement
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: pinskia at gcc dot gnu.org
CC: rguenth at gcc dot gnu.org, tnfchris at gcc dot gnu.org,
victorldn at gcc dot gnu.org
Depends on: 114061
Blocks: 53947, 120162
Target Milestone: ---
+++ This bug was initially created as a clone of Bug #114061 +++
The following example:
void foo(double * restrict a, double * restrict b, int n){
int i;
for(i=0; i<n; ++i){
if (i % 1024 == 0)
__builtin_prefetch(&(b[i+1024]));
a[i] = a[i] + b[i];
}
}
fails to vectorize because of the __builtin_prefetch block.
/app/example.cpp:3:13: note: using as main loop exit: 6 -> 11 [AUX: (nil)]
/app/example.cpp:3:13: missed: not vectorized: unsupported control flow in
loop.
/app/example.cpp:3:13: missed: bad loop form.
/app/example.cpp:3:13: missed: couldn't vectorize loop
/app/example.cpp:3:13: missed: not vectorized: unsupported control flow in
loop.
/app/example.cpp:1:6: note: vectorized 0 loops in function.
However:
prefetching are usually hints anyway and not a correctness thing. It should be
safe to elide the call and vectorizer as normal.
Referenced Bugs:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53947
[Bug 53947] [meta-bug] vectorizer missed-optimizations
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114061
[Bug 114061] GCC fails vectorization when using __builtin_prefetch
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120162
[Bug 120162] Prefetch causes vectorization to fail