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

--- Comment #3 from Tobias Burnus <burnus at gcc dot gnu.org> ---
Commenting out the 'gcc_assert' of comment 0, it compiles and produces the
following dump.
I don't understand why there is a 'lastprivate' – and 'i' in the bounds are
wrong: for the first iteration, it is undefined and otherwise, it lags always
behind.

          #pragma omp simd lastprivate(count.0) collapse(2)
          for (count.0 = 0; count.0 < 5; count.0 = count.0 + 1)
            for (j = 1; j <= i; j = j + 1)
              {
                i = count.0 * 2 + 1;
                L.1:;
              }

And yet another variant:
   !$omp do simd collapse(2)
   do i = 1, 9, 2
      do j = 1, i, 2
i.e. both with non-unit strides. Then the result is still an ICE; commenting
the assert, the result is:

    D.4265 = (i + 1) / 2;  // Ups! This should use 'count.1' and shall not be
hoisted!
    #pragma omp for collapse(2)
      {
        {
          #pragma omp simd lastprivate(count.1) lastprivate(count.0)
collapse(2)
          for (count.0 = 0; count.0 < 5; count.0 = count.0 + 1)
            for (count.1 = 0; count.1 < D.4265; count.1 = count.1 + 1)
              {
                i = count.0 * 2 + 1;
                j = count.1 * 2 + 1;
                L.1:;
              }

Here, COUNT is used in the inner loop - that would be also the option for the
stride==1 case, but as the expression needs to be in the condition already, it
might be better to have for inner stride == 1:
            for (j = 1; j <= count.0 * 2 + 1; j = j + 1)
and for inner stride == 2:
            for (j = 1; j <= (count.0 * 2 + 1 + 1) / 2; j = j + 1)

We probably need to check whether any of lb,ub,stride contains a parent loop
var.

Reply via email to