Skip to content

[flang] Allow cycle in target teams distribute [simd] #145462

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
Jun 24, 2025

Conversation

ergawy
Copy link
Member

@ergawy ergawy commented Jun 24, 2025

flang incorrectly issues a semantic erorr when a cycle statement is used inside a target teams distribute [simd] associated loop. This is not prevented by the spec, therefore this PR allows such construct.

flang incorrectly issues a semantic erorr when a `cycle` statement is
used inside a `target teams distribute [simd]` associated loop. This is
not prevented by the spec, therefore this PR allows such construct.
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:openmp flang:semantics labels Jun 24, 2025
@llvmbot
Copy link
Member

llvmbot commented Jun 24, 2025

@llvm/pr-subscribers-flang-semantics

@llvm/pr-subscribers-flang-openmp

Author: Kareem Ergawy (ergawy)

Changes

flang incorrectly issues a semantic erorr when a cycle statement is used inside a target teams distribute [simd] associated loop. This is not prevented by the spec, therefore this PR allows such construct.


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

2 Files Affected:

  • (modified) flang/lib/Semantics/check-directive-structure.h (+2)
  • (modified) flang/test/Semantics/OpenMP/do05-positivecase.f90 (+14)
diff --git a/flang/lib/Semantics/check-directive-structure.h b/flang/lib/Semantics/check-directive-structure.h
index 4a4893fe805a2..b1bf3e550aebc 100644
--- a/flang/lib/Semantics/check-directive-structure.h
+++ b/flang/lib/Semantics/check-directive-structure.h
@@ -76,6 +76,8 @@ template <typename D> class NoBranchingEnforce {
         case llvm::omp::Directive::OMPD_distribute_parallel_for:
         case llvm::omp::Directive::OMPD_distribute_simd:
         case llvm::omp::Directive::OMPD_distribute_parallel_for_simd:
+        case llvm::omp::Directive::OMPD_target_teams_distribute:
+        case llvm::omp::Directive::OMPD_target_teams_distribute_simd:
         case llvm::omp::Directive::OMPD_target_teams_distribute_parallel_do:
         case llvm::omp::Directive::
             OMPD_target_teams_distribute_parallel_do_simd:
diff --git a/flang/test/Semantics/OpenMP/do05-positivecase.f90 b/flang/test/Semantics/OpenMP/do05-positivecase.f90
index 8481cb2fc2ca0..eda04610535c2 100644
--- a/flang/test/Semantics/OpenMP/do05-positivecase.f90
+++ b/flang/test/Semantics/OpenMP/do05-positivecase.f90
@@ -57,4 +57,18 @@ program omp_do
     if(i<10) cycle
   end do
   !$omp end target teams distribute parallel do simd
+
+  !$omp target teams distribute 
+  !DEF: /omp_do/OtherConstruct6/i (OmpPrivate, OmpPreDetermined) HostAssoc INTEGER(4)
+  do i=1,100
+    !REF: /omp_do/OtherConstruct6/i
+    if(i < 5) cycle
+  end do
+
+  !$omp target teams distribute simd
+  !DEF: /omp_do/OtherConstruct7/i (OmpLinear, OmpPreDetermined) HostAssoc INTEGER(4)
+  do i=1,100
+    !REF: /omp_do/OtherConstruct7/i
+    if(i < 5) cycle
+  end do
 end program omp_do

Copy link
Contributor

@mjklemm mjklemm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@NimishMishra NimishMishra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks

@ergawy ergawy merged commit 9aebfde into main Jun 24, 2025
11 checks passed
@ergawy ergawy deleted the users/ergawy/cycle_in_target_teams_distribute branch June 24, 2025 12:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:openmp flang:semantics flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants