https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128307
Bug ID: 128307
Summary: wrong code with -fopenmp: omp for
schedule(simd:static, 1) runs only the first iteration
of each chunk
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Keywords: openmp, wrong-code
Severity: normal
Priority: P3
Component: middle-end
Assignee: unassigned at gcc dot gnu.org
Reporter: kyuwoncho18 at gmail dot com
Target Milestone: ---
Target: x86_64-pc-linux-gnu
#include <stdio.h>
int main(void)
{
int a[8] = { 0 };
#pragma omp parallel num_threads(1)
#pragma omp for schedule(simd:static, 1)
for (int i = 0; i < 8; ++i)
a[i] = 1;
int sum = 0;
for (int i = 0; i < 8; ++i)
sum += a[i];
printf("%d\n", sum);
return 0;
}
godbolt: https://godbolt.org/z/xzG77Yzvf
Each of the 8 iterations stores 1, so the program must print 8, as it does at
-O0 -fopenmp and with -O2 -fopenmp -fno-tree-loop-vectorize. With -fopenmp at
-O1, -O2, -O3 and -Os it prints 1; with schedule(simd:static, 2) or
schedule(static, 1) it prints 8.