Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
kiranchandramohan opened this issue Dec 4, 2023 · 4 comments · Fixed by #77761
Closed

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

kiranchandramohan opened this issue Dec 4, 2023 · 4 comments · Fixed by #77761

Comments

@kiranchandramohan
Copy link
Contributor

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
@kparzysz
Copy link
Contributor

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
Copy link
Contributor

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.

@kiranchandramohan
Copy link
Contributor Author

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.
flang-compiler#1178
flang-compiler#1394

kparzysz added a commit that referenced this issue Jan 11, 2024
This brings `createBodyOfOp` to its final intended form. First, input
privatization is performed, then the recursive lowering takes place,
and finally the output privatization (lastprivate) is done.

This enables fixing a known issue with infinite loops inside of an
OpenMP region, and the fix is included in this patch.

Fixes #74348.

Recursive lowering [5/5]
kparzysz added a commit that referenced this issue Jan 22, 2024
…77761)

This brings `createBodyOfOp` to its final intended form. First, input
privatization is performed, then the recursive lowering takes place, and
finally the output privatization (lastprivate) is done.

This enables fixing a known issue with infinite loops inside of an
OpenMP region, and the fix is included in this patch.

Fixes #74348.

Recursive lowering [5/5]

---------

Co-authored-by: Kiran Chandramohan <kiran.chandramohan@arm.com>
@llvmbot
Copy link
Collaborator

llvmbot commented Jan 22, 2024

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants