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

            Bug ID: 128073
           Summary: wrong code with -fopenmp-simd for omp simd collapse(2)
                    with an unsigned char outer loop and a non-constant
                    inner step
           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

__attribute__((noipa)) int
f (long step)
{
  int sum = 0;
#pragma omp simd collapse(2) reduction(+:sum)
  for (unsigned char i = 0; i < 2; ++i)
    for (long j = 0; j < 300; j += step)
      sum++;
  return sum;
}

int
main (void)
{
  if (f (1) != 600)
    __builtin_abort ();
}

godbolt: https://godbolt.org/z/9zsscrv1P

The collapsed nest runs 2 x 300 times, so f (1) returns 600. Without
-fopenmp-simd the program exits normally; with -fopenmp-simd or -fopenmp, at
-O0 and above, f (1) returns 88 and the program aborts. With an unsigned short
outer iterator it returns 600.

Reply via email to