[flang-commits] [flang] [flang][OpenACC] Skip non-loop evaluations when descending a collapsed/tiled DO nest (PR #223579)

Razvan Lupusoru via flang-commits flang-commits at lists.llvm.org
Tue Sep 15 11:22:50 PDT 2026


================
@@ -0,0 +1,55 @@
+! RUN: bbc -fopenacc -emit-hlfir %s -o - | FileCheck %s
+
+! Verify that a compiler directive (e.g. !DIR$ IVDEP) appearing between the
+! levels of a collapsed loop nest does not get mistaken for the next nested
+! DO CONSTRUCT. The directive is an extra sibling evaluation between the
+! NonLabelDoStmt and the inner DoConstruct; the collapse descent must skip
+! over it rather than absorbing it as the loop body.
+
+subroutine collapse2_directive_between_loops(n, a)
+  integer, intent(in) :: n
+  integer :: a(n,n)
+  integer :: i, j
+
+  !$acc parallel loop collapse(2) copy(a)
+  do i = 1, n
+!DIR$ IVDEP
+    do j = 1, n
+      a(j,i) = 1
+    end do
+  end do
+  !$acc end parallel loop
+end subroutine
+
+! CHECK-LABEL: func.func @_QPcollapse2_directive_between_loops(
+! CHECK: acc.parallel
+! CHECK: acc.loop combined(parallel)
+! CHECK: hlfir.designate
+! CHECK: hlfir.assign
+! CHECK: acc.yield
+! CHECK: collapse([2])
+
+subroutine collapse3_directive_between_loops(n, a)
+  integer, intent(in) :: n
+  integer :: a(n,n,n)
+  integer :: i, j, k
+
+  !$acc parallel loop collapse(3) copy(a)
+  do i = 1, n
+!DIR$ NOVECTOR
----------------
razvanlupusoru wrote:

Would it make sense to add another test with directive between the inner loops?

And maybe also a `cuf kernel do` and `acc loop tile` test?


https://github.com/llvm/llvm-project/pull/223579


More information about the flang-commits mailing list