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

A DO loop whose raw branching is confined to its body keeps its structured
form, with only the body folded into an scf.execute_region. Only increment
loops qualified. A do concurrent header puts no control flow in the body
either: its indices are always integer and its mask is a test inside the
innermost loop. So a do concurrent qualifies under the same body checks.

This lets a do concurrent with, for example, a SELECT CASE in its body lower
inside an OpenACC kernels region instead of hitting the "unstructured do loop
in acc kernels" TODO.

The tests cover a do concurrent that keeps its structured form with a SELECT
CASE in its body, a mask over two indices, a CYCLE, a locality specifier, an
EXIT of a BLOCK, and an EXIT of an inner DO, and the same loop under OpenACC
parallel loop and kernels. They also cover the shapes that stay unstructured:
a GOTO back to an earlier statement of the body, and an infinite DO in the
body. do_concurrent.f90 also checks the old lowering with
--wrap-unstructured-constructs-in-execute-region=false.


>From 9b196b799447c811593c07e7544e24384df34dcd Mon Sep 17 00:00:00 2001
From: ergawy <[email protected]>
Date: Thu, 19 Nov 2026 02:41:18 -0800
Subject: [PATCH] [flang] Keep do concurrent structured when its branching
 stays in the body

A DO loop whose raw branching is confined to its body keeps its structured
form, with only the body folded into an scf.execute_region. Only increment
loops qualified. A do concurrent header puts no control flow in the body
either: its indices are always integer and its mask is a test inside the
innermost loop. So a do concurrent qualifies under the same body checks.

This lets a do concurrent with, for example, a SELECT CASE in its body lower
inside an OpenACC kernels region instead of hitting the "unstructured do loop
in acc kernels" TODO.
---
 flang/lib/Lower/PFTBuilder.cpp                |  42 ++--
 .../OpenACC/acc-directive-loop-bounds.f90     |  65 ++++++
 .../do-concurrent-unstructured-internals.f90  | 214 ++++++++++++++++++
 flang/test/Lower/do_concurrent.f90            |  88 ++++---
 flang/test/Lower/do_loop_unstructured.f90     |  21 +-
 flang/test/Lower/loops.f90                    |   8 +-
 6 files changed, 377 insertions(+), 61 deletions(-)
 create mode 100644 flang/test/Lower/do-concurrent-unstructured-internals.f90

diff --git a/flang/lib/Lower/PFTBuilder.cpp b/flang/lib/Lower/PFTBuilder.cpp
index b2915fcc0800f7..6498c520d24207 100644
--- a/flang/lib/Lower/PFTBuilder.cpp
+++ b/flang/lib/Lower/PFTBuilder.cpp
@@ -2924,10 +2924,10 @@ static bool isStructurableWithUnstructuredInternals(
       loop.evaluationList->size() < 3)
     return false;
 
-  // Only an increment loop keeps all of its control outside the body. A DO
-  // WHILE or an infinite DO lowers through a header block and a back edge, and
-  // a do concurrent has no plain bounds triple either, so in each case the
-  // loop's own control flow runs through the body a wrap would cover.
+  // Only an increment loop or a do concurrent keeps all of its control outside
+  // the body. A DO WHILE or an infinite DO lowers through a header block and a
+  // back edge, so the loop's own control flow runs through the body a wrap
+  // would cover.
   const auto *doConstruct = loop.getIf<parser::DoConstruct>();
   if (!doConstruct)
     return false;
@@ -2936,22 +2936,28 @@ static bool isStructurableWithUnstructuredInternals(
   if (!loopControl)
     return false;
 
-  const auto *bounds =
-      std::get_if<parser::LoopControl::Bounds>(&loopControl->u);
-  if (!bounds)
-    return false;
+  // A do concurrent header puts no control flow in the body: its indices are
+  // always integer, and its mask is a test inside the innermost loop. The body
+  // checks below still apply.
+  if (!std::holds_alternative<parser::LoopControl::Concurrent>(
+          loopControl->u)) {
+    const auto *bounds =
+        std::get_if<parser::LoopControl::Bounds>(&loopControl->u);
+    if (!bounds)
+      return false;
 
-  // A REAL control variable does not lower to fir.do_loop, whose induction
-  // variable must be a signless integer or index, so such a loop is lowered as
-  // unstructured whatever its body looks like.
-  const semantics::Symbol *ctrlVar = bounds->Name().thing.symbol;
-  if (!ctrlVar)
-    return false;
+    // A REAL control variable does not lower to fir.do_loop, whose induction
+    // variable must be a signless integer or index, so such a loop is lowered
+    // as unstructured whatever its body looks like.
+    const semantics::Symbol *ctrlVar = bounds->Name().thing.symbol;
+    if (!ctrlVar)
+      return false;
 
-  const semantics::DeclTypeSpec *ctrlType = ctrlVar->GetType();
-  if (!ctrlType || ctrlType->category() != semantics::DeclTypeSpec::Numeric ||
-      ctrlType->numericTypeSpec().category() != common::TypeCategory::Integer)
-    return false;
+    const semantics::DeclTypeSpec *ctrlType = ctrlVar->GetType();
+    if (!ctrlType || ctrlType->category() != semantics::DeclTypeSpec::Numeric 
||
+        ctrlType->numericTypeSpec().category() != 
common::TypeCategory::Integer)
+      return false;
+  }
 
   const Fortran::lower::pft::Evaluation *endDoStmt =
       &loop.evaluationList->back();
diff --git a/flang/test/Lower/OpenACC/acc-directive-loop-bounds.f90 
b/flang/test/Lower/OpenACC/acc-directive-loop-bounds.f90
index edc1b2c0e54e3b..a6664077b9756a 100644
--- a/flang/test/Lower/OpenACC/acc-directive-loop-bounds.f90
+++ b/flang/test/Lower/OpenACC/acc-directive-loop-bounds.f90
@@ -64,3 +64,68 @@ subroutine parallel_region_goto(a, n)
 ! CHECK: Subroutine parallel_region_goto
 ! CHECK: <<OpenACCConstruct!>>
 ! CHECK: GotoStmt!
+
+! A do concurrent with a SELECT CASE in its body keeps its structured form too,
+! so the directive's acc.loop carries the bounds.
+subroutine parallel_loop_do_concurrent(a, n, tag)
+  real :: a(n)
+  integer :: n, i, tag
+  !$acc parallel loop
+  do concurrent (i = 1:n)
+    select case (tag)
+    case (1)
+      a(i) = 1.0
+    case default
+      a(i) = 0.0
+    end select
+  end do
+end subroutine
+
+! CHECK: Subroutine parallel_loop_do_concurrent
+! CHECK: <<OpenACCConstruct~>>
+! CHECK: <<DoConstruct~>>
+
+! FIR-LABEL: func.func @_QPparallel_loop_do_concurrent
+! FIR:         acc.parallel combined(loop) {
+! FIR-NOT:       acc.loop
+! FIR:           acc.loop combined(parallel) private({{.*}}) control(%{{.*}} : 
i32) = (%{{.*}} : i32) to (%{{.*}} : i32) step (%{{.*}} : i32) {
+! FIR:             scf.execute_region no_inline {
+! FIR:               fir.select_case
+! FIR:               scf.yield
+! FIR:             }
+! FIR-NOT:       acc.loop
+! FIR:           acc.yield
+! FIR:         }
+
+! The same do concurrent directly in a kernels region gets the implicit 
acc.loop
+! with bounds, instead of being reported as an unstructured DO.
+subroutine kernels_do_concurrent(a, n, tag)
+  real :: a(n)
+  integer :: n, i, tag
+  !$acc kernels
+  do concurrent (i = 1:n)
+    select case (tag)
+    case (1)
+      a(i) = 1.0
+    case default
+      a(i) = 0.0
+    end select
+  end do
+  !$acc end kernels
+end subroutine
+
+! CHECK: Subroutine kernels_do_concurrent
+! CHECK: <<OpenACCConstruct~>>
+! CHECK: <<DoConstruct~>>
+
+! FIR-LABEL: func.func @_QPkernels_do_concurrent
+! FIR:         acc.kernels {
+! FIR-NOT:       acc.loop
+! FIR:           acc.loop private({{.*}}) control(%{{.*}} : i32) = (%{{.*}} : 
i32) to (%{{.*}} : i32) step (%{{.*}} : i32) {
+! FIR:             scf.execute_region no_inline {
+! FIR:               fir.select_case
+! FIR:               scf.yield
+! FIR:             }
+! FIR-NOT:       acc.loop
+! FIR:           acc.yield
+! FIR:         }
diff --git a/flang/test/Lower/do-concurrent-unstructured-internals.f90 
b/flang/test/Lower/do-concurrent-unstructured-internals.f90
new file mode 100644
index 00000000000000..17a897e0d226fd
--- /dev/null
+++ b/flang/test/Lower/do-concurrent-unstructured-internals.f90
@@ -0,0 +1,214 @@
+! A do concurrent whose branching is confined to its body keeps its structured
+! form: its header puts no control flow in the body, so only the body is folded
+! into an scf.execute_region. The body checks that apply to an increment loop
+! still apply.
+
+! RUN: %flang_fc1 -fdebug-dump-pft -o /dev/null %s 2>&1 | FileCheck %s
+! RUN: %flang_fc1 -emit-hlfir -o - %s | FileCheck %s --check-prefix=FIR
+
+! A SELECT CASE is lowered as raw branching, but its branches stay in the body.
+subroutine select_case(n, a, tag)
+  integer :: n, tag, i
+  real :: a(n)
+  do concurrent (i = 1:n)
+    select case (tag)
+    case (1)
+      a(i) = 1
+    case default
+      a(i) = 0
+    end select
+  end do
+end subroutine
+
+! CHECK-LABEL: Subroutine select_case
+! CHECK:   <<DoConstruct~>>
+! CHECK:     <<CaseConstruct!>>
+! CHECK:   <<End DoConstruct~>>
+
+! FIR-LABEL: func.func @_QPselect_case
+! FIR:         fir.do_concurrent {
+! FIR:           fir.do_concurrent.loop
+! FIR:             scf.execute_region no_inline {
+! FIR:               fir.select_case
+! FIR:               scf.yield
+! FIR:             }
+
+! Two indices and a mask: the mask stays a test around the wrapped body.
+subroutine mask_two_indices(n, a, tag)
+  integer :: n, tag, i, j
+  real :: a(n, n)
+  do concurrent (i = 1:n, j = 1:n, a(i, j) > 0.0)
+    select case (tag)
+    case (1)
+      a(i, j) = 1
+    case default
+      a(i, j) = 0
+    end select
+  end do
+end subroutine
+
+! CHECK-LABEL: Subroutine mask_two_indices
+! CHECK:   <<DoConstruct~>>
+! CHECK:   <<End DoConstruct~>>
+
+! FIR-LABEL: func.func @_QPmask_two_indices
+! FIR:         fir.do_concurrent {
+! FIR:           fir.do_concurrent.loop (%{{.*}}, %{{.*}}) =
+! FIR:             %[[MASK:.*]] = arith.cmpf ogt
+! FIR:             fir.if %[[MASK]] {
+! FIR:               scf.execute_region no_inline {
+! FIR:                 fir.select_case
+! FIR:                 scf.yield
+! FIR:               }
+
+! A CYCLE targets the EndDoStmt, so it does not escape the body.
+subroutine cycle_in_body(n, a, tag)
+  integer :: n, tag, i
+  real :: a(n)
+  do concurrent (i = 1:n)
+    select case (tag)
+    case (1)
+      cycle
+    case default
+      a(i) = 0
+    end select
+  end do
+end subroutine
+
+! CHECK-LABEL: Subroutine cycle_in_body
+! CHECK:   <<DoConstruct~>>
+! CHECK:   <<End DoConstruct~>>
+
+! FIR-LABEL: func.func @_QPcycle_in_body
+! FIR:         fir.do_concurrent.loop
+! FIR:           scf.execute_region no_inline {
+! FIR:             fir.select_case
+! FIR:             scf.yield
+! FIR:           }
+
+! A locality specifier does not change the classification.
+subroutine local_spec(n, a, tag)
+  integer :: n, tag, i
+  real :: a(n), t
+  do concurrent (i = 1:n) local(t)
+    select case (tag)
+    case (1)
+      t = 1
+    case default
+      t = 2
+    end select
+    a(i) = t
+  end do
+end subroutine
+
+! CHECK-LABEL: Subroutine local_spec
+! CHECK:   <<DoConstruct~>>
+! CHECK:   <<End DoConstruct~>>
+
+! FIR-LABEL: func.func @_QPlocal_spec
+! FIR:         fir.do_concurrent.loop {{.*}} local(
+! FIR:           scf.execute_region no_inline {
+! FIR:             fir.select_case
+! FIR:             scf.yield
+! FIR:           }
+
+! An EXIT of a BLOCK in the body stays in the body.
+subroutine exit_block(n, a)
+  integer :: n, i
+  real :: a(n)
+  do concurrent (i = 1:n)
+    b: block
+      if (a(i) < 0.0) exit b
+      a(i) = 1
+    end block b
+  end do
+end subroutine
+
+! CHECK-LABEL: Subroutine exit_block
+! CHECK:   <<DoConstruct~>>
+! CHECK:     <<BlockConstruct!>>
+! CHECK:   <<End DoConstruct~>>
+
+! FIR-LABEL: func.func @_QPexit_block
+! FIR:         fir.do_concurrent.loop
+! FIR:           scf.execute_region no_inline {
+! FIR:             cf.cond_br
+! FIR:             scf.yield
+! FIR:           }
+
+! An EXIT of an inner increment loop belongs to that loop. The inner loop
+! leaves the do concurrent structured, so the do concurrent needs no wrap.
+subroutine exit_inner_loop(n, a)
+  integer :: n, i, j
+  real :: a(n)
+  do concurrent (i = 1:n)
+    do j = 1, n
+      if (a(j) < 0.0) exit
+      a(i) = a(i) + 1
+    end do
+  end do
+end subroutine
+
+! CHECK-LABEL: Subroutine exit_inner_loop
+! CHECK:   <<DoConstruct>>
+! CHECK:     <<DoConstruct!>>
+! CHECK:     <<End DoConstruct!>>
+! CHECK:   <<End DoConstruct>>
+
+! FIR-LABEL: func.func @_QPexit_inner_loop
+! FIR:         fir.do_concurrent.loop
+! FIR:           scf.execute_region no_inline {
+! FIR:             cf.cond_br
+! FIR:             scf.yield
+! FIR:           }
+
+! A GOTO back to an earlier statement of the body may never let the body
+! complete, so the loop stays unstructured.
+subroutine goto_cycle_in_body(n, a)
+  integer :: n, i
+  real :: a(n)
+  do concurrent (i = 1:n)
+10  a(i) = a(i) + 1.0
+    if (a(i) < 5.0) goto 10
+  end do
+end subroutine
+
+! CHECK-LABEL: Subroutine goto_cycle_in_body
+! CHECK:   <<DoConstruct!>>
+! CHECK:   <<End DoConstruct!>>
+
+! The whole construct is folded into one region, with the loop control as raw
+! branches inside it.
+! FIR-LABEL: func.func @_QPgoto_cycle_in_body
+! FIR-NOT:     fir.do_concurrent
+! FIR:         scf.execute_region no_inline {
+! FIR-NOT:       fir.do_concurrent
+! FIR:           cf.cond_br
+! FIR:           scf.yield
+! FIR:         }
+
+! An infinite DO in the body cannot run to completion either.
+subroutine infinite_inner(n, a)
+  integer :: n, i
+  real :: a(n)
+  do concurrent (i = 1:n)
+    do
+      a(i) = a(i) + 1.0
+      if (a(i) > 5.0) exit
+    end do
+  end do
+end subroutine
+
+! CHECK-LABEL: Subroutine infinite_inner
+! CHECK:   <<DoConstruct!>>
+! CHECK:     <<DoConstruct!>>
+! CHECK:     <<End DoConstruct!>>
+! CHECK:   <<End DoConstruct!>>
+
+! The infinite DO is not wrappable, so the loop control stays raw branches in
+! the function body.
+! FIR-LABEL: func.func @_QPinfinite_inner
+! FIR-NOT:     fir.do_concurrent
+! FIR-NOT:     scf.execute_region
+! FIR:         cf.cond_br
+! FIR:         return
diff --git a/flang/test/Lower/do_concurrent.f90 
b/flang/test/Lower/do_concurrent.f90
index 99454c0e50b93c..a2353d00636eca 100644
--- a/flang/test/Lower/do_concurrent.f90
+++ b/flang/test/Lower/do_concurrent.f90
@@ -1,4 +1,5 @@
-! RUN: %flang_fc1 -emit-hlfir -o - %s | FileCheck %s
+! RUN: %flang_fc1 -emit-hlfir -o - %s | FileCheck %s 
--check-prefixes=CHECK,WRAP
+! RUN: %flang_fc1 -emit-hlfir -mmlir 
--wrap-unstructured-constructs-in-execute-region=false -o - %s | FileCheck %s 
--check-prefixes=CHECK,NOWRAP
 
 ! Simple tests for structured concurrent loops with loop-control.
 
@@ -86,39 +87,66 @@ subroutine sub2(n)
    end do
 end subroutine
 
+! The computed GOTO's targets are all inside the body, so the loop keeps its
+! structured form and only the body is folded into an scf.execute_region,
+! inside the mask test.
 !CHECK-LABEL: unstructured
 subroutine unstructured(inner_step)
   integer(4) :: i, j, inner_step
 
-!CHECK-NOT: cf.br
-!CHECK-NOT: cf.cond_br
-!CHECK:     %[[LB1:.*]] = arith.constant 1 : i32
-!CHECK:     %[[LB1_CVT:.*]] = fir.convert %c1_i32 : (i32) -> i16
-!CHECK:     %[[UB1:.*]] = arith.constant 5 : i32
-!CHECK:     %[[UB1_CVT:.*]] = fir.convert %c5_i32 : (i32) -> i16
-!CHECK:     %[[STP1:.*]] = arith.constant 1 : i16
-
-!CHECK-NOT: cf.br
-!CHECK-NOT: cf.cond_br
-!CHECK:     %[[LB2:.*]] = arith.constant 3 : i32
-!CHECK:     %[[LB2_CVT:.*]] = fir.convert %[[LB2]] : (i32) -> i16
-!CHECK:     %[[UB2:.*]] = arith.constant 9 : i32
-!CHECK:     %[[UB2_CVT:.*]] = fir.convert %[[UB2]] : (i32) -> i16
-!CHECK:     %[[STP2:.*]] = fir.load %{{.*}}#0 : !fir.ref<i32>
-!CHECK:     %[[STP2_CVT:.*]] = fir.convert %[[STP2]] : (i32) -> i16
-!CHECK:     fir.store %[[STP2_CVT]] to %{{.*}} : !fir.ref<i16>
-!CHECK:     cf.br ^[[I_LOOP_HEADER:.*]]
-
-!CHECK: ^[[I_LOOP_HEADER]]:
-!CHECK-NEXT: %{{.*}} = fir.load %{{.*}} : !fir.ref<i16>
-!CHECK-NEXT: %{{.*}} = arith.constant 0 : i16
-!CHECK-NEXT: %{{.*}} = arith.cmpi sgt, %{{.*}}, %{{.*}}: i16
-!CHECK-NEXT: cf.cond_br %{{.*}}, ^[[J_LOOP_HEADER:.*]], ^{{.*}}
-
-!CHECK: ^[[J_LOOP_HEADER]]:
-!CHECK-NEXT: %[[RANGE:.*]] = arith.subi %[[UB2_CVT]], %[[LB2_CVT]] : i16
-!CHECK-NEXT: %{{.*}} = arith.addi %[[RANGE]], %[[STP2_CVT]] : i16
-!CHECK-NEXT: %{{.*}} = arith.divsi %{{.*}}, %[[STP2_CVT]] : i16
+!WRAP:     %[[LB1:.*]] = arith.constant 1 : i32
+!WRAP:     %[[LB1_CVT:.*]] = fir.convert %[[LB1]] : (i32) -> index
+!WRAP:     %[[UB1:.*]] = arith.constant 5 : i32
+!WRAP:     %[[UB1_CVT:.*]] = fir.convert %[[UB1]] : (i32) -> index
+!WRAP:     %[[STP1:.*]] = arith.constant 1 : index
+!WRAP:     %[[LB2:.*]] = arith.constant 3 : i32
+!WRAP:     %[[LB2_CVT:.*]] = fir.convert %[[LB2]] : (i32) -> index
+!WRAP:     %[[UB2:.*]] = arith.constant 9 : i32
+!WRAP:     %[[UB2_CVT:.*]] = fir.convert %[[UB2]] : (i32) -> index
+!WRAP:     %[[STP2:.*]] = fir.load %{{.*}}#0 : !fir.ref<i32>
+!WRAP:     %[[STP2_CVT:.*]] = fir.convert %[[STP2]] : (i32) -> index
+!WRAP:     fir.do_concurrent {
+!WRAP:       fir.do_concurrent.loop (%{{.*}}, %{{.*}}) = (%[[LB1_CVT]], 
%[[LB2_CVT]]) to (%[[UB1_CVT]], %[[UB2_CVT]]) step (%[[STP1]], %[[STP2_CVT]]) {
+!WRAP:         %[[MASK:.*]] = arith.cmpi ne
+!WRAP:         fir.if %[[MASK]] {
+!WRAP:           scf.execute_region no_inline {
+!WRAP:             fir.select
+!WRAP:             scf.yield
+!WRAP:           }
+!WRAP:         }
+!WRAP:       }
+!WRAP:     }
+
+! With the wrap disabled, the loop is lowered as raw branches.
+!NOWRAP-NOT: cf.br
+!NOWRAP-NOT: cf.cond_br
+!NOWRAP:     %[[LB1:.*]] = arith.constant 1 : i32
+!NOWRAP:     %[[LB1_CVT:.*]] = fir.convert %c1_i32 : (i32) -> i16
+!NOWRAP:     %[[UB1:.*]] = arith.constant 5 : i32
+!NOWRAP:     %[[UB1_CVT:.*]] = fir.convert %c5_i32 : (i32) -> i16
+!NOWRAP:     %[[STP1:.*]] = arith.constant 1 : i16
+
+!NOWRAP-NOT: cf.br
+!NOWRAP-NOT: cf.cond_br
+!NOWRAP:     %[[LB2:.*]] = arith.constant 3 : i32
+!NOWRAP:     %[[LB2_CVT:.*]] = fir.convert %[[LB2]] : (i32) -> i16
+!NOWRAP:     %[[UB2:.*]] = arith.constant 9 : i32
+!NOWRAP:     %[[UB2_CVT:.*]] = fir.convert %[[UB2]] : (i32) -> i16
+!NOWRAP:     %[[STP2:.*]] = fir.load %{{.*}}#0 : !fir.ref<i32>
+!NOWRAP:     %[[STP2_CVT:.*]] = fir.convert %[[STP2]] : (i32) -> i16
+!NOWRAP:     fir.store %[[STP2_CVT]] to %{{.*}} : !fir.ref<i16>
+!NOWRAP:     cf.br ^[[I_LOOP_HEADER:.*]]
+
+!NOWRAP: ^[[I_LOOP_HEADER]]:
+!NOWRAP-NEXT: %{{.*}} = fir.load %{{.*}} : !fir.ref<i16>
+!NOWRAP-NEXT: %{{.*}} = arith.constant 0 : i16
+!NOWRAP-NEXT: %{{.*}} = arith.cmpi sgt, %{{.*}}, %{{.*}}: i16
+!NOWRAP-NEXT: cf.cond_br %{{.*}}, ^[[J_LOOP_HEADER:.*]], ^{{.*}}
+
+!NOWRAP: ^[[J_LOOP_HEADER]]:
+!NOWRAP-NEXT: %[[RANGE:.*]] = arith.subi %[[UB2_CVT]], %[[LB2_CVT]] : i16
+!NOWRAP-NEXT: %{{.*}} = arith.addi %[[RANGE]], %[[STP2_CVT]] : i16
+!NOWRAP-NEXT: %{{.*}} = arith.divsi %{{.*}}, %[[STP2_CVT]] : i16
   do concurrent (integer(2)::i=1:5, j=3:9:inner_step, i.ne.3)
     goto (7, 7) i+1
     print*, 'E:', i, j
diff --git a/flang/test/Lower/do_loop_unstructured.f90 
b/flang/test/Lower/do_loop_unstructured.f90
index e38c6ceda0f2be..51db47fbaf49ec 100644
--- a/flang/test/Lower/do_loop_unstructured.f90
+++ b/flang/test/Lower/do_loop_unstructured.f90
@@ -89,16 +89,15 @@ subroutine unstructured_do_concurrent
     error stop "fail"
   enddo
 end
+! The ERROR STOP stays in the body, so the loop keeps its structured form and
+! only the body is folded into a region.
 ! CHECK-LABEL: func.func @_QPunstructured_do_concurrent
-! CHECK:         %[[ITER_VAR:.*]] = fir.alloca i32
-! CHECK:         scf.execute_region no_inline {
-! CHECK:           cf.br ^[[HEADER:.*]]
-! CHECK:         ^[[HEADER]]:
-! CHECK:           %{{.*}} = fir.load %[[ITER_VAR]] : !fir.ref<i32>
-! CHECK:           cf.cond_br %{{.*}}, ^[[BODY:.*]], ^[[EXIT:.*]]
-! CHECK:         ^[[BODY]]:
-! CHECK-NEXT:      %{{.*}} = fir.alloca !fir.logical<4> <{bindc_name = 
"success", {{.*}}}>
-! CHECK:         ^[[EXIT]]:
-! CHECK-NEXT:      scf.yield
-! CHECK:         }
+! CHECK:         fir.do_concurrent {
+! CHECK:           fir.do_concurrent.loop (%{{.*}}) = (%{{.*}}) to (%{{.*}}) 
step (%{{.*}}) local(@{{.*}}success{{.*}}) {
+! CHECK:             scf.execute_region no_inline {
+! CHECK:               fir.call @_FortranAStopStatementText
+! CHECK-NEXT:          fir.unreachable
+! CHECK-NEXT:        }
+! CHECK-NEXT:      }
+! CHECK-NEXT:    }
 ! CHECK:         return
diff --git a/flang/test/Lower/loops.f90 b/flang/test/Lower/loops.f90
index 0c1dc9f5ae04d2..b1bdf9c11dbbe6 100644
--- a/flang/test/Lower/loops.f90
+++ b/flang/test/Lower/loops.f90
@@ -64,8 +64,12 @@ subroutine loop_test
   6 continue
   enddo
 
-  ! CHECK-NOT: fir.do_loop
-  ! CHECK-NOT: fir.if
+  ! The computed GOTO's targets are inside the body, so only the body is
+  ! folded into a region, inside the mask test.
+  ! CHECK: fir.do_concurrent.loop (%{{.*}}) = {{.*}}
+  ! CHECK: fir.if
+  ! CHECK: scf.execute_region no_inline {
+  ! CHECK: fir.select
   do concurrent (integer(2)::i=1:5, i.ne.3)
     goto (7, 7) i+1
     ! CHECK: fir.call @_FortranAioBeginExternalListOutput

_______________________________________________
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

Reply via email to