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

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


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

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)

>From 42e2bae362f72657cfbe248088a8aa66b70e19d6 Mon Sep 17 00:00:00 2001
From: Chandra Ghale <ghale at pe34genoa.hpc.amslabs.hpecorp.net>
Date: Fri, 24 Apr 2026 07:31:44 -0500
Subject: [PATCH] Fix crash lowering parallel do with nested tile construct

---
 flang/lib/Lower/OpenMP/Utils.cpp             | 10 ++++++---
 flang/test/Lower/OpenMP/tile-parallel-do.f90 | 22 ++++++++++++++++++++
 2 files changed, 29 insertions(+), 3 deletions(-)
 create mode 100644 flang/test/Lower/OpenMP/tile-parallel-do.f90

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)
+



More information about the flang-commits mailing list