Skip to content

Commit

Permalink
[flang][stack-arrays] Collect analysis results for OMP ws loops (llvm…
Browse files Browse the repository at this point in the history
…#103590)

We missed collecting the analysis results for regions terminated with
`omp.yield`. This result in missing some opportunities for malloc
optimizations inside omp regions.
  • Loading branch information
ergawy committed Aug 19, 2024
1 parent d2b3307 commit 4ddc994
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
2 changes: 2 additions & 0 deletions flang/lib/Optimizer/Transforms/StackArrays.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -457,10 +457,12 @@ StackArraysAnalysisWrapper::analyseFunction(mlir::Operation *func) {
if (lattice)
(void)point.join(*lattice);
};

func->walk([&](mlir::func::ReturnOp child) { joinOperationLattice(child); });
func->walk([&](fir::UnreachableOp child) { joinOperationLattice(child); });
func->walk(
[&](mlir::omp::TerminatorOp child) { joinOperationLattice(child); });
func->walk([&](mlir::omp::YieldOp child) { joinOperationLattice(child); });

llvm::DenseSet<mlir::Value> freedValues;
point.appendFreedValues(freedValues);
Expand Down
28 changes: 28 additions & 0 deletions flang/test/Transforms/stack-arrays-hlfir.f90
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,31 @@ end subroutine omp_temp_array
! CHECK-NEXT: }
! CHECK: return
! CHECK-NEXT: }

subroutine omp_target_wsloop
implicit none
integer (8) :: lV, i
integer (8), dimension (2) :: iaVS

lV = 202

!$omp target teams distribute
do i = 1, 10
iaVS = [lV, lV]
end do
!$omp end target teams distribute
end subroutine omp_target_wsloop
! CHECK-LABEL: func.func @_QPomp_target_wsloop{{.*}} {
! CHECK: omp.target {{.*}} {
! CHECK-NOT: fir.allocmem
! CHECK-NOT: fir.freemem
! CHECK: fir.alloca !fir.array<2xi64>
! CHECK: omp.teams {
! CHECK: omp.distribute {
! CHECK: omp.loop_nest {{.*}} {
! CHECK-NOT: fir.allocmem
! CHECK-NOT: fir.freemem
! CHECK: omp.yield
! CHECK-NEXT: }
! CHECK: return
! CHECK-NEXT: }

0 comments on commit 4ddc994

Please sign in to comment.