Skip to content

Commit 4fa5ab3

Browse files
authored
[flang][OpenMP] Skip multi-block teams regions when processing loop directives (llvm#132687)
Fixes a regression when the generic `loop` directive conversion pass encounters a multi-block `teams` region. At the moment, we skip such regions.
1 parent 2f2c02e commit 4fa5ab3

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

flang/lib/Optimizer/OpenMP/GenericLoopConversion.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,8 +398,8 @@ class ReductionsHoistingPattern
398398

399399
static mlir::omp::LoopOp
400400
tryToFindNestedLoopWithReduction(mlir::omp::TeamsOp teamsOp) {
401-
assert(!teamsOp.getRegion().empty() &&
402-
teamsOp.getRegion().getBlocks().size() == 1);
401+
if (teamsOp.getRegion().getBlocks().size() != 1)
402+
return nullptr;
403403

404404
mlir::Block &teamsBlock = *teamsOp.getRegion().begin();
405405
auto loopOpIter = llvm::find_if(teamsBlock, [](mlir::Operation &op) {

flang/test/Lower/OpenMP/loop-directive.f90

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,3 +337,24 @@ subroutine loop_teams_loop_reduction
337337
x = x + i
338338
end do
339339
end subroutine
340+
341+
342+
! Tests a regression when the pass encounters a multi-block `teams` region.
343+
subroutine multi_block_teams
344+
implicit none
345+
integer :: i
346+
347+
! CHECK: omp.target {{.*}} {
348+
! CHECK: omp.teams {
349+
! CHECK: ^bb1:
350+
! CHECK: cf.br ^bb2
351+
! CHECK: ^bb2:
352+
! CHECK: omp.terminator
353+
! CHECK: }
354+
! CHECK: }
355+
!$omp target teams
356+
select case (i)
357+
case(1)
358+
end select
359+
!$omp end target teams
360+
end subroutine

0 commit comments

Comments
 (0)