Skip to content

[flang][OpenMP] Skip multi-block teams regions when processing loop directives #132687

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

Merged
merged 1 commit into from
Mar 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions flang/lib/Optimizer/OpenMP/GenericLoopConversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,8 +398,8 @@ class ReductionsHoistingPattern

static mlir::omp::LoopOp
tryToFindNestedLoopWithReduction(mlir::omp::TeamsOp teamsOp) {
assert(!teamsOp.getRegion().empty() &&
teamsOp.getRegion().getBlocks().size() == 1);
if (teamsOp.getRegion().getBlocks().size() != 1)
return nullptr;

mlir::Block &teamsBlock = *teamsOp.getRegion().begin();
auto loopOpIter = llvm::find_if(teamsBlock, [](mlir::Operation &op) {
Expand Down
21 changes: 21 additions & 0 deletions flang/test/Lower/OpenMP/loop-directive.f90
Original file line number Diff line number Diff line change
Expand Up @@ -337,3 +337,24 @@ subroutine loop_teams_loop_reduction
x = x + i
end do
end subroutine


! Tests a regression when the pass encounters a multi-block `teams` region.
subroutine multi_block_teams
implicit none
integer :: i

! CHECK: omp.target {{.*}} {
! CHECK: omp.teams {
! CHECK: ^bb1:
! CHECK: cf.br ^bb2
! CHECK: ^bb2:
! CHECK: omp.terminator
! CHECK: }
! CHECK: }
!$omp target teams
select case (i)
case(1)
end select
!$omp end target teams
end subroutine