Skip to content

Revert "[Flang][OpenMP] Disable lowering of omp.simd reductions in co… #113683

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 6 additions & 14 deletions flang/lib/Lower/OpenMP/OpenMP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2246,12 +2246,6 @@ static void genCompositeDistributeParallelDoSimd(
genSimdClauses(converter, semaCtx, simdItem->clauses, loc, simdClauseOps,
simdReductionSyms);

// TODO: Remove this after omp.simd reductions on composite constructs are
// supported.
simdClauseOps.reductionVars.clear();
simdClauseOps.reductionByref.clear();
simdClauseOps.reductionSyms.clear();

mlir::omp::LoopNestOperands loopNestClauseOps;
llvm::SmallVector<const semantics::Symbol *> iv;
genLoopNestClauses(converter, semaCtx, eval, simdItem->clauses, loc,
Expand All @@ -2273,7 +2267,9 @@ static void genCompositeDistributeParallelDoSimd(
wsloopOp.setComposite(/*val=*/true);

EntryBlockArgs simdArgs;
// TODO: Add private and reduction syms and vars.
// TODO: Add private syms and vars.
simdArgs.reduction.syms = simdReductionSyms;
simdArgs.reduction.vars = simdClauseOps.reductionVars;
auto simdOp =
genWrapperOp<mlir::omp::SimdOp>(converter, loc, simdClauseOps, simdArgs);
simdOp.setComposite(/*val=*/true);
Expand Down Expand Up @@ -2366,12 +2362,6 @@ static void genCompositeDoSimd(lower::AbstractConverter &converter,
genSimdClauses(converter, semaCtx, simdItem->clauses, loc, simdClauseOps,
simdReductionSyms);

// TODO: Remove this after omp.simd reductions on composite constructs are
// supported.
simdClauseOps.reductionVars.clear();
simdClauseOps.reductionByref.clear();
simdClauseOps.reductionSyms.clear();

// TODO: Support delayed privatization.
DataSharingProcessor dsp(converter, semaCtx, simdItem->clauses, eval,
/*shouldCollectPreDeterminedSymbols=*/true,
Expand All @@ -2395,7 +2385,9 @@ static void genCompositeDoSimd(lower::AbstractConverter &converter,
wsloopOp.setComposite(/*val=*/true);

EntryBlockArgs simdArgs;
// TODO: Add private and reduction syms and vars.
// TODO: Add private syms and vars.
simdArgs.reduction.syms = simdReductionSyms;
simdArgs.reduction.vars = simdClauseOps.reductionVars;
auto simdOp =
genWrapperOp<mlir::omp::SimdOp>(converter, loc, simdClauseOps, simdArgs);
simdOp.setComposite(/*val=*/true);
Expand Down
21 changes: 21 additions & 0 deletions flang/test/Lower/OpenMP/wsloop-simd.f90
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,24 @@ subroutine do_simd_simdlen()
end do
!$omp end do simd
end subroutine do_simd_simdlen

! CHECK-LABEL: func.func @_QPdo_simd_reduction(
subroutine do_simd_reduction()
integer :: sum
sum = 0
! CHECK: omp.wsloop
! CHECK-SAME: reduction(@[[RED_SYM:.*]] %{{.*}} -> %[[RED_OUTER:.*]] : !fir.ref<i32>)
! CHECK-NEXT: omp.simd
! CHECK-SAME: reduction(@[[RED_SYM]] %[[RED_OUTER]] -> %[[RED_INNER:.*]] : !fir.ref<i32>)
! CHECK-NEXT: omp.loop_nest
! CHECK: %[[RED_DECL:.*]]:2 = hlfir.declare %[[RED_INNER]]
! CHECK: %[[RED:.*]] = fir.load %[[RED_DECL]]#0 : !fir.ref<i32>
! CHECK: %[[RESULT:.*]] = arith.addi %[[RED]], %{{.*}} : i32
! CHECK: hlfir.assign %[[RESULT]] to %[[RED_DECL]]#0 : i32, !fir.ref<i32>
! CHECK-NEXT: omp.yield
!$omp do simd reduction(+:sum)
do index_ = 1, 10
sum = sum + 1
end do
!$omp end do simd
end subroutine do_simd_reduction
Loading