[flang-commits] [flang] [flang][OpenMP] Implement collapse for imperfectly nested loops (PR #202435)

Caroline Newcombe via flang-commits flang-commits at lists.llvm.org
Wed Jul 1 06:15:11 PDT 2026


cenewcombe 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?

https://github.com/llvm/llvm-project/pull/202435


More information about the flang-commits mailing list