[flang-commits] [flang] [flang][OpenMP] Implement collapse for imperfectly nested loops (PR #202435)
Deepak Eachempati via flang-commits
flang-commits at lists.llvm.org
Wed Jul 1 07:55:15 PDT 2026
dreachem wrote:
> > I was wondering about whether we need to handle a case like this?
> > ```
> > !$omp do collapse(2)
> > do i = 1, n
> > call imperfect_nest()
> > do j = 1, 0 ! zero iterations
> > call body()
> > end do
> > end do
> > ```
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > I think it behaviour is unspecified and we can ignore it, but I wanted to check if anyone else has thoughts.
>
> @dreachem I wanted to consult your knowledge of the spec per @tblah's example of a zero trip inner loop with collapse. My implementation flattens the nest into the product iteration space, so a zero-trip inner loop makes the whole space empty and the intervening imperfect_nest() runs 0 times (no crash, just 0 executions) — whereas the serialized nest would run it n times.
>
> Is the 0-execution behavior conforming (i.e. intervening code is defined over the collapsed logical iteration space), or does the standard require the serialized-nest semantics here? Or is it simply undefined?
@cenewcombe @tblah That example would be non-conforming (i.e., unspecified behavior). The spec says the following:
> If the iteration count of any loop is zero and that loop does not enclose the intervening code, the behavior is unspecified.
That means the spec makes no guarantees for the behavior of such a program. That should probably instead be listed as a restriction, so it's clear to the reader that the intent is that this is non-conforming.
https://github.com/llvm/llvm-project/pull/202435
More information about the flang-commits
mailing list