Skip to content

Conversation

@kiranchandramohan
Copy link
Contributor

Simdizable constructs are permitted in a simd region. The loop construct is a simdizable construct.

Also fixes the TODO corresponding to this.

Simdizable constructs are permitted in a simd region. The loop
construct is a simdizable construct.

Also fixes the TODO corresponding to this.
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:openmp flang:semantics labels Apr 23, 2025
@llvmbot
Copy link
Member

llvmbot commented Apr 23, 2025

@llvm/pr-subscribers-flang-semantics

@llvm/pr-subscribers-flang-openmp

Author: Kiran Chandramohan (kiranchandramohan)

Changes

Simdizable constructs are permitted in a simd region. The loop construct is a simdizable construct.

Also fixes the TODO corresponding to this.


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

2 Files Affected:

  • (modified) flang/lib/Semantics/check-omp-structure.cpp (+3-4)
  • (modified) flang/test/Semantics/OpenMP/nested-simd.f90 (+15)
diff --git a/flang/lib/Semantics/check-omp-structure.cpp b/flang/lib/Semantics/check-omp-structure.cpp
index 717982f66027c..fde97e74b1121 100644
--- a/flang/lib/Semantics/check-omp-structure.cpp
+++ b/flang/lib/Semantics/check-omp-structure.cpp
@@ -849,8 +849,6 @@ void OmpStructureChecker::CheckSIMDNest(const parser::OpenMPConstruct &c) {
   //  The only OpenMP constructs that can be encountered during execution of
   // a simd region are the `atomic` construct, the `loop` construct, the `simd`
   // construct and the `ordered` construct with the `simd` clause.
-  // TODO:  Expand the check to include `LOOP` construct as well when it is
-  // supported.
 
   // Check if the parent context has the SIMD clause
   // Please note that we use GetContext() instead of GetContextParent()
@@ -893,14 +891,15 @@ void OmpStructureChecker::CheckSIMDNest(const parser::OpenMPConstruct &c) {
               }
             }
           },
-          // Allowing SIMD construct
+          // Allowing SIMD and loop construct
           [&](const parser::OpenMPLoopConstruct &c) {
             const auto &beginLoopDir{
                 std::get<parser::OmpBeginLoopDirective>(c.t)};
             const auto &beginDir{
                 std::get<parser::OmpLoopDirective>(beginLoopDir.t)};
             if ((beginDir.v == llvm::omp::Directive::OMPD_simd) ||
-                (beginDir.v == llvm::omp::Directive::OMPD_do_simd)) {
+                (beginDir.v == llvm::omp::Directive::OMPD_do_simd) ||
+                (beginDir.v == llvm::omp::Directive::OMPD_loop)) {
               eligibleSIMD = true;
             }
           },
diff --git a/flang/test/Semantics/OpenMP/nested-simd.f90 b/flang/test/Semantics/OpenMP/nested-simd.f90
index c9fb90cdeceb2..9b2e40a9f5ab6 100644
--- a/flang/test/Semantics/OpenMP/nested-simd.f90
+++ b/flang/test/Semantics/OpenMP/nested-simd.f90
@@ -189,3 +189,18 @@ SUBROUTINE NESTED_BAD(N)
 
 
 END SUBROUTINE NESTED_BAD
+
+SUBROUTINE SIMD_LOOP(A, B, N)
+  REAL :: A(100), B(100)
+  INTEGER :: I, J, N
+
+  !$OMP SIMD
+  DO I = 1, N
+    !$OMP LOOP
+    DO J = 1, N
+      B(J) = B(J) + A(J)
+    END DO
+    !$OMP END LOOP
+  END DO
+  !$OMP END SIMD
+END SUBROUTINE

Copy link
Contributor

@tblah tblah 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 Kiran

@kiranchandramohan kiranchandramohan merged commit 1b5cd1d into llvm:main Apr 28, 2025
15 checks passed
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
Simdizable constructs are permitted in a simd region. The loop construct
is a simdizable construct.

Also fixes the TODO corresponding to this.
GeorgeARM pushed a commit to GeorgeARM/llvm-project that referenced this pull request May 7, 2025
Simdizable constructs are permitted in a simd region. The loop construct
is a simdizable construct.

Also fixes the TODO corresponding to this.
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.

3 participants