[flang-commits] [flang] [Flang][OpenMP] Fix crash lowering parallel do with nested tile construct (PR #193955)

via flang-commits flang-commits at lists.llvm.org
Fri Apr 24 05:35:55 PDT 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-flang-openmp

Author: CHANDRA GHALE (chandraghale)

<details>
<summary>Changes</summary>

This fixes a crash in OpenMP lowering for cases like `!$omp parallel do with nested !$omp tile sizes(...)` .
The loop-walk logic now correctly steps through intermediate OpenMP transformation wrappers to find the actual do construct, instead of assuming it is directly nested.

Fixes :  [https://github.com/llvm/llvm-project/issues/193256](https://github.com/llvm/llvm-project/issues/193256) 
sample reproducer : [https://godbolt.org/z/b7zecYEMT](https://godbolt.org/z/b7zecYEMT)

---
Full diff: https://github.com/llvm/llvm-project/pull/193955.diff


2 Files Affected:

- (modified) flang/lib/Lower/OpenMP/Utils.cpp (+7-3) 
- (added) flang/test/Lower/OpenMP/tile-parallel-do.f90 (+22) 


``````````diff
diff --git a/flang/lib/Lower/OpenMP/Utils.cpp b/flang/lib/Lower/OpenMP/Utils.cpp
index b7d1cb8b419fd..d65663dbebc53 100644
--- a/flang/lib/Lower/OpenMP/Utils.cpp
+++ b/flang/lib/Lower/OpenMP/Utils.cpp
@@ -702,9 +702,13 @@ pft::Evaluation *getNestedDoConstruct(pft::Evaluation &eval) {
     //     <<DoConstruct>> -> 7
     if (nested.getIf<parser::NonLabelDoStmt>())
       continue;
-    assert(nested.getIf<parser::DoConstruct>() &&
-           "Unexpected construct in the nested evaluations");
-    return &nested;
+    if (nested.getIf<parser::DoConstruct>())
+      return &nested;
+    // Loop transformations can introduce nested OpenMP
+    // constructs between the directive and the actual do-loop nest.
+    if (nested.getIf<parser::OpenMPConstruct>())
+      return getNestedDoConstruct(nested);
+    assert(false && "Unexpected construct in the nested evaluations");
   }
   llvm_unreachable("Expected do loop to be in the nested evaluations");
 }
diff --git a/flang/test/Lower/OpenMP/tile-parallel-do.f90 b/flang/test/Lower/OpenMP/tile-parallel-do.f90
new file mode 100644
index 0000000000000..e3d4f9f1e9e3a
--- /dev/null
+++ b/flang/test/Lower/OpenMP/tile-parallel-do.f90
@@ -0,0 +1,22 @@
+! RUN: %flang_fc1 -emit-hlfir -fopenmp -fopenmp-version=51 -o - %s | FileCheck %s
+
+subroutine func7(a)
+  implicit none
+  double precision :: a(100, 100)
+  integer :: i, j
+
+  !$omp parallel do
+  !$omp tile sizes(4, 16)
+  do i = 1, 100
+    do j = 1, 100
+      a(j, i) = a(j, i) + 1.0d0
+    end do
+  end do
+end subroutine
+
+! CHECK-LABEL: func.func @_QPfunc7(
+! CHECK: omp.parallel
+! CHECK: omp.wsloop
+! CHECK: omp.loop_nest
+! CHECK-SAME: tiles(4, 16)
+

``````````

</details>


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


More information about the flang-commits mailing list