Skip to content

Commit ee4a8e0

Browse files
committed
[flang][OpenMP] use reduction alloc region
I removed the `*-hlfir*` tests because they are duplicate now that the other tests have been updated to use the HLFIR lowering.
1 parent 9e37da3 commit ee4a8e0

35 files changed

+317
-436
lines changed

flang/lib/Lower/OpenMP/ReductionProcessor.cpp

Lines changed: 63 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -489,23 +489,57 @@ static mlir::Type unwrapSeqOrBoxedType(mlir::Type ty) {
489489
return ty;
490490
}
491491

492-
static mlir::Value
493-
createReductionInitRegion(fir::FirOpBuilder &builder, mlir::Location loc,
494-
mlir::omp::DeclareReductionOp &reductionDecl,
495-
const ReductionProcessor::ReductionIdentifier redId,
496-
mlir::Type type, bool isByRef) {
492+
static void createReductionAllocAndInitRegions(
493+
fir::FirOpBuilder &builder, mlir::Location loc,
494+
mlir::omp::DeclareReductionOp &reductionDecl,
495+
const ReductionProcessor::ReductionIdentifier redId, mlir::Type type,
496+
bool isByRef) {
497+
auto yield = [&](mlir::Value ret) {
498+
builder.create<mlir::omp::YieldOp>(loc, ret);
499+
};
500+
501+
mlir::Block *allocBlock = nullptr;
502+
mlir::Block *initBlock = nullptr;
503+
if (isByRef) {
504+
allocBlock =
505+
builder.createBlock(&reductionDecl.getAllocRegion(),
506+
reductionDecl.getAllocRegion().end(), {}, {});
507+
initBlock = builder.createBlock(&reductionDecl.getInitializerRegion(),
508+
reductionDecl.getInitializerRegion().end(),
509+
{type, type}, {loc, loc});
510+
} else {
511+
initBlock = builder.createBlock(&reductionDecl.getInitializerRegion(),
512+
reductionDecl.getInitializerRegion().end(),
513+
{type}, {loc});
514+
}
515+
497516
mlir::Type ty = fir::unwrapRefType(type);
517+
builder.setInsertionPointToEnd(initBlock);
498518
mlir::Value initValue = ReductionProcessor::getReductionInitValue(
499519
loc, unwrapSeqOrBoxedType(ty), redId, builder);
500520

501521
if (fir::isa_trivial(ty)) {
502522
if (isByRef) {
503-
mlir::Value alloca = builder.create<fir::AllocaOp>(loc, ty);
504-
builder.createStoreWithConvert(loc, initValue, alloca);
505-
return alloca;
523+
// alloc region
524+
{
525+
builder.setInsertionPointToEnd(allocBlock);
526+
mlir::Value alloca = builder.create<fir::AllocaOp>(loc, ty);
527+
yield(alloca);
528+
}
529+
530+
// init region
531+
{
532+
builder.setInsertionPointToEnd(initBlock);
533+
// block arg is mapped to the alloca yielded from the alloc region
534+
mlir::Value alloc = reductionDecl.getInitializerAllocArg();
535+
builder.createStoreWithConvert(loc, initValue, alloc);
536+
yield(alloc);
537+
}
538+
return;
506539
}
507540
// by val
508-
return initValue;
541+
yield(initValue);
542+
return;
509543
}
510544

511545
// check if an allocatable box is unallocated. If so, initialize the boxAlloca
@@ -520,10 +554,10 @@ createReductionInitRegion(fir::FirOpBuilder &builder, mlir::Location loc,
520554
// fir.store %something to %box_alloca
521555
// }
522556
// omp.yield %box_alloca
523-
mlir::Value blockArg =
524-
builder.loadIfRef(loc, builder.getBlock()->getArgument(0));
557+
mlir::Value moldArg =
558+
builder.loadIfRef(loc, reductionDecl.getInitializerMoldArg());
525559
auto handleNullAllocatable = [&](mlir::Value boxAlloca) -> fir::IfOp {
526-
mlir::Value addr = builder.create<fir::BoxAddrOp>(loc, blockArg);
560+
mlir::Value addr = builder.create<fir::BoxAddrOp>(loc, moldArg);
527561
mlir::Value isNotAllocated = builder.genIsNullAddr(loc, addr);
528562
fir::IfOp ifOp = builder.create<fir::IfOp>(loc, isNotAllocated,
529563
/*withElseRegion=*/true);
@@ -539,7 +573,17 @@ createReductionInitRegion(fir::FirOpBuilder &builder, mlir::Location loc,
539573
assert(isByRef && "passing boxes by value is unsupported");
540574
bool isAllocatableOrPointer =
541575
mlir::isa<fir::HeapType, fir::PointerType>(boxTy.getEleTy());
542-
mlir::Value boxAlloca = builder.create<fir::AllocaOp>(loc, ty);
576+
577+
// alloc region
578+
{
579+
builder.setInsertionPointToEnd(allocBlock);
580+
mlir::Value boxAlloca = builder.create<fir::AllocaOp>(loc, ty);
581+
yield(boxAlloca);
582+
}
583+
584+
// init region
585+
builder.setInsertionPointToEnd(initBlock);
586+
mlir::Value boxAlloca = reductionDecl.getInitializerAllocArg();
543587
mlir::Type innerTy = fir::unwrapRefType(boxTy.getEleTy());
544588
if (fir::isa_trivial(innerTy)) {
545589
// boxed non-sequence value e.g. !fir.box<!fir.heap<i32>>
@@ -558,7 +602,8 @@ createReductionInitRegion(fir::FirOpBuilder &builder, mlir::Location loc,
558602
createReductionCleanupRegion(builder, loc, reductionDecl);
559603
builder.restoreInsertionPoint(insPt);
560604
builder.setInsertionPointAfter(ifUnallocated);
561-
return boxAlloca;
605+
yield(boxAlloca);
606+
return;
562607
}
563608
innerTy = fir::extractSequenceType(boxTy);
564609
if (!mlir::isa<fir::SequenceType>(innerTy))
@@ -571,7 +616,7 @@ createReductionInitRegion(fir::FirOpBuilder &builder, mlir::Location loc,
571616
}
572617

573618
// Create the private copy from the initial fir.box:
574-
mlir::Value loadedBox = builder.loadIfRef(loc, blockArg);
619+
mlir::Value loadedBox = builder.loadIfRef(loc, moldArg);
575620
hlfir::Entity source = hlfir::Entity{loadedBox};
576621

577622
// Allocating on the heap in case the whole reduction is nested inside of a
@@ -616,7 +661,8 @@ createReductionInitRegion(fir::FirOpBuilder &builder, mlir::Location loc,
616661
builder.create<fir::StoreOp>(loc, box, boxAlloca);
617662
if (ifUnallocated)
618663
builder.setInsertionPointAfter(ifUnallocated);
619-
return boxAlloca;
664+
yield(boxAlloca);
665+
return;
620666
}
621667

622668
TODO(loc, "createReductionInitRegion for unsupported type");
@@ -643,13 +689,7 @@ mlir::omp::DeclareReductionOp ReductionProcessor::createDeclareReduction(
643689

644690
decl = modBuilder.create<mlir::omp::DeclareReductionOp>(loc, reductionOpName,
645691
type);
646-
builder.createBlock(&decl.getInitializerRegion(),
647-
decl.getInitializerRegion().end(), {type}, {loc});
648-
builder.setInsertionPointToEnd(&decl.getInitializerRegion().back());
649-
650-
mlir::Value init =
651-
createReductionInitRegion(builder, loc, decl, redId, type, isByRef);
652-
builder.create<mlir::omp::YieldOp>(loc, init);
692+
createReductionAllocAndInitRegions(builder, loc, decl, redId, type, isByRef);
653693

654694
builder.createBlock(&decl.getReductionRegion(),
655695
decl.getReductionRegion().end(), {type, type},

flang/test/Lower/OpenMP/delayed-privatization-reduction-byref.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ subroutine red_and_delayed_private
2222
! CHECK-SAME: @[[PRIVATIZER_SYM:.*]] : !fir.ref<i32> alloc {
2323

2424
! CHECK-LABEL: omp.declare_reduction
25-
! CHECK-SAME: @[[REDUCTION_SYM:.*]] : !fir.ref<i32> init
25+
! CHECK-SAME: @[[REDUCTION_SYM:.*]] : !fir.ref<i32> alloc
2626

2727
! CHECK-LABEL: _QPred_and_delayed_private
2828
! CHECK: omp.parallel

flang/test/Lower/OpenMP/parallel-reduction-add-byref.f90

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33

44
!CHECK-LABEL: omp.declare_reduction
55
!CHECK-SAME: @[[RED_F32_NAME:.*]] : !fir.ref<f32>
6-
!CHECK-SAME: init {
7-
!CHECK: ^bb0(%{{.*}}: !fir.ref<f32>):
8-
!CHECK: %[[C0_1:.*]] = arith.constant 0.000000e+00 : f32
6+
!CHECK-SAME: alloc {
97
!CHECK: %[[REF:.*]] = fir.alloca f32
10-
!CHECKL fir.store [[%C0_1]] to %[[REF]] : !fir.ref<f32>
118
!CHECK: omp.yield(%[[REF]] : !fir.ref<f32>)
9+
!CHECK-LABEL: } init {
10+
!CHECK: ^bb0(%{{.*}}: !fir.ref<f32>, %[[ALLOC:.*]]: !fir.ref<f32>):
11+
!CHECK: %[[C0_1:.*]] = arith.constant 0.000000e+00 : f32
12+
!CHECKL fir.store [[%C0_1]] to %[[ALLOC]] : !fir.ref<f32>
13+
!CHECK: omp.yield(%[[ALLOC]] : !fir.ref<f32>)
1214
!CHECK: } combiner {
1315
!CHECK: ^bb0(%[[ARG0:.*]]: !fir.ref<f32>, %[[ARG1:.*]]: !fir.ref<f32>):
1416
!CHECK: %[[LD0:.*]] = fir.load %[[ARG0]] : !fir.ref<f32>
@@ -20,12 +22,14 @@
2022

2123
!CHECK-LABEL: omp.declare_reduction
2224
!CHECK-SAME: @[[RED_I32_NAME:.*]] : !fir.ref<i32>
23-
!CHECK-SAME: init {
24-
!CHECK: ^bb0(%{{.*}}: !fir.ref<i32>):
25-
!CHECK: %[[C0_1:.*]] = arith.constant 0 : i32
25+
!CHECK-SAME: alloc {
2626
!CHECK: %[[REF:.*]] = fir.alloca i32
27-
!CHECK: fir.store %[[C0_1]] to %[[REF]] : !fir.ref<i32>
2827
!CHECK: omp.yield(%[[REF]] : !fir.ref<i32>)
28+
!CHECK-LABEL: } init {
29+
!CHECK: ^bb0(%{{.*}}: !fir.ref<i32>, %[[ALLOC:.*]]: !fir.ref<i32>):
30+
!CHECK: %[[C0_1:.*]] = arith.constant 0 : i32
31+
!CHECK: fir.store %[[C0_1]] to %[[ALLOC]] : !fir.ref<i32>
32+
!CHECK: omp.yield(%[[ALLOC]] : !fir.ref<i32>)
2933
!CHECK: } combiner {
3034
!CHECK: ^bb0(%[[ARG0:.*]]: !fir.ref<i32>, %[[ARG1:.*]]: !fir.ref<i32>):
3135
!CHECK: %[[LD0:.*]] = fir.load %[[ARG0]] : !fir.ref<i32>

flang/test/Lower/OpenMP/parallel-reduction-allocatable-array.f90

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,20 @@ program reduce
1818

1919
end program
2020

21-
! CHECK-LABEL: omp.declare_reduction @add_reduction_byref_box_heap_Uxi32 : !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>> init {
22-
! CHECK: ^bb0(%[[VAL_0:.*]]: !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>):
21+
! CHECK-LABEL: omp.declare_reduction @add_reduction_byref_box_heap_Uxi32 : !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>> alloc {
22+
! CHECK: %[[VAL_10:.*]] = fir.alloca !fir.box<!fir.heap<!fir.array<?xi32>>>
23+
! CHECK: omp.yield(%[[VAL_10]] : !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>)
24+
! CHECK-LABEL: } init {
25+
! CHECK: ^bb0(%[[VAL_0:.*]]: !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>, %[[ALLOC:.*]]: !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>):
2326
! CHECK: %[[VAL_1:.*]] = arith.constant 0 : i32
2427
! CHECK: %[[VAL_2:.*]] = fir.load %[[VAL_0]] : !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>
25-
! CHECK: %[[VAL_10:.*]] = fir.alloca !fir.box<!fir.heap<!fir.array<?xi32>>>
2628
! CHECK: %[[ADDR:.*]] = fir.box_addr %[[VAL_2]] : (!fir.box<!fir.heap<!fir.array<?xi32>>>) -> !fir.heap<!fir.array<?xi32>>
2729
! CHECK: %[[ADDRI:.*]] = fir.convert %[[ADDR]] : (!fir.heap<!fir.array<?xi32>>) -> i64
2830
! CHECK: %[[C0_I64:.*]] = arith.constant 0 : i64
2931
! CHECK: %[[IS_NULL:.*]] = arith.cmpi eq, %[[ADDRI]], %[[C0_I64]] : i64
3032
! CHECK: fir.if %[[IS_NULL]] {
3133
! CHECK: %[[NULL_BOX:.*]] = fir.embox %[[ADDR]] : (!fir.heap<!fir.array<?xi32>>) -> !fir.box<!fir.heap<!fir.array<?xi32>>>
32-
! CHECK: fir.store %[[NULL_BOX]] to %[[VAL_10]] : !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>
34+
! CHECK: fir.store %[[NULL_BOX]] to %[[ALLOC]] : !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>
3335
! CHECK: } else {
3436
! CHECK: %[[VAL_3:.*]] = arith.constant 0 : index
3537
! CHECK: %[[VAL_4:.*]]:3 = fir.box_dims %[[VAL_2]], %[[VAL_3]] : (!fir.box<!fir.heap<!fir.array<?xi32>>>, index) -> (index, index, index)
@@ -42,9 +44,9 @@ program reduce
4244
! CHECK: %[[SHIFT:.*]] = fir.shape_shift %[[DIMS]]#0, %[[DIMS]]#1 : (index, index) -> !fir.shapeshift<1>
4345
! CHECK: %[[REBOX:.*]] = fir.rebox %[[VAL_8]]#0(%[[SHIFT]]) : (!fir.box<!fir.array<?xi32>>, !fir.shapeshift<1>) -> !fir.box<!fir.heap<!fir.array<?xi32>>>
4446
! CHECK: hlfir.assign %[[VAL_1]] to %[[REBOX]] : i32, !fir.box<!fir.heap<!fir.array<?xi32>>>
45-
! CHECK: fir.store %[[REBOX]] to %[[VAL_10]] : !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>
47+
! CHECK: fir.store %[[REBOX]] to %[[ALLOC]] : !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>
4648
! CHECK: }
47-
! CHECK: omp.yield(%[[VAL_10]] : !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>)
49+
! CHECK: omp.yield(%[[ALLOC]] : !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>)
4850
! CHECK: } combiner {
4951
! CHECK: ^bb0(%[[VAL_0:.*]]: !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>, %[[VAL_1:.*]]: !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>):
5052
! CHECK: %[[VAL_2:.*]] = fir.load %[[VAL_0]] : !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>

flang/test/Lower/OpenMP/parallel-reduction-array-lb.f90

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ program reduce
1212

1313
end program
1414

15-
! CHECK-LABEL: omp.declare_reduction @add_reduction_byref_box_3x2xi32 : !fir.ref<!fir.box<!fir.array<3x2xi32>>> init {
16-
! CHECK: ^bb0(%[[VAL_0:.*]]: !fir.ref<!fir.box<!fir.array<3x2xi32>>>):
15+
! CHECK-LABEL: omp.declare_reduction @add_reduction_byref_box_3x2xi32 : !fir.ref<!fir.box<!fir.array<3x2xi32>>> alloc {
16+
! CHECK: %[[VAL_15:.*]] = fir.alloca !fir.box<!fir.array<3x2xi32>>
17+
! CHECK: omp.yield(%[[VAL_15]] : !fir.ref<!fir.box<!fir.array<3x2xi32>>>)
18+
! CHECK-LABEL: } init {
19+
! CHECK: ^bb0(%[[VAL_0:.*]]: !fir.ref<!fir.box<!fir.array<3x2xi32>>>, %[[ALLOC:.*]]: !fir.ref<!fir.box<!fir.array<3x2xi32>>>):
1720
! CHECK: %[[VAL_1:.*]] = arith.constant 0 : i32
1821
! CHECK: %[[VAL_2:.*]] = fir.load %[[VAL_0]] : !fir.ref<!fir.box<!fir.array<3x2xi32>>>
19-
! CHECK: %[[VAL_15:.*]] = fir.alloca !fir.box<!fir.array<3x2xi32>>
2022
! CHECK: %[[VAL_3:.*]] = arith.constant 3 : index
2123
! CHECK: %[[VAL_4:.*]] = arith.constant 2 : index
2224
! CHECK: %[[VAL_5:.*]] = fir.shape %[[VAL_3]], %[[VAL_4]] : (index, index) -> !fir.shape<2>
@@ -30,8 +32,8 @@ program reduce
3032
! CHECK: %[[VAL_13:.*]] = fir.shape_shift %[[VAL_10]]#0, %[[VAL_10]]#1, %[[VAL_12]]#0, %[[VAL_12]]#1 : (index, index, index, index) -> !fir.shapeshift<2>
3133
! CHECK: %[[VAL_14:.*]] = fir.embox %[[VAL_8]]#0(%[[VAL_13]]) : (!fir.heap<!fir.array<3x2xi32>>, !fir.shapeshift<2>) -> !fir.box<!fir.array<3x2xi32>>
3234
! CHECK: hlfir.assign %[[VAL_1]] to %[[VAL_14]] : i32, !fir.box<!fir.array<3x2xi32>>
33-
! CHECK: fir.store %[[VAL_14]] to %[[VAL_15]] : !fir.ref<!fir.box<!fir.array<3x2xi32>>>
34-
! CHECK: omp.yield(%[[VAL_15]] : !fir.ref<!fir.box<!fir.array<3x2xi32>>>)
35+
! CHECK: fir.store %[[VAL_14]] to %[[ALLOC]] : !fir.ref<!fir.box<!fir.array<3x2xi32>>>
36+
! CHECK: omp.yield(%[[ALLOC]] : !fir.ref<!fir.box<!fir.array<3x2xi32>>>)
3537
! CHECK: } combiner {
3638
! CHECK: ^bb0(%[[VAL_0:.*]]: !fir.ref<!fir.box<!fir.array<3x2xi32>>>, %[[VAL_1:.*]]: !fir.ref<!fir.box<!fir.array<3x2xi32>>>):
3739
! CHECK: %[[VAL_2:.*]] = fir.load %[[VAL_0]] : !fir.ref<!fir.box<!fir.array<3x2xi32>>>

flang/test/Lower/OpenMP/parallel-reduction-array.f90

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@ program reduce
1313
print *,i
1414
end program
1515

16-
! CHECK-LABEL: omp.declare_reduction @add_reduction_byref_box_3xi32 : !fir.ref<!fir.box<!fir.array<3xi32>>> init {
17-
! CHECK: ^bb0(%[[VAL_0:.*]]: !fir.ref<!fir.box<!fir.array<3xi32>>>):
16+
! CHECK-LABEL: omp.declare_reduction @add_reduction_byref_box_3xi32 : !fir.ref<!fir.box<!fir.array<3xi32>>> alloc {
17+
! CHECK: %[[VAL_8:.*]] = fir.alloca !fir.box<!fir.array<3xi32>>
18+
! CHECK: omp.yield(%[[VAL_8]] : !fir.ref<!fir.box<!fir.array<3xi32>>>)
19+
! CHECK-LABEL: } init {
20+
! CHECK: ^bb0(%[[VAL_0:.*]]: !fir.ref<!fir.box<!fir.array<3xi32>>>, %[[ALLOC:.*]]: !fir.ref<!fir.box<!fir.array<3xi32>>>):
1821
! CHECK: %[[VAL_2:.*]] = arith.constant 0 : i32
1922
! CHECK: %[[VAL_3:.*]] = fir.load %[[VAL_0]] : !fir.ref<!fir.box<!fir.array<3xi32>>>
20-
! CHECK: %[[VAL_8:.*]] = fir.alloca !fir.box<!fir.array<3xi32>>
2123
! CHECK: %[[VAL_4:.*]] = arith.constant 3 : index
2224
! CHECK: %[[VAL_5:.*]] = fir.shape %[[VAL_4]] : (index) -> !fir.shape<1>
2325
! CHECK: %[[VAL_1:.*]] = fir.allocmem !fir.array<3xi32> {bindc_name = ".tmp", uniq_name = ""}
@@ -29,8 +31,8 @@ program reduce
2931
! CHECK: %[[SHIFT:.*]] = fir.shape_shift %[[DIMS]]#0, %[[DIMS]]#1 : (index, index) -> !fir.shapeshift<1>
3032
! CHECK: %[[VAL_7:.*]] = fir.embox %[[VAL_6]]#0(%[[SHIFT]]) : (!fir.heap<!fir.array<3xi32>>, !fir.shapeshift<1>) -> !fir.box<!fir.array<3xi32>>
3133
! CHECK: hlfir.assign %[[VAL_2]] to %[[VAL_7]] : i32, !fir.box<!fir.array<3xi32>>
32-
! CHECK: fir.store %[[VAL_7]] to %[[VAL_8]] : !fir.ref<!fir.box<!fir.array<3xi32>>>
33-
! CHECK: omp.yield(%[[VAL_8]] : !fir.ref<!fir.box<!fir.array<3xi32>>>)
34+
! CHECK: fir.store %[[VAL_7]] to %[[ALLOC]] : !fir.ref<!fir.box<!fir.array<3xi32>>>
35+
! CHECK: omp.yield(%[[ALLOC]] : !fir.ref<!fir.box<!fir.array<3xi32>>>)
3436
! CHECK: } combiner {
3537
! CHECK: ^bb0(%[[VAL_0:.*]]: !fir.ref<!fir.box<!fir.array<3xi32>>>, %[[VAL_1:.*]]: !fir.ref<!fir.box<!fir.array<3xi32>>>):
3638
! CHECK: %[[VAL_2:.*]] = fir.load %[[VAL_0]] : !fir.ref<!fir.box<!fir.array<3xi32>>>

flang/test/Lower/OpenMP/parallel-reduction-array2.f90

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@ program reduce
1313
print *,i
1414
end program
1515

16-
! CHECK-LABEL: omp.declare_reduction @add_reduction_byref_box_3xi32 : !fir.ref<!fir.box<!fir.array<3xi32>>> init {
17-
! CHECK: ^bb0(%[[VAL_0:.*]]: !fir.ref<!fir.box<!fir.array<3xi32>>>):
16+
! CHECK-LABEL: omp.declare_reduction @add_reduction_byref_box_3xi32 : !fir.ref<!fir.box<!fir.array<3xi32>>> alloc {
17+
! CHECK: %[[VAL_8:.*]] = fir.alloca !fir.box<!fir.array<3xi32>>
18+
! CHECK: omp.yield(%[[VAL_8]] : !fir.ref<!fir.box<!fir.array<3xi32>>>)
19+
! CHECK-LABEL: } init {
20+
! CHECK: ^bb0(%[[VAL_0:.*]]: !fir.ref<!fir.box<!fir.array<3xi32>>>, %[[ALLOC:.*]]: !fir.ref<!fir.box<!fir.array<3xi32>>>):
1821
! CHECK: %[[VAL_2:.*]] = arith.constant 0 : i32
1922
! CHECK: %[[VAL_3:.*]] = fir.load %[[VAL_0]] : !fir.ref<!fir.box<!fir.array<3xi32>>>
20-
! CHECK: %[[VAL_8:.*]] = fir.alloca !fir.box<!fir.array<3xi32>>
2123
! CHECK: %[[VAL_4:.*]] = arith.constant 3 : index
2224
! CHECK: %[[VAL_5:.*]] = fir.shape %[[VAL_4]] : (index) -> !fir.shape<1>
2325
! CHECK: %[[VAL_1:.*]] = fir.allocmem !fir.array<3xi32>
@@ -28,8 +30,8 @@ program reduce
2830
! CHECK: %[[SHIFT:.*]] = fir.shape_shift %[[DIMS]]#0, %[[DIMS]]#1 : (index, index) -> !fir.shapeshift<1>
2931
! CHECK: %[[VAL_7:.*]] = fir.embox %[[VAL_6]]#0(%[[SHIFT]]) : (!fir.heap<!fir.array<3xi32>>, !fir.shapeshift<1>) -> !fir.box<!fir.array<3xi32>>
3032
! CHECK: hlfir.assign %[[VAL_2]] to %[[VAL_7]] : i32, !fir.box<!fir.array<3xi32>>
31-
! CHECK: fir.store %[[VAL_7]] to %[[VAL_8]] : !fir.ref<!fir.box<!fir.array<3xi32>>>
32-
! CHECK: omp.yield(%[[VAL_8]] : !fir.ref<!fir.box<!fir.array<3xi32>>>)
33+
! CHECK: fir.store %[[VAL_7]] to %[[ALLOC]] : !fir.ref<!fir.box<!fir.array<3xi32>>>
34+
! CHECK: omp.yield(%[[ALLOC]] : !fir.ref<!fir.box<!fir.array<3xi32>>>)
3335
! CHECK: } combiner {
3436
! CHECK: ^bb0(%[[VAL_0:.*]]: !fir.ref<!fir.box<!fir.array<3xi32>>>, %[[VAL_1:.*]]: !fir.ref<!fir.box<!fir.array<3xi32>>>):
3537
! CHECK: %[[VAL_2:.*]] = fir.load %[[VAL_0]] : !fir.ref<!fir.box<!fir.array<3xi32>>>

flang/test/Lower/OpenMP/parallel-reduction-byref.f90

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
! RUN: %flang_fc1 -emit-hlfir -fopenmp -mmlir --force-byref-reduction -o - %s 2>&1 | FileCheck %s
33

44
!CHECK: omp.declare_reduction @[[REDUCTION_DECLARE:[_a-z0-9]+]] : !fir.ref<i32>
5-
!CHECK-SAME: init {
6-
!CHECK: ^bb0(%{{.*}}: !fir.ref<i32>):
7-
!CHECK: %[[I0:[_a-z0-9]+]] = arith.constant 0 : i32
8-
!CHECK: %[[REF:.*]] = fir.alloca i32
9-
!CHECKL fir.store [[%I0]] to %[[REF]] : !fir.ref<i32>
5+
!CHECK-SAME: alloc {
6+
!CHECK: %[[REF:.*]] = fir.alloca i32
107
!CHECK: omp.yield(%[[REF]] : !fir.ref<i32>)
8+
!CHECK-LABEL: } init {
9+
!CHECK: ^bb0(%{{.*}}: !fir.ref<i32>, %[[ALLOC:.*]]: !fir.ref<i32>):
10+
!CHECK: %[[I0:[_a-z0-9]+]] = arith.constant 0 : i32
11+
!CHECKL fir.store [[%I0]] to %[[ALLOC]] : !fir.ref<i32>
12+
!CHECK: omp.yield(%[[ALLOC]] : !fir.ref<i32>)
1113
!CHECK: } combiner {
1214
!CHECK: ^bb0(%[[C0:[_a-z0-9]+]]: !fir.ref<i32>, %[[C1:[_a-z0-9]+]]: !fir.ref<i32>):
1315
!CHECK: %[[LD0:.*]] = fir.load %[[C0]] : !fir.ref<i32>

flang/test/Lower/OpenMP/parallel-reduction-mixed.f90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ end subroutine proc
2424
!CHECK: %[[TID_LOCAL:.*]] = alloca i32
2525
!CHECK: %[[TID:.*]] = load i32, ptr %[[TID_ADDR]]
2626
!CHECK: store i32 %[[TID]], ptr %[[TID_LOCAL]]
27-
!CHECK: %[[I_priv:.*]] = alloca i32
2827
!CHECK: %[[F_priv:.*]] = alloca ptr
28+
!CHECK: %[[I_priv:.*]] = alloca i32
29+
!CHECK: store ptr %{{.*}}, ptr %[[F_priv]]
2930

3031
!CHECK: omp.reduction.init:
31-
!CHECK: store ptr %{{.*}}, ptr %[[F_priv]]
3232
!CHECK: store i32 0, ptr %[[I_priv]]
3333

3434
!CHECK: omp.par.region:

0 commit comments

Comments
 (0)