[flang-commits] [flang] 1b5cd1d - [Flang][OpenMP] Permit loop construct in simd regions (#137020)

via flang-commits flang-commits at lists.llvm.org
Mon Apr 28 08:20:02 PDT 2025


Author: Kiran Chandramohan
Date: 2025-04-28T16:19:59+01:00
New Revision: 1b5cd1dfb3b9597a2a04f25e04143f218ebf5459

URL: https://github.com/llvm/llvm-project/commit/1b5cd1dfb3b9597a2a04f25e04143f218ebf5459
DIFF: https://github.com/llvm/llvm-project/commit/1b5cd1dfb3b9597a2a04f25e04143f218ebf5459.diff

LOG: [Flang][OpenMP] Permit loop construct in simd regions (#137020)

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

Also fixes the TODO corresponding to this.

Added: 
    

Modified: 
    flang/lib/Semantics/check-omp-structure.cpp
    flang/test/Semantics/OpenMP/nested-simd.f90

Removed: 
    


################################################################################
diff  --git a/flang/lib/Semantics/check-omp-structure.cpp b/flang/lib/Semantics/check-omp-structure.cpp
index 987066313fee5..d9fe32bae1c27 100644
--- a/flang/lib/Semantics/check-omp-structure.cpp
+++ b/flang/lib/Semantics/check-omp-structure.cpp
@@ -867,8 +867,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()
@@ -911,14 +909,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


        


More information about the flang-commits mailing list