Unverified Commit 8116e869 authored by CHANDRA GHALE's avatar CHANDRA GHALE Committed by GitHub
Browse files

[Flang][OpenMP] Fix crash lowering parallel do with nested tile construct (#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)



Co-authored-by: default avatarChandra Ghale <ghale@pe34genoa.hpc.amslabs.hpecorp.net>
parent 889708ee
Loading
Loading
Loading
Loading
+7 −3
Original line number Diff line number Diff line
@@ -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");
    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");
}
+22 −0
Original line number Diff line number Diff line
! 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)