Skip to content

[Flang][OpenMP] Permit loop construct in simd regions #137020

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
Apr 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions flang/lib/Semantics/check-omp-structure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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;
}
},
Expand Down
15 changes: 15 additions & 0 deletions flang/test/Semantics/OpenMP/nested-simd.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading