Skip to content

Commit 1b5cd1d

Browse files
[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.
1 parent d1a84b9 commit 1b5cd1d

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

flang/lib/Semantics/check-omp-structure.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -867,8 +867,6 @@ void OmpStructureChecker::CheckSIMDNest(const parser::OpenMPConstruct &c) {
867867
// The only OpenMP constructs that can be encountered during execution of
868868
// a simd region are the `atomic` construct, the `loop` construct, the `simd`
869869
// construct and the `ordered` construct with the `simd` clause.
870-
// TODO: Expand the check to include `LOOP` construct as well when it is
871-
// supported.
872870

873871
// Check if the parent context has the SIMD clause
874872
// Please note that we use GetContext() instead of GetContextParent()
@@ -911,14 +909,15 @@ void OmpStructureChecker::CheckSIMDNest(const parser::OpenMPConstruct &c) {
911909
}
912910
}
913911
},
914-
// Allowing SIMD construct
912+
// Allowing SIMD and loop construct
915913
[&](const parser::OpenMPLoopConstruct &c) {
916914
const auto &beginLoopDir{
917915
std::get<parser::OmpBeginLoopDirective>(c.t)};
918916
const auto &beginDir{
919917
std::get<parser::OmpLoopDirective>(beginLoopDir.t)};
920918
if ((beginDir.v == llvm::omp::Directive::OMPD_simd) ||
921-
(beginDir.v == llvm::omp::Directive::OMPD_do_simd)) {
919+
(beginDir.v == llvm::omp::Directive::OMPD_do_simd) ||
920+
(beginDir.v == llvm::omp::Directive::OMPD_loop)) {
922921
eligibleSIMD = true;
923922
}
924923
},

flang/test/Semantics/OpenMP/nested-simd.f90

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,3 +189,18 @@ SUBROUTINE NESTED_BAD(N)
189189

190190

191191
END SUBROUTINE NESTED_BAD
192+
193+
SUBROUTINE SIMD_LOOP(A, B, N)
194+
REAL :: A(100), B(100)
195+
INTEGER :: I, J, N
196+
197+
!$OMP SIMD
198+
DO I = 1, N
199+
!$OMP LOOP
200+
DO J = 1, N
201+
B(J) = B(J) + A(J)
202+
END DO
203+
!$OMP END LOOP
204+
END DO
205+
!$OMP END SIMD
206+
END SUBROUTINE

0 commit comments

Comments
 (0)