Skip to content

Commit c28703e

Browse files
[Flang][OpenMP] Permit loop construct in simd regions
Simdizable constructs are permitted in a simd region. The loop construct is a simdizable construct. Also fixes the TODO corresponding to this.
1 parent 913dcf1 commit c28703e

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

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

+3-4
Original file line numberDiff line numberDiff line change
@@ -849,8 +849,6 @@ void OmpStructureChecker::CheckSIMDNest(const parser::OpenMPConstruct &c) {
849849
// The only OpenMP constructs that can be encountered during execution of
850850
// a simd region are the `atomic` construct, the `loop` construct, the `simd`
851851
// construct and the `ordered` construct with the `simd` clause.
852-
// TODO: Expand the check to include `LOOP` construct as well when it is
853-
// supported.
854852

855853
// Check if the parent context has the SIMD clause
856854
// Please note that we use GetContext() instead of GetContextParent()
@@ -893,14 +891,15 @@ void OmpStructureChecker::CheckSIMDNest(const parser::OpenMPConstruct &c) {
893891
}
894892
}
895893
},
896-
// Allowing SIMD construct
894+
// Allowing SIMD and loop construct
897895
[&](const parser::OpenMPLoopConstruct &c) {
898896
const auto &beginLoopDir{
899897
std::get<parser::OmpBeginLoopDirective>(c.t)};
900898
const auto &beginDir{
901899
std::get<parser::OmpLoopDirective>(beginLoopDir.t)};
902900
if ((beginDir.v == llvm::omp::Directive::OMPD_simd) ||
903-
(beginDir.v == llvm::omp::Directive::OMPD_do_simd)) {
901+
(beginDir.v == llvm::omp::Directive::OMPD_do_simd) ||
902+
(beginDir.v == llvm::omp::Directive::OMPD_loop)) {
904903
eligibleSIMD = true;
905904
}
906905
},

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

+15
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)