https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122361
Bug ID: 122361
Summary: [OpenMP] Resolve 'false'/not-matching context
selectors earlier
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Keywords: missed-optimization, openmp, rejects-valid
Severity: normal
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: burnus at gcc dot gnu.org
Target Milestone: ---
This is a follow up to both PR122306 and PR120180:
GCC rejects code like the following in Fortran - but accepts it with C:
!$omp metadirective &
!$omp& when (implementation={vendor("gnu")}: &
!$omp& teams distribute parallel do COLLAPSE(2) ) &
!$omp& otherwise(parallel do)
do i = 1, N
!$omp metadirective when (implementation={vendor("ibm")}: simd)
do i = 1, N
a(i,j) = b(j,i)
end do
end do
The problem is that 'COLLAPSE(2) + 'simd' clash – but the compiler could
remove the inner 'metadirective' as for GCC, 'otherwise(nothing)' applies.
There is currently a skip-check in openmp.cc's gfc_resolve_omp_context_selector
but only for 'user={condition(expr)}'.
There are a couple of additional cases which can be optimized, like the one
shown above. That's handled via omp_context_selector_matches.
This can be called early for C/C++, but for Fortran, it is only called during
trans-openmp.cc, which comes too late for the
Error: not enough DO loops for collapsed
check. An attempt to call the omp_context_selector_matches function from
gfc_resolve_omp_context_selector failed because the 'tree' cannot always be
generated during resolution time. In particular, the following is not possible:
subroutine sub(flag)
logical :: flag
...
!$omp metadirective when(user={ condition(flag) }: nothing)
as this requires that sym->backend_decl is already set for the PARM_DECL.
* * *
EXPECTED: Handle more/all not-matching cases during resolution; this requires
some additional handling in gfc_resolve_omp_context_selector but also the
possibility to do checks via a (new) middle-end function in omp-general.cc that
does not require a 'tree' - or at least less tree.