[flang-commits] [flang] c0d731e - [flang][OpenACC] add TODO for unstructured loops in acc loop directives (#163972)

via flang-commits flang-commits at lists.llvm.org
Mon Oct 20 06:48:59 PDT 2025


Author: jeanPerier
Date: 2025-10-20T15:48:56+02:00
New Revision: c0d731e7594a89cc49b00155ca4917c2d90db241

URL: https://github.com/llvm/llvm-project/commit/c0d731e7594a89cc49b00155ca4917c2d90db241
DIFF: https://github.com/llvm/llvm-project/commit/c0d731e7594a89cc49b00155ca4917c2d90db241.diff

LOG: [flang][OpenACC] add TODO for unstructured loops in acc loop directives (#163972)

The lowering of `!$acc loop` loops with an early exit currently ends-up
"duplicating" the control flow in the acc.loop and inside it as explicit
control flow (as if each iteration executes each iteration until the
early exit).

Add a TODO for now.

Added: 
    

Modified: 
    flang/lib/Lower/OpenACC.cpp
    flang/test/Lower/OpenACC/acc-unstructured.f90

Removed: 
    


################################################################################
diff  --git a/flang/lib/Lower/OpenACC.cpp b/flang/lib/Lower/OpenACC.cpp
index 77a5716ab9c04..5670978a3d106 100644
--- a/flang/lib/Lower/OpenACC.cpp
+++ b/flang/lib/Lower/OpenACC.cpp
@@ -2717,12 +2717,19 @@ genACC(Fortran::lower::AbstractConverter &converter,
   const auto &loopDirective =
       std::get<Fortran::parser::AccLoopDirective>(beginLoopDirective.t);
 
+  mlir::Location currentLocation =
+      converter.genLocation(beginLoopDirective.source);
   bool needEarlyExitHandling = false;
-  if (eval.lowerAsUnstructured())
+  if (eval.lowerAsUnstructured()) {
     needEarlyExitHandling = hasEarlyReturn(eval);
+    // If the loop is lowered in an unstructured fashion, lowering generates
+    // explicit control flow that duplicates the looping semantics of the
+    // loops.
+    if (!needEarlyExitHandling)
+      TODO(currentLocation,
+           "loop with early exit inside OpenACC loop construct");
+  }
 
-  mlir::Location currentLocation =
-      converter.genLocation(beginLoopDirective.source);
   Fortran::lower::StatementContext stmtCtx;
 
   assert(loopDirective.v == llvm::acc::ACCD_loop &&
@@ -3521,6 +3528,10 @@ genACC(Fortran::lower::AbstractConverter &converter,
       converter.genLocation(beginCombinedDirective.source);
   Fortran::lower::StatementContext stmtCtx;
 
+  if (eval.lowerAsUnstructured())
+    TODO(currentLocation,
+         "loop with early exit inside OpenACC combined construct");
+
   if (combinedDirective.v == llvm::acc::ACCD_kernels_loop) {
     createComputeOp<mlir::acc::KernelsOp>(
         converter, currentLocation, eval, semanticsContext, stmtCtx,

diff  --git a/flang/test/Lower/OpenACC/acc-unstructured.f90 b/flang/test/Lower/OpenACC/acc-unstructured.f90
index c57af98770cf5..c42c7dddc5ca1 100644
--- a/flang/test/Lower/OpenACC/acc-unstructured.f90
+++ b/flang/test/Lower/OpenACC/acc-unstructured.f90
@@ -1,4 +1,5 @@
 ! RUN: bbc -fopenacc -emit-hlfir %s -o - | FileCheck %s
+! XFAIL: *
 
 subroutine test_unstructured1(a, b, c)
   integer :: i, j, k


        


More information about the flang-commits mailing list