[llvm-branch-commits] [flang] [flang][OpenACC] Test unstructured seq loops that stay TODO in kernels (PR #240802)

Kareem Ergawy via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Nov 10 03:59:57 PST 2026


https://github.com/ergawy created https://github.com/llvm/llvm-project/pull/240802

Cover the unstructured `acc loop seq` shapes in kernels that still hit the "unstructured do loop in acc kernels" TODO on the seq loop's own DO: a seq loop inside an unstructured IF, SELECT CASE, BLOCK or DO WHILE, a loop that is seq only for a non-default device_type, and auto loops. Each case checks its pre-FIR tree, and every TODO check in the file now names the line of the loop it fires on, using split-file --leading-lines.

Stacked on https://github.com/llvm/llvm-project/pull/240801.

🤖 Generated with [Claude Code](https://claude.com/claude-code)


>From 7efed70f5b830a7a532849c590a2c16da71aea06 Mon Sep 17 00:00:00 2001
From: ergawy <kareem.ergawy at gmail.com>
Date: Tue, 10 Nov 2026 03:44:41 -0800
Subject: [PATCH] [flang][OpenACC] Test unstructured seq loops that stay TODO
 in kernels

Cover the unstructured `acc loop seq` shapes in kernels that still hit
the "unstructured do loop in acc kernels" TODO on the seq loop's own
DO: a seq loop inside an unstructured IF, SELECT CASE, BLOCK or DO
WHILE, a loop that is seq only for a non-default device_type, and auto
loops. Each case checks its pre-FIR tree, and every TODO check in the
file now names the line of the loop it fires on, using split-file
--leading-lines.
---
 .../Todo/do-loops-to-acc-loops-todo.f90       | 295 +++++++++++++++++-
 1 file changed, 289 insertions(+), 6 deletions(-)

diff --git a/flang/test/Lower/OpenACC/Todo/do-loops-to-acc-loops-todo.f90 b/flang/test/Lower/OpenACC/Todo/do-loops-to-acc-loops-todo.f90
index 9bba7aa067ffa..1c244520774d9 100644
--- a/flang/test/Lower/OpenACC/Todo/do-loops-to-acc-loops-todo.f90
+++ b/flang/test/Lower/OpenACC/Todo/do-loops-to-acc-loops-todo.f90
@@ -1,9 +1,23 @@
-! RUN: split-file %s %t
+! RUN: split-file --leading-lines %s %t
 ! RUN: %not_todo_cmd bbc -fopenacc -emit-hlfir %t/do_loop_with_cycle_goto.f90 -o - 2>&1 | FileCheck %s --check-prefix=CHECK2
 ! RUN: %not_todo_cmd bbc -fopenacc -emit-hlfir %t/nested_goto_loop.f90 -o - 2>&1 | FileCheck %s --check-prefix=CHECK3
 ! RUN: %not_todo_cmd bbc -fopenacc -emit-hlfir %t/collapse_lt.f90 -o - 2>&1 | FileCheck %s --check-prefix=CHECK7
 ! RUN: %not_todo_cmd bbc -fopenacc -emit-hlfir %t/collapse_gt.f90 -o - 2>&1 | FileCheck %s --check-prefix=CHECK8
 ! RUN: %not_todo_cmd bbc -fopenacc -emit-hlfir %t/collapse_nested.f90 -o - 2>&1 | FileCheck %s --check-prefix=CHECK6
+! RUN: bbc -fopenacc -pft-test -o /dev/null %t/seq_exit_in_if.f90 | FileCheck %s --check-prefix=PFT12
+! RUN: %not_todo_cmd bbc -fopenacc -emit-hlfir %t/seq_exit_in_if.f90 -o - 2>&1 | FileCheck %s --check-prefix=CHECK12
+! RUN: bbc -fopenacc -pft-test -o /dev/null %t/seq_exit_in_select_case.f90 | FileCheck %s --check-prefix=PFT13
+! RUN: %not_todo_cmd bbc -fopenacc -emit-hlfir %t/seq_exit_in_select_case.f90 -o - 2>&1 | FileCheck %s --check-prefix=CHECK13
+! RUN: bbc -fopenacc -pft-test -o /dev/null %t/seq_exit_in_block.f90 | FileCheck %s --check-prefix=PFT14
+! RUN: %not_todo_cmd bbc -fopenacc -emit-hlfir %t/seq_exit_in_block.f90 -o - 2>&1 | FileCheck %s --check-prefix=CHECK14
+! RUN: bbc -fopenacc -pft-test -o /dev/null %t/seq_exit_in_do_while.f90 | FileCheck %s --check-prefix=PFT15
+! RUN: %not_todo_cmd bbc -fopenacc -emit-hlfir %t/seq_exit_in_do_while.f90 -o - 2>&1 | FileCheck %s --check-prefix=CHECK15
+! RUN: bbc -fopenacc -pft-test -o /dev/null %t/seq_exit_device_type_seq.f90 | FileCheck %s --check-prefix=PFT16
+! RUN: %not_todo_cmd bbc -fopenacc -emit-hlfir %t/seq_exit_device_type_seq.f90 -o - 2>&1 | FileCheck %s --check-prefix=CHECK16
+! RUN: bbc -fopenacc -pft-test -o /dev/null %t/auto_exit_in_kernels.f90 | FileCheck %s --check-prefix=PFT17
+! RUN: %not_todo_cmd bbc -fopenacc -emit-hlfir %t/auto_exit_in_kernels.f90 -o - 2>&1 | FileCheck %s --check-prefix=CHECK17
+! RUN: bbc -fopenacc -pft-test -o /dev/null %t/loop_exit_in_kernels.f90 | FileCheck %s --check-prefix=PFT18
+! RUN: %not_todo_cmd bbc -fopenacc -emit-hlfir %t/loop_exit_in_kernels.f90 -o - 2>&1 | FileCheck %s --check-prefix=CHECK18
 
 //--- do_loop_with_cycle_goto.f90
 
@@ -15,6 +29,7 @@ subroutine do_loop_with_cycle_goto()
   ! Do loop with cycle and goto - unstructured control flow is not converted.
   ! The loop is directly attached to the `acc kernels` directive, so it is not
   ! wrapped in an scf.execute_region either.
+  ! CHECK2: {{.*}}do_loop_with_cycle_goto.f90":[[@LINE+2]]:3){{.*}}not yet implemented: unstructured do loop in acc kernels
   !$acc kernels
   do i = 1, n
     if (i == 3) cycle
@@ -25,7 +40,6 @@ subroutine do_loop_with_cycle_goto()
 200 continue
   !$acc end kernels
 
-! CHECK2: not yet implemented: unstructured do loop in acc kernels
 
 end subroutine
 
@@ -37,6 +51,7 @@ subroutine nested_goto_loop()
   real, dimension(n,m) :: a, b
 
   ! Nested loop with goto from inner to outer - should NOT convert to acc.loop
+  ! CHECK3: {{.*}}nested_goto_loop.f90":[[@LINE+2]]:3){{.*}}not yet implemented: unstructured do loop in acc kernels
   !$acc kernels
   do i = 1, n
     do j = 1, m
@@ -47,7 +62,6 @@ subroutine nested_goto_loop()
 300 continue
   !$acc end kernels
 
-! CHECK3: not yet implemented: unstructured do loop in acc kernels
 
 end subroutine
 
@@ -57,11 +71,11 @@ subroutine nested_goto_loop()
 subroutine combined(i, j, k)
   integer :: i, j, k
   integer :: a(i,j,k)
+  ! CHECK7: {{.*}}collapse_lt.f90":[[@LINE+1]]:9){{.*}}not yet implemented: OpenACC LOOP COLLAPSE less than DO CONCURRENT control count
   !$acc parallel loop collapse(2)
   do concurrent (i=1:10, j=1:100, k=1:200)
     a(i,j,k) = a(i,j,k) + 1
   end do
-  ! CHECK7: not yet implemented: OpenACC LOOP COLLAPSE less than DO CONCURRENT control count
 end subroutine
 
 //--- collapse_gt.f90
@@ -71,13 +85,13 @@ subroutine combined(i, j, k)
 subroutine combined(i, j, k)
   integer :: i, j, k
   integer :: a(i,j,k)
+  ! CHECK8: {{.*}}collapse_gt.f90":[[@LINE+1]]:9){{.*}}not yet implemented: OpenACC LOOP COLLAPSE greater than DO CONCURRENT control count
   !$acc parallel loop collapse(3)
   do concurrent (i=1:10, j=1:100)
     do k = 1, 200
       a(i,j,k) = a(i,j,k) + 1
     end do
   end do
-  ! CHECK8: not yet implemented: OpenACC LOOP COLLAPSE greater than DO CONCURRENT control count
 end subroutine
 
 //--- collapse_nested.f90
@@ -88,10 +102,279 @@ subroutine combined(i, j, k)
   integer :: a(i,j,k)
   !$acc parallel loop collapse(3)
   do i = 1, 10
+    ! CHECK6: {{.*}}collapse_nested.f90":[[@LINE+1]]:5){{.*}}not yet implemented: OpenACC LOOP with nested DO CONCURRENT
     do concurrent (j=1:100, k=1:200)
       a(i,j,k) = a(i,j,k) + 1
     end do
   end do
-  ! CHECK6: not yet implemented: OpenACC LOOP with nested DO CONCURRENT
+
+end subroutine
+
+//--- seq_exit_in_if.f90
+
+! A seq loop with an early EXIT inside an IF in the kernels region. The IF
+! holding the `acc loop` construct stays unstructured, so the seq loop is not
+! contained.
+subroutine seq_exit_in_if(m, b, kfirst, c)
+  integer :: m, kfirst
+  real :: b(m)
+  logical :: c
+  integer :: k
+  !$acc kernels
+  kfirst = 0
+  if (c) then
+    ! Lowering stops at the seq loop's `!` DO over k. The IF around the seq
+    ! loop's `acc loop` construct is unstructured and is not the kernels
+    ! construct.
+    ! CHECK12: {{.*}}seq_exit_in_if.f90":[[@LINE+2]]:5){{.*}}not yet implemented: unstructured do loop in acc kernels
+    !$acc loop seq
+    do k = 1, m
+      if (b(k) > 0.0) then
+        kfirst = k
+        exit
+      end if
+    end do
+  end if
+  !$acc end kernels
+
+! PFT12-LABEL: Subroutine seq_exit_in_if
+! PFT12:         <<OpenACCConstruct>>
+! PFT12:           <<IfConstruct!>>
+! PFT12:             <<^OpenACCConstruct!>>
+! PFT12:               <<DoConstruct!>>
+! PFT12:                 NonLabelDoStmt {{.*}}: do k = 1, m
+! PFT12:                   ExitStmt! {{.*}}: exit
+! PFT12:               <<End DoConstruct!>>
+! PFT12:             <<End OpenACCConstruct!>>
+! PFT12:           <<End IfConstruct!>>
+! PFT12:         <<End OpenACCConstruct>>
+
+
+end subroutine
+
+//--- seq_exit_in_select_case.f90
+
+! A seq loop with an early EXIT inside a SELECT CASE in the kernels region.
+subroutine seq_exit_in_select_case(m, b, kfirst, s)
+  integer :: m, kfirst
+  real :: b(m)
+  integer :: s
+  integer :: k
+  !$acc kernels
+  kfirst = 0
+  select case (s)
+  case (1)
+    ! Lowering stops at the seq loop's `!` DO over k. The SELECT CASE around the
+    ! seq loop's `acc loop` construct is unstructured and is not the kernels
+    ! construct.
+    ! CHECK13: {{.*}}seq_exit_in_select_case.f90":[[@LINE+2]]:5){{.*}}not yet implemented: unstructured do loop in acc kernels
+    !$acc loop seq
+    do k = 1, m
+      if (b(k) > 0.0) then
+        kfirst = k
+        exit
+      end if
+    end do
+  end select
+  !$acc end kernels
+
+! PFT13-LABEL: Subroutine seq_exit_in_select_case
+! PFT13:         <<OpenACCConstruct!>>
+! PFT13:           <<CaseConstruct!>>
+! PFT13:             <<OpenACCConstruct!>>
+! PFT13:               <<DoConstruct!>>
+! PFT13:                 NonLabelDoStmt {{.*}}: do k = 1, m
+! PFT13:                   ExitStmt! {{.*}}: exit
+! PFT13:               <<End DoConstruct!>>
+! PFT13:             <<End OpenACCConstruct!>>
+! PFT13:           <<End CaseConstruct!>>
+! PFT13:         <<End OpenACCConstruct!>>
+
+
+end subroutine
+
+//--- seq_exit_in_block.f90
+
+! A seq loop with an early EXIT inside a BLOCK construct in the kernels
+! region.
+subroutine seq_exit_in_block(m, b, kfirst)
+  integer :: m, kfirst
+  real :: b(m)
+  integer :: k
+  !$acc kernels
+  kfirst = 0
+  block
+    ! Lowering stops at the seq loop's `!` DO over k. The BLOCK around the seq
+    ! loop's `acc loop` construct is unstructured and is not the kernels
+    ! construct.
+    ! CHECK14: {{.*}}seq_exit_in_block.f90":[[@LINE+2]]:5){{.*}}not yet implemented: unstructured do loop in acc kernels
+    !$acc loop seq
+    do k = 1, m
+      if (b(k) > 0.0) then
+        kfirst = k
+        exit
+      end if
+    end do
+  end block
+  !$acc end kernels
+
+! PFT14-LABEL: Subroutine seq_exit_in_block
+! PFT14:         <<OpenACCConstruct!>>
+! PFT14:           <<BlockConstruct!>>
+! PFT14:             <<OpenACCConstruct!>>
+! PFT14:               <<DoConstruct!>>
+! PFT14:                 NonLabelDoStmt {{.*}}: do k = 1, m
+! PFT14:                   ExitStmt! {{.*}}: exit
+! PFT14:               <<End DoConstruct!>>
+! PFT14:             <<End OpenACCConstruct!>>
+! PFT14:           <<End BlockConstruct!>>
+! PFT14:         <<End OpenACCConstruct!>>
+
+
+end subroutine
+
+//--- seq_exit_in_do_while.f90
+
+! A seq loop with an early EXIT inside a DO WHILE in the kernels region. A DO
+! WHILE is never reclassified as structured with unstructured internals.
+subroutine seq_exit_in_do_while(n, m, b, kfirst)
+  integer :: m, kfirst
+  real :: b(m)
+  integer :: n, i
+  integer :: k
+  !$acc kernels
+  kfirst = 0
+  i = 0
+  do while (i < n)
+    i = i + 1
+    ! Lowering stops at the seq loop's `!` DO over k. The DO WHILE around the
+    ! seq loop's `acc loop` construct is unstructured and is not the kernels
+    ! construct.
+    ! CHECK15: {{.*}}seq_exit_in_do_while.f90":[[@LINE+2]]:5){{.*}}not yet implemented: unstructured do loop in acc kernels
+    !$acc loop seq
+    do k = 1, m
+      if (b(k) > 0.0) then
+        kfirst = k
+        exit
+      end if
+    end do
+  end do
+  !$acc end kernels
+
+! PFT15-LABEL: Subroutine seq_exit_in_do_while
+! PFT15:         <<OpenACCConstruct!>>
+! PFT15:           <<DoConstruct!>>
+! PFT15:             NonLabelDoStmt! {{.*}}: do while(i < n)
+! PFT15:             <<OpenACCConstruct!>>
+! PFT15:               <<DoConstruct!>>
+! PFT15:                 NonLabelDoStmt {{.*}}: do k = 1, m
+! PFT15:                   ExitStmt! {{.*}}: exit
+! PFT15:               <<End DoConstruct!>>
+! PFT15:             <<End OpenACCConstruct!>>
+! PFT15:           <<End DoConstruct!>>
+! PFT15:         <<End OpenACCConstruct!>>
+
+
+end subroutine
+
+//--- seq_exit_device_type_seq.f90
+
+! A loop with an early EXIT in the kernels region that is seq only for one
+! device_type. For the default device_type it is not seq.
+subroutine seq_exit_device_type_seq(m, b, kfirst)
+  integer :: m, kfirst
+  real :: b(m)
+  integer :: k
+  !$acc kernels
+  kfirst = 0
+  ! Lowering stops at the `!` DO over k: its acc.loop is not seq for the
+  ! default device_type.
+  ! CHECK16: {{.*}}seq_exit_device_type_seq.f90":[[@LINE+2]]:3){{.*}}not yet implemented: unstructured do loop in acc kernels
+  !$acc loop device_type(nvidia) seq
+  do k = 1, m
+    if (b(k) > 0.0) then
+      kfirst = k
+      exit
+    end if
+  end do
+  !$acc end kernels
+
+! PFT16-LABEL: Subroutine seq_exit_device_type_seq
+! PFT16:         <<OpenACCConstruct!>>
+! PFT16:           <<OpenACCConstruct!>>
+! PFT16:             <<DoConstruct!>>
+! PFT16:               NonLabelDoStmt {{.*}}: do k = 1, m
+! PFT16:                 ExitStmt! {{.*}}: exit
+! PFT16:             <<End DoConstruct!>>
+! PFT16:           <<End OpenACCConstruct!>>
+! PFT16:         <<End OpenACCConstruct!>>
+
+
+end subroutine
+
+//--- auto_exit_in_kernels.f90
+
+! An `acc loop auto` with an early EXIT in the kernels region.
+subroutine auto_exit_in_kernels(m, b, kfirst)
+  integer :: m, kfirst
+  real :: b(m)
+  integer :: k
+  !$acc kernels
+  kfirst = 0
+  ! Lowering stops at the `!` DO over k: its acc.loop is auto, not seq.
+  ! CHECK17: {{.*}}auto_exit_in_kernels.f90":[[@LINE+2]]:3){{.*}}not yet implemented: unstructured do loop in acc kernels
+  !$acc loop auto
+  do k = 1, m
+    if (b(k) > 0.0) then
+      kfirst = k
+      exit
+    end if
+  end do
+  !$acc end kernels
+
+! PFT17-LABEL: Subroutine auto_exit_in_kernels
+! PFT17:         <<OpenACCConstruct!>>
+! PFT17:           <<OpenACCConstruct!>>
+! PFT17:             <<DoConstruct!>>
+! PFT17:               NonLabelDoStmt {{.*}}: do k = 1, m
+! PFT17:                 ExitStmt! {{.*}}: exit
+! PFT17:             <<End DoConstruct!>>
+! PFT17:           <<End OpenACCConstruct!>>
+! PFT17:         <<End OpenACCConstruct!>>
+
+
+end subroutine
+
+//--- loop_exit_in_kernels.f90
+
+! An `acc loop` without a parallelism clause, with an early EXIT, in the
+! kernels region. In kernels it is treated as auto.
+subroutine loop_exit_in_kernels(m, b, kfirst)
+  integer :: m, kfirst
+  real :: b(m)
+  integer :: k
+  !$acc kernels
+  kfirst = 0
+  ! Lowering stops at the `!` DO over k: its acc.loop is auto, not seq.
+  ! CHECK18: {{.*}}loop_exit_in_kernels.f90":[[@LINE+2]]:3){{.*}}not yet implemented: unstructured do loop in acc kernels
+  !$acc loop
+  do k = 1, m
+    if (b(k) > 0.0) then
+      kfirst = k
+      exit
+    end if
+  end do
+  !$acc end kernels
+
+! PFT18-LABEL: Subroutine loop_exit_in_kernels
+! PFT18:         <<OpenACCConstruct!>>
+! PFT18:           <<OpenACCConstruct!>>
+! PFT18:             <<DoConstruct!>>
+! PFT18:               NonLabelDoStmt {{.*}}: do k = 1, m
+! PFT18:                 ExitStmt! {{.*}}: exit
+! PFT18:             <<End DoConstruct!>>
+! PFT18:           <<End OpenACCConstruct!>>
+! PFT18:         <<End OpenACCConstruct!>>
+
 
 end subroutine



More information about the llvm-branch-commits mailing list