diff --git a/flang/lib/Lower/OpenMP/OpenMP.cpp b/flang/lib/Lower/OpenMP/OpenMP.cpp index 329cbf3d7539f..4f9e2347308aa 100644 --- a/flang/lib/Lower/OpenMP/OpenMP.cpp +++ b/flang/lib/Lower/OpenMP/OpenMP.cpp @@ -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 iv; genLoopNestClauses(converter, semaCtx, eval, simdItem->clauses, loc, @@ -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(converter, loc, simdClauseOps, simdArgs); simdOp.setComposite(/*val=*/true); @@ -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, @@ -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(converter, loc, simdClauseOps, simdArgs); simdOp.setComposite(/*val=*/true); diff --git a/flang/test/Lower/OpenMP/wsloop-simd.f90 b/flang/test/Lower/OpenMP/wsloop-simd.f90 index 899ab59714f14..49a9a523e11fe 100644 --- a/flang/test/Lower/OpenMP/wsloop-simd.f90 +++ b/flang/test/Lower/OpenMP/wsloop-simd.f90 @@ -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) + ! CHECK-NEXT: omp.simd + ! CHECK-SAME: reduction(@[[RED_SYM]] %[[RED_OUTER]] -> %[[RED_INNER:.*]] : !fir.ref) + ! CHECK-NEXT: omp.loop_nest + ! CHECK: %[[RED_DECL:.*]]:2 = hlfir.declare %[[RED_INNER]] + ! CHECK: %[[RED:.*]] = fir.load %[[RED_DECL]]#0 : !fir.ref + ! CHECK: %[[RESULT:.*]] = arith.addi %[[RED]], %{{.*}} : i32 + ! CHECK: hlfir.assign %[[RESULT]] to %[[RED_DECL]]#0 : i32, !fir.ref + ! 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