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

            Bug ID: 128149
           Summary: wrong code with -fopenmp at -O1 and above: a
                    100-iteration loop with schedule(simd:dynamic,
                    LONG_MAX) does not terminate
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Keywords: 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 <limits.h>
#include <stdio.h>

int main(void)
{
  int count = 0;
#pragma omp parallel for simd num_threads(2) schedule(simd:dynamic, LONG_MAX)
reduction(+:count)
  for (long i = 0; i < 100; ++i)
    count++;
  printf("%d\n", count);
  return count != 100;
}

godbolt: https://godbolt.org/z/bTY1nY5rn

On x86-64, -O0 -fopenmp prints 100 and exits normally, while -O1, -O2, -O3 and
-Os with -fopenmp produce no output and hit Compiler Explorer's 20-second
execution limit. The loop has 100 iterations and a positive, constant chunk
size, so the reduction must produce 100 and the program must terminate. With
-O1 -fopenmp, either removing the simd schedule modifier or changing the chunk
size to LONG_MAX - 15 makes it print 100 and exit normally.

Reply via email to