https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127616

            Bug ID: 127616
           Summary: OpenMP map iterator wrong code
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: parras at gcc dot gnu.org
  Target Milestone: ---

Created attachment 65687
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=65687&action=edit
Runtime test

The following map-iterator shape produces wrong results:

  iterator(ii=1:N, jj=1:M): a(1:2, ii), b(1:2, jj)

where a's update only depends on ii, b's only on jj.

This is because remove_unused_omp_iterator_vars (gimplify.cc) finds in
OMP_CLAUSE_DECL no literal reference to either ii or jj, which are concealed in
the OMP_ITERATOR_BLOCK (see -fdump-tree-original-details). The root cause is in
the Fortran FE: OMP_CLAUSE_DECL goes through gfc_evaluate_now (via
gfc_conv_expr_descriptor), which replaces the iterator variables with scalar
temporaries (parm.0, parm.1, etc.).

Fixing it by walking the whole OMP_ITERATOR_BLOCK in
remove_unused_omp_iterator_vars would be tricky and error-prone.

A cleaner solution would be for Fortran to skip remove_unused_omp_iterator_vars
entirely and do the pruning in the front end instead. Note: not pruning at all
would restore the correct behaviour but result in a blow-up in the iteration
space.

Concretely, after pruning, the initial code should have the shape:

  iterator(ii=1:N): a(1:2, ii)
  iterator(jj=1:M): b(1:2, jj)

Reply via email to