Skip to content

Commit 32241ac

Browse files
committed
Revert "[Flang][OpenMP] Disable lowering of omp.simd reductions in composites (#112686)"
Lowering of reductions in composite operations can now be re-enabled, since previous commits in this PR stack fix the MLIR representation produced and it no longer triggers a compiler crash during translation to LLVM IR. This reverts commit c44860c.
1 parent b656553 commit 32241ac

File tree

2 files changed

+27
-14
lines changed

2 files changed

+27
-14
lines changed

flang/lib/Lower/OpenMP/OpenMP.cpp

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2237,12 +2237,6 @@ static void genCompositeDistributeParallelDoSimd(
22372237
genSimdClauses(converter, semaCtx, simdItem->clauses, loc, simdClauseOps,
22382238
simdReductionSyms);
22392239

2240-
// TODO: Remove this after omp.simd reductions on composite constructs are
2241-
// supported.
2242-
simdClauseOps.reductionVars.clear();
2243-
simdClauseOps.reductionByref.clear();
2244-
simdClauseOps.reductionSyms.clear();
2245-
22462240
mlir::omp::LoopNestOperands loopNestClauseOps;
22472241
llvm::SmallVector<const semantics::Symbol *> iv;
22482242
genLoopNestClauses(converter, semaCtx, eval, simdItem->clauses, loc,
@@ -2264,7 +2258,9 @@ static void genCompositeDistributeParallelDoSimd(
22642258
wsloopOp.setComposite(/*val=*/true);
22652259

22662260
EntryBlockArgs simdArgs;
2267-
// TODO: Add private and reduction syms and vars.
2261+
// TODO: Add private syms and vars.
2262+
simdArgs.reduction.syms = simdReductionSyms;
2263+
simdArgs.reduction.vars = simdClauseOps.reductionVars;
22682264
auto simdOp =
22692265
genWrapperOp<mlir::omp::SimdOp>(converter, loc, simdClauseOps, simdArgs);
22702266
simdOp.setComposite(/*val=*/true);
@@ -2357,12 +2353,6 @@ static void genCompositeDoSimd(lower::AbstractConverter &converter,
23572353
genSimdClauses(converter, semaCtx, simdItem->clauses, loc, simdClauseOps,
23582354
simdReductionSyms);
23592355

2360-
// TODO: Remove this after omp.simd reductions on composite constructs are
2361-
// supported.
2362-
simdClauseOps.reductionVars.clear();
2363-
simdClauseOps.reductionByref.clear();
2364-
simdClauseOps.reductionSyms.clear();
2365-
23662356
// TODO: Support delayed privatization.
23672357
DataSharingProcessor dsp(converter, semaCtx, simdItem->clauses, eval,
23682358
/*shouldCollectPreDeterminedSymbols=*/true,
@@ -2386,7 +2376,9 @@ static void genCompositeDoSimd(lower::AbstractConverter &converter,
23862376
wsloopOp.setComposite(/*val=*/true);
23872377

23882378
EntryBlockArgs simdArgs;
2389-
// TODO: Add private and reduction syms and vars.
2379+
// TODO: Add private syms and vars.
2380+
simdArgs.reduction.syms = simdReductionSyms;
2381+
simdArgs.reduction.vars = simdClauseOps.reductionVars;
23902382
auto simdOp =
23912383
genWrapperOp<mlir::omp::SimdOp>(converter, loc, simdClauseOps, simdArgs);
23922384
simdOp.setComposite(/*val=*/true);

flang/test/Lower/OpenMP/wsloop-simd.f90

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,24 @@ subroutine do_simd_simdlen()
4545
end do
4646
!$omp end do simd
4747
end subroutine do_simd_simdlen
48+
49+
! CHECK-LABEL: func.func @_QPdo_simd_reduction(
50+
subroutine do_simd_reduction()
51+
integer :: sum
52+
sum = 0
53+
! CHECK: omp.wsloop
54+
! CHECK-SAME: reduction(@[[RED_SYM:.*]] %{{.*}} -> %[[RED_OUTER:.*]] : !fir.ref<i32>)
55+
! CHECK-NEXT: omp.simd
56+
! CHECK-SAME: reduction(@[[RED_SYM]] %[[RED_OUTER]] -> %[[RED_INNER:.*]] : !fir.ref<i32>)
57+
! CHECK-NEXT: omp.loop_nest
58+
! CHECK: %[[RED_DECL:.*]]:2 = hlfir.declare %[[RED_INNER]]
59+
! CHECK: %[[RED:.*]] = fir.load %[[RED_DECL]]#0 : !fir.ref<i32>
60+
! CHECK: %[[RESULT:.*]] = arith.addi %[[RED]], %{{.*}} : i32
61+
! CHECK: hlfir.assign %[[RESULT]] to %[[RED_DECL]]#0 : i32, !fir.ref<i32>
62+
! CHECK-NEXT: omp.yield
63+
!$omp do simd reduction(+:sum)
64+
do index_ = 1, 10
65+
sum = sum + 1
66+
end do
67+
!$omp end do simd
68+
end subroutine do_simd_reduction

0 commit comments

Comments
 (0)