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

Conversation

ergawy
Copy link
Member

@ergawy ergawy commented Mar 24, 2025

Fixes a regression when the generic loop directive conversion pass encounters a multi-block teams region. At the moment, we skip such regions.

…p` directives

Fixes a regression when the generic `loop` directive conversion pass
encounters a multi-block `teams` region. At the moment, we skip such
regions.
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:fir-hlfir flang:openmp labels Mar 24, 2025
@ergawy ergawy requested review from skatrak and jsjodin March 24, 2025 07:48
@llvmbot
Copy link
Member

llvmbot commented Mar 24, 2025

@llvm/pr-subscribers-flang-openmp

@llvm/pr-subscribers-flang-fir-hlfir

Author: Kareem Ergawy (ergawy)

Changes

Fixes a regression when the generic loop directive conversion pass encounters a multi-block teams region. At the moment, we skip such regions.


Full diff: https://github.com/llvm/llvm-project/pull/132687.diff

2 Files Affected:

  • (modified) flang/lib/Optimizer/OpenMP/GenericLoopConversion.cpp (+2-2)
  • (modified) flang/test/Lower/OpenMP/loop-directive.f90 (+21)
diff --git a/flang/lib/Optimizer/OpenMP/GenericLoopConversion.cpp b/flang/lib/Optimizer/OpenMP/GenericLoopConversion.cpp
index 2ca1de1e1cbd6..74ad6330b11a7 100644
--- a/flang/lib/Optimizer/OpenMP/GenericLoopConversion.cpp
+++ b/flang/lib/Optimizer/OpenMP/GenericLoopConversion.cpp
@@ -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) {
diff --git a/flang/test/Lower/OpenMP/loop-directive.f90 b/flang/test/Lower/OpenMP/loop-directive.f90
index 8cf2e98332d7d..954985e2d64f1 100644
--- a/flang/test/Lower/OpenMP/loop-directive.f90
+++ b/flang/test/Lower/OpenMP/loop-directive.f90
@@ -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

@dpalermo dpalermo self-requested a review March 24, 2025 12:42
@dpalermo dpalermo merged commit 4fa5ab3 into main Mar 24, 2025
15 checks passed
@dpalermo dpalermo deleted the users/ergawy/donot_assert_on_empty_teams_regions branch March 24, 2025 12:43
searlmc1 pushed a commit to ROCm/llvm-project that referenced this pull request Mar 24, 2025
…p` 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:fir-hlfir flang:openmp flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants