Skip to content

Commit 3d730dc

Browse files
authored
[flang][stack-arrays] Collect analysis results for OMP ws loops (llvm#103590) (llvm#145)
We missed collecting the analysis results for regions terminated with `omp.yield`. This result in missing some opportunities for malloc optimizations inside omp regions.
1 parent d2b3307 commit 3d730dc

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

flang/lib/Optimizer/Transforms/StackArrays.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,10 +457,12 @@ StackArraysAnalysisWrapper::analyseFunction(mlir::Operation *func) {
457457
if (lattice)
458458
(void)point.join(*lattice);
459459
};
460+
460461
func->walk([&](mlir::func::ReturnOp child) { joinOperationLattice(child); });
461462
func->walk([&](fir::UnreachableOp child) { joinOperationLattice(child); });
462463
func->walk(
463464
[&](mlir::omp::TerminatorOp child) { joinOperationLattice(child); });
465+
func->walk([&](mlir::omp::YieldOp child) { joinOperationLattice(child); });
464466

465467
llvm::DenseSet<mlir::Value> freedValues;
466468
point.appendFreedValues(freedValues);

flang/test/Transforms/stack-arrays-hlfir.f90

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,31 @@ end subroutine omp_temp_array
5353
! CHECK-NEXT: }
5454
! CHECK: return
5555
! CHECK-NEXT: }
56+
57+
subroutine omp_target_wsloop
58+
implicit none
59+
integer (8) :: lV, i
60+
integer (8), dimension (2) :: iaVS
61+
62+
lV = 202
63+
64+
!$omp target teams distribute
65+
do i = 1, 10
66+
iaVS = [lV, lV]
67+
end do
68+
!$omp end target teams distribute
69+
end subroutine omp_target_wsloop
70+
! CHECK-LABEL: func.func @_QPomp_target_wsloop{{.*}} {
71+
! CHECK: omp.target {{.*}} {
72+
! CHECK-NOT: fir.allocmem
73+
! CHECK-NOT: fir.freemem
74+
! CHECK: fir.alloca !fir.array<2xi64>
75+
! CHECK: omp.teams {
76+
! CHECK: omp.distribute {
77+
! CHECK: omp.loop_nest {{.*}} {
78+
! CHECK-NOT: fir.allocmem
79+
! CHECK-NOT: fir.freemem
80+
! CHECK: omp.yield
81+
! CHECK-NEXT: }
82+
! CHECK: return
83+
! CHECK-NEXT: }

0 commit comments

Comments
 (0)