llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[Flang][OpenMP] Error when unstructured code is present

Open kiranchandramohan opened this issue 3 years ago • 4 comments

This is another instance where the presence of unstructured code in OpenMP regions leads to failure.

Error

error: loc("fname.f90":10:3): operation with block successors must terminate its parent block

Program

subroutine sb(ninter, numnod)
  integer :: ninter, numnod
  integer, dimension(:), allocatable :: indx_nm

  !$omp parallel
  if (ninter>0) then
    allocate( indx_nm(numnod) )
  endif
  220      continue
  goto 220
  !$omp end parallel
end subroutine

kiranchandramohan avatar Dec 04 '23 17:12 kiranchandramohan

There is the problem:

    "omp.parallel"() <{operandSegmentSizes = array<i32: 0, 0, 0, 0, 0>}> ({
      [...]
      "cf.br"()[^bb1] : () -> ()
    ^bb1:  // 2 preds: ^bb0, ^bb1
      "cf.br"()[^bb1] : () -> ()       // <-- not terminating the block
      "omp.terminator"() : () -> ()
    }) : () -> ()

kparzysz avatar Dec 14 '23 20:12 kparzysz

This happens because we always insert a terminator into the last block of the construct. In this case the last block is the loop (which is lowered later, and inserts its own branch), and we end up with omp.terminator and cf.br in the same block.

This looks like it would be solved by the recursive lowering, since the loop would be lowered as a part of the parallel op lowering. This would make it possible to only insert omp.terminator where there isn't one already. I'll try to have a prototype of that working soon.

kparzysz avatar Dec 14 '23 21:12 kparzysz

Thanks @kparzysz for investigating this. It will be great if it works with your proposal.

It might be good to go back and have a look at some of the previous fixes to ensure that you have the full context. https://github.com/flang-compiler/f18-llvm-project/pull/1178 https://github.com/flang-compiler/f18-llvm-project/pull/1394

kiranchandramohan avatar Dec 15 '23 12:12 kiranchandramohan

@llvm/issue-subscribers-flang-ir

Author: Kiran Chandramohan (kiranchandramohan)

This is another instance where the presence of unstructured code in OpenMP regions leads to failure.

Error

error: loc("fname.f90":10:3): operation with block successors must terminate its parent block

Program

subroutine sb(ninter, numnod)
  integer :: ninter, numnod
  integer, dimension(:), allocatable :: indx_nm

  !$omp parallel
  if (ninter&gt;0) then
    allocate( indx_nm(numnod) )
  endif
  220      continue
  goto 220
  !$omp end parallel
end subroutine

llvmbot avatar Jan 22 '24 15:01 llvmbot