Skip to content

Commit f74b85c

Browse files
authored
[flang][openacc] Support array with dynamic extents in reduction recipe (#68829)
Add support for array with dynamic extents in lowering of the reduction recipe.
1 parent e2e32f0 commit f74b85c

File tree

2 files changed

+143
-20
lines changed

2 files changed

+143
-20
lines changed

flang/lib/Lower/OpenACC.cpp

Lines changed: 90 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -920,18 +920,27 @@ static mlir::Value genReductionInitRegion(fir::FirOpBuilder &builder,
920920
declareOp.getBase());
921921
return declareOp.getBase();
922922
} else if (auto seqTy = mlir::dyn_cast_or_null<fir::SequenceType>(ty)) {
923-
if (seqTy.hasDynamicExtents())
924-
TODO(loc, "reduction recipe of array with dynamic extents");
925923
if (fir::isa_trivial(seqTy.getEleTy())) {
926-
mlir::Value alloca = builder.create<fir::AllocaOp>(loc, seqTy);
927-
auto shapeOp = genShapeOp(builder, seqTy, loc);
924+
mlir::Value shape;
925+
auto extents = builder.getBlock()->getArguments().drop_front(1);
926+
if (seqTy.hasDynamicExtents())
927+
shape = builder.create<fir::ShapeOp>(loc, extents);
928+
else
929+
shape = genShapeOp(builder, seqTy, loc);
930+
mlir::Value alloca = builder.create<fir::AllocaOp>(
931+
loc, seqTy, /*typeparams=*/mlir::ValueRange{}, extents);
928932
auto declareOp = builder.create<hlfir::DeclareOp>(
929-
loc, alloca, accReductionInitName, shapeOp,
933+
loc, alloca, accReductionInitName, shape,
930934
llvm::ArrayRef<mlir::Value>{}, fir::FortranVariableFlagsAttr{});
931935
mlir::Type idxTy = builder.getIndexType();
932936
mlir::Type refTy = fir::ReferenceType::get(seqTy.getEleTy());
933937
llvm::SmallVector<fir::DoLoopOp> loops;
934938
llvm::SmallVector<mlir::Value> ivs;
939+
940+
if (seqTy.hasDynamicExtents()) {
941+
builder.create<hlfir::AssignOp>(loc, initValue, declareOp.getBase());
942+
return declareOp.getBase();
943+
}
935944
for (auto ext : llvm::reverse(seqTy.getShape())) {
936945
auto lb = builder.createIntegerConstant(loc, idxTy, 0);
937946
auto ub = builder.createIntegerConstant(loc, idxTy, ext - 1);
@@ -1052,6 +1061,18 @@ static mlir::Value genScalarCombiner(fir::FirOpBuilder &builder,
10521061
TODO(loc, "reduction operator");
10531062
}
10541063

1064+
static hlfir::DesignateOp::Subscripts
1065+
getTripletsFromArgs(mlir::acc::ReductionRecipeOp recipe) {
1066+
hlfir::DesignateOp::Subscripts triplets;
1067+
for (unsigned i = 2; i < recipe.getCombinerRegion().getArguments().size();
1068+
i += 3)
1069+
triplets.emplace_back(hlfir::DesignateOp::Triplet{
1070+
recipe.getCombinerRegion().getArgument(i),
1071+
recipe.getCombinerRegion().getArgument(i + 1),
1072+
recipe.getCombinerRegion().getArgument(i + 2)});
1073+
return triplets;
1074+
}
1075+
10551076
static void genCombiner(fir::FirOpBuilder &builder, mlir::Location loc,
10561077
mlir::acc::ReductionOperator op, mlir::Type ty,
10571078
mlir::Value value1, mlir::Value value2,
@@ -1061,11 +1082,60 @@ static void genCombiner(fir::FirOpBuilder &builder, mlir::Location loc,
10611082
ty = fir::unwrapRefType(ty);
10621083

10631084
if (auto seqTy = mlir::dyn_cast<fir::SequenceType>(ty)) {
1064-
assert(!seqTy.hasDynamicExtents() &&
1065-
"Assumed shaped array should be boxed for reduction");
10661085
mlir::Type refTy = fir::ReferenceType::get(seqTy.getEleTy());
10671086
llvm::SmallVector<fir::DoLoopOp> loops;
10681087
llvm::SmallVector<mlir::Value> ivs;
1088+
if (seqTy.hasDynamicExtents()) {
1089+
auto shape =
1090+
genShapeFromBoundsOrArgs(loc, builder, seqTy, bounds,
1091+
recipe.getCombinerRegion().getArguments());
1092+
auto v1DeclareOp = builder.create<hlfir::DeclareOp>(
1093+
loc, value1, llvm::StringRef{}, shape, llvm::ArrayRef<mlir::Value>{},
1094+
fir::FortranVariableFlagsAttr{});
1095+
auto v2DeclareOp = builder.create<hlfir::DeclareOp>(
1096+
loc, value2, llvm::StringRef{}, shape, llvm::ArrayRef<mlir::Value>{},
1097+
fir::FortranVariableFlagsAttr{});
1098+
hlfir::DesignateOp::Subscripts triplets = getTripletsFromArgs(recipe);
1099+
1100+
llvm::SmallVector<mlir::Value> lenParamsLeft;
1101+
auto leftEntity = hlfir::Entity{v1DeclareOp.getBase()};
1102+
hlfir::genLengthParameters(loc, builder, leftEntity, lenParamsLeft);
1103+
auto leftDesignate = builder.create<hlfir::DesignateOp>(
1104+
loc, v1DeclareOp.getBase().getType(), v1DeclareOp.getBase(),
1105+
/*component=*/"",
1106+
/*componentShape=*/mlir::Value{}, triplets,
1107+
/*substring=*/mlir::ValueRange{}, /*complexPartAttr=*/std::nullopt,
1108+
shape, lenParamsLeft);
1109+
auto left = hlfir::Entity{leftDesignate.getResult()};
1110+
1111+
llvm::SmallVector<mlir::Value> lenParamsRight;
1112+
auto rightEntity = hlfir::Entity{v2DeclareOp.getBase()};
1113+
hlfir::genLengthParameters(loc, builder, rightEntity, lenParamsLeft);
1114+
auto rightDesignate = builder.create<hlfir::DesignateOp>(
1115+
loc, v2DeclareOp.getBase().getType(), v2DeclareOp.getBase(),
1116+
/*component=*/"",
1117+
/*componentShape=*/mlir::Value{}, triplets,
1118+
/*substring=*/mlir::ValueRange{}, /*complexPartAttr=*/std::nullopt,
1119+
shape, lenParamsRight);
1120+
auto right = hlfir::Entity{rightDesignate.getResult()};
1121+
1122+
llvm::SmallVector<mlir::Value, 1> typeParams;
1123+
auto genKernel = [&builder, &loc, op, seqTy, &left, &right](
1124+
mlir::Location l, fir::FirOpBuilder &b,
1125+
mlir::ValueRange oneBasedIndices) -> hlfir::Entity {
1126+
auto leftElement = hlfir::getElementAt(l, b, left, oneBasedIndices);
1127+
auto rightElement = hlfir::getElementAt(l, b, right, oneBasedIndices);
1128+
auto leftVal = hlfir::loadTrivialScalar(l, b, leftElement);
1129+
auto rightVal = hlfir::loadTrivialScalar(l, b, rightElement);
1130+
return hlfir::Entity{genScalarCombiner(
1131+
builder, loc, op, seqTy.getEleTy(), leftVal, rightVal)};
1132+
};
1133+
mlir::Value elemental = hlfir::genElementalOp(
1134+
loc, builder, seqTy.getEleTy(), shape, typeParams, genKernel,
1135+
/*isUnordered=*/true);
1136+
builder.create<hlfir::AssignOp>(loc, elemental, v1DeclareOp.getBase());
1137+
return;
1138+
}
10691139
if (allConstantBound) {
10701140
// Use the constant bound directly in the combiner region so they do not
10711141
// need to be passed as block argument.
@@ -1108,7 +1178,6 @@ static void genCombiner(fir::FirOpBuilder &builder, mlir::Location loc,
11081178
builder.create<fir::StoreOp>(loc, res, addr1);
11091179
builder.setInsertionPointAfter(loops[0]);
11101180
} else if (auto boxTy = mlir::dyn_cast<fir::BaseBoxType>(ty)) {
1111-
llvm::SmallVector<mlir::Value> tripletArgs;
11121181
mlir::Type innerTy = extractSequenceType(boxTy);
11131182
fir::SequenceType seqTy =
11141183
mlir::dyn_cast_or_null<fir::SequenceType>(innerTy);
@@ -1160,8 +1229,20 @@ mlir::acc::ReductionRecipeOp Fortran::lower::createOrGetReductionRecipe(
11601229
mlir::OpBuilder modBuilder(mod.getBodyRegion());
11611230
auto recipe =
11621231
modBuilder.create<mlir::acc::ReductionRecipeOp>(loc, recipeName, ty, op);
1232+
llvm::SmallVector<mlir::Type> initArgsTy{ty};
1233+
llvm::SmallVector<mlir::Location> initArgsLoc{loc};
1234+
mlir::Type refTy = fir::unwrapRefType(ty);
1235+
if (auto seqTy = mlir::dyn_cast_or_null<fir::SequenceType>(refTy)) {
1236+
if (seqTy.hasDynamicExtents()) {
1237+
mlir::Type idxTy = builder.getIndexType();
1238+
for (unsigned i = 0; i < seqTy.getDimension(); ++i) {
1239+
initArgsTy.push_back(idxTy);
1240+
initArgsLoc.push_back(loc);
1241+
}
1242+
}
1243+
}
11631244
builder.createBlock(&recipe.getInitRegion(), recipe.getInitRegion().end(),
1164-
{ty}, {loc});
1245+
initArgsTy, initArgsLoc);
11651246
builder.setInsertionPointToEnd(&recipe.getInitRegion().back());
11661247
mlir::Value initValue = genReductionInitRegion(builder, loc, ty, op);
11671248
builder.create<mlir::acc::YieldOp>(loc, initValue);

flang/test/Lower/OpenACC/acc-reduction.f90

Lines changed: 53 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,35 @@
33
! RUN: bbc -fopenacc -emit-fir %s -o - | FileCheck %s --check-prefixes=CHECK,FIR
44
! RUN: bbc -fopenacc -emit-hlfir %s -o - | FileCheck %s --check-prefixes=CHECK,HLFIR
55

6+
! CHECK-LABEL: acc.reduction.recipe @reduction_max_ref_UxUxf32 : !fir.ref<!fir.array<?x?xf32>> reduction_operator <max> init {
7+
! CHECK: ^bb0(%[[ARG0:.*]]: !fir.ref<!fir.array<?x?xf32>>, %[[ARG1:.*]]: index, %[[ARG2:.*]]: index):
8+
! HLFIR: %[[CST:.*]] = arith.constant -1.401300e-45 : f32
9+
! HLFIR: %[[SHAPE:.*]] = fir.shape %arg1, %arg2 : (index, index) -> !fir.shape<2>
10+
! HLFIR: %[[TEMP:.*]] = fir.alloca !fir.array<?x?xf32>, %arg1, %arg2
11+
! HLFIR: %[[DECL:.*]]:2 = hlfir.declare %[[TEMP]](%[[SHAPE]]) {uniq_name = "acc.reduction.init"} : (!fir.ref<!fir.array<?x?xf32>>, !fir.shape<2>) -> (!fir.box<!fir.array<?x?xf32>>, !fir.ref<!fir.array<?x?xf32>>)
12+
! HLFIR: hlfir.assign %[[CST]] to %[[DECL]]#0 : f32, !fir.box<!fir.array<?x?xf32>>
13+
! HLFIR: acc.yield %[[DECL]]#0 : !fir.box<!fir.array<?x?xf32>>
14+
! CHECK: } combiner {
15+
! CHECK: ^bb0(%[[V1:.*]]: !fir.ref<!fir.array<?x?xf32>>, %[[V2:.*]]: !fir.ref<!fir.array<?x?xf32>>, %[[LB0:.*]]: index, %[[UB0:.*]]: index, %[[STEP0:.*]]: index, %[[LB1:.*]]: index, %[[UB1:.*]]: index, %[[STEP1:.*]]: index):
16+
! HLFIR: %[[SHAPE:.*]] = fir.shape %{{.*}}, %{{.*}} : (index, index) -> !fir.shape<2>
17+
! HLFIR: %[[DECL_V1:.*]]:2 = hlfir.declare %[[V1]](%[[SHAPE]]) {uniq_name = ""} : (!fir.ref<!fir.array<?x?xf32>>, !fir.shape<2>) -> (!fir.box<!fir.array<?x?xf32>>, !fir.ref<!fir.array<?x?xf32>>)
18+
! HLFIR: %[[DECL_V2:.*]]:2 = hlfir.declare %[[V2]](%[[SHAPE]]) {uniq_name = ""} : (!fir.ref<!fir.array<?x?xf32>>, !fir.shape<2>) -> (!fir.box<!fir.array<?x?xf32>>, !fir.ref<!fir.array<?x?xf32>>)
19+
! HLFIR: %[[DES_V1:.*]] = hlfir.designate %[[DECL_V1]]#0 (%arg2:%arg3:%arg4, %arg5:%arg6:%arg7) shape %10 : (!fir.box<!fir.array<?x?xf32>>, index, index, index, index, index, index, !fir.shape<2>) -> !fir.box<!fir.array<?x?xf32>>
20+
! HLFIR: %[[DES_V2:.*]] = hlfir.designate %[[DECL_V2]]#0 (%arg2:%arg3:%arg4, %arg5:%arg6:%arg7) shape %10 : (!fir.box<!fir.array<?x?xf32>>, index, index, index, index, index, index, !fir.shape<2>) -> !fir.box<!fir.array<?x?xf32>>
21+
! HLFIR: %[[ELEMENTAL:.*]] = hlfir.elemental %[[SHAPE]] unordered : (!fir.shape<2>) -> !hlfir.expr<?x?xf32> {
22+
! HLFIR: ^bb0(%[[ARG0:.*]]: index, %[[ARG1:.*]]: index):
23+
! HLFIR: %[[D1:.*]] = hlfir.designate %13 (%[[ARG0]], %[[ARG1]]) : (!fir.box<!fir.array<?x?xf32>>, index, index) -> !fir.ref<f32>
24+
! HLFIR: %[[D2:.*]] = hlfir.designate %14 (%[[ARG0]], %[[ARG1]]) : (!fir.box<!fir.array<?x?xf32>>, index, index) -> !fir.ref<f32>
25+
! HLFIR: %[[LOAD1:.*]] = fir.load %[[D1]] : !fir.ref<f32>
26+
! HLFIR: %[[LOAD2:.*]] = fir.load %[[D2]] : !fir.ref<f32>
27+
! HLFIR: %[[CMP:.*]] = arith.cmpf ogt, %[[LOAD1]], %[[LOAD2]] : f32
28+
! HLFIR: %[[SELECT:.*]] = arith.select %[[CMP]], %[[LOAD1]], %[[LOAD2]] : f32
29+
! HLFIR: hlfir.yield_element %[[SELECT]] : f32
30+
! HLFIR: }
31+
! HLFIR: hlfir.assign %[[ELEMENTAL]] to %[[DECL_V1]]#0 : !hlfir.expr<?x?xf32>, !fir.box<!fir.array<?x?xf32>>
32+
! HLFIR: acc.yield %[[V1]] : !fir.ref<!fir.array<?x?xf32>>
33+
! CHECK: }
34+
635
! CHECK-LABEL: acc.reduction.recipe @reduction_max_box_ptr_Uxf32 : !fir.box<!fir.ptr<!fir.array<?xf32>>> reduction_operator <max> init {
736
! CHECK: ^bb0(%{{.*}}: !fir.box<!fir.ptr<!fir.array<?xf32>>>):
837
! CHECK: } combiner {
@@ -290,8 +319,8 @@
290319
! CHECK-LABEL: acc.reduction.recipe @reduction_max_section_ext100_ref_100xf32 : !fir.ref<!fir.array<100xf32>> reduction_operator <max> init {
291320
! CHECK: ^bb0(%{{.*}}: !fir.ref<!fir.array<100xf32>>):
292321
! CHECK: %[[INIT:.*]] = arith.constant -1.401300e-45 : f32
293-
! CHECK: %[[ALLOCA:.*]] = fir.alloca !fir.array<100xf32>
294322
! HLFIR: %[[SHAPE:.*]] = fir.shape %{{.*}} : (index) -> !fir.shape<1>
323+
! CHECK: %[[ALLOCA:.*]] = fir.alloca !fir.array<100xf32>
295324
! HLFIR: %[[DECLARE:.*]]:2 = hlfir.declare %[[ALLOCA]](%[[SHAPE]]) {uniq_name = "acc.reduction.init"} : (!fir.ref<!fir.array<100xf32>>, !fir.shape<1>) -> (!fir.ref<!fir.array<100xf32>>, !fir.ref<!fir.array<100xf32>>)
296325
! CHECK: %[[LB:.*]] = arith.constant 0 : index
297326
! CHECK: %[[UB:.*]] = arith.constant 99 : index
@@ -338,8 +367,8 @@
338367
! CHECK-LABEL: acc.reduction.recipe @reduction_max_section_ext100xext10_ref_100x10xi32 : !fir.ref<!fir.array<100x10xi32>> reduction_operator <max> init {
339368
! CHECK: ^bb0(%arg0: !fir.ref<!fir.array<100x10xi32>>):
340369
! CHECK: %[[INIT:.*]] = arith.constant -2147483648 : i32
341-
! CHECK: %[[ALLOCA:.*]] = fir.alloca !fir.array<100x10xi32>
342370
! HLFIR: %[[SHAPE:.*]] = fir.shape %{{.*}}, %{{.*}} : (index, index) -> !fir.shape<2>
371+
! CHECK: %[[ALLOCA:.*]] = fir.alloca !fir.array<100x10xi32>
343372
! HLFIR: %[[DECLARE:.*]]:2 = hlfir.declare %[[ALLOCA]](%[[SHAPE]]) {uniq_name = "acc.reduction.init"} : (!fir.ref<!fir.array<100x10xi32>>, !fir.shape<2>) -> (!fir.ref<!fir.array<100x10xi32>>, !fir.ref<!fir.array<100x10xi32>>)
344373
! HLFIR: acc.yield %[[DECLARE]]#0 : !fir.ref<!fir.array<100x10xi32>>
345374
! CHECK: } combiner {
@@ -384,8 +413,8 @@
384413
! CHECK-LABEL: acc.reduction.recipe @reduction_min_section_ext100xext10_ref_100x10xf32 : !fir.ref<!fir.array<100x10xf32>> reduction_operator <min> init {
385414
! CHECK: ^bb0(%{{.*}}: !fir.ref<!fir.array<100x10xf32>>):
386415
! CHECK: %[[INIT:.*]] = arith.constant 3.40282347E+38 : f32
387-
! CHECK: %[[ALLOCA:.*]] = fir.alloca !fir.array<100x10xf32>
388416
! HLFIR: %[[SHAPE:.*]] = fir.shape %{{.*}}, %{{.*}} : (index, index) -> !fir.shape<2>
417+
! CHECK: %[[ALLOCA:.*]] = fir.alloca !fir.array<100x10xf32>
389418
! HLFIR: %[[DECLARE:.*]]:2 = hlfir.declare %[[ALLOCA]](%[[SHAPE]]) {uniq_name = "acc.reduction.init"} : (!fir.ref<!fir.array<100x10xf32>>, !fir.shape<2>) -> (!fir.ref<!fir.array<100x10xf32>>, !fir.ref<!fir.array<100x10xf32>>)
390419
! HLFIR: acc.yield %[[DECLARE]]#0 : !fir.ref<!fir.array<100x10xf32>>
391420
! CHECK: } combiner {
@@ -430,8 +459,8 @@
430459
! CHECK-LABEL: acc.reduction.recipe @reduction_min_section_ext100_ref_100xi32 : !fir.ref<!fir.array<100xi32>> reduction_operator <min> init {
431460
! CHECK: ^bb0(%{{.*}}: !fir.ref<!fir.array<100xi32>>):
432461
! CHECK: %[[INIT:.*]] = arith.constant 2147483647 : i32
433-
! CHECK: %[[ALLOCA:.*]] = fir.alloca !fir.array<100xi32>
434462
! HLFIR: %[[SHAPE:.*]] = fir.shape %{{.*}} : (index) -> !fir.shape<1>
463+
! CHECK: %[[ALLOCA:.*]] = fir.alloca !fir.array<100xi32>
435464
! HLFIR: %[[DECLARE:.*]]:2 = hlfir.declare %[[ALLOCA]](%[[SHAPE]]) {uniq_name = "acc.reduction.init"} : (!fir.ref<!fir.array<100xi32>>, !fir.shape<1>) -> (!fir.ref<!fir.array<100xi32>>, !fir.ref<!fir.array<100xi32>>)
436465
! HLFIR: acc.yield %[[DECLARE]]#0 : !fir.ref<!fir.array<100xi32>>
437466
! CHECK: } combiner {
@@ -487,8 +516,8 @@
487516
! CHECK-LABEL: acc.reduction.recipe @reduction_mul_section_ext100_ref_100xi32 : !fir.ref<!fir.array<100xi32>> reduction_operator <mul> init {
488517
! CHECK: ^bb0(%{{.*}}: !fir.ref<!fir.array<100xi32>>):
489518
! CHECK: %[[INIT:.*]] = arith.constant 1 : i32
490-
! CHECK: %[[ALLOCA:.*]] = fir.alloca !fir.array<100xi32>
491519
! HLFIR: %[[SHAPE:.*]] = fir.shape %{{.*}} : (index) -> !fir.shape<1>
520+
! CHECK: %[[ALLOCA:.*]] = fir.alloca !fir.array<100xi32>
492521
! HLFIR: %[[DECLARE:.*]]:2 = hlfir.declare %[[ALLOCA]](%[[SHAPE]]) {uniq_name = "acc.reduction.init"} : (!fir.ref<!fir.array<100xi32>>, !fir.shape<1>) -> (!fir.ref<!fir.array<100xi32>>, !fir.ref<!fir.array<100xi32>>)
493522
! HLFIR: acc.yield %[[DECLARE]]#0 : !fir.ref<!fir.array<100xi32>>
494523
! CHECK: } combiner {
@@ -526,8 +555,8 @@
526555
! CHECK-LABEL: acc.reduction.recipe @reduction_add_section_ext100_ref_100xf32 : !fir.ref<!fir.array<100xf32>> reduction_operator <add> init {
527556
! CHECK: ^bb0(%{{.*}}: !fir.ref<!fir.array<100xf32>>):
528557
! CHECK: %[[INIT:.*]] = arith.constant 0.000000e+00 : f32
529-
! CHECK: %[[ALLOCA:.*]] = fir.alloca !fir.array<100xf32>
530558
! HLFIR: %[[SHAPE:.*]] = fir.shape %{{.*}} : (index) -> !fir.shape<1>
559+
! CHECK: %[[ALLOCA:.*]] = fir.alloca !fir.array<100xf32>
531560
! HLFIR: %[[DECLARE:.*]]:2 = hlfir.declare %[[ALLOCA]](%[[SHAPE]]) {uniq_name = "acc.reduction.init"} : (!fir.ref<!fir.array<100xf32>>, !fir.shape<1>) -> (!fir.ref<!fir.array<100xf32>>, !fir.ref<!fir.array<100xf32>>)
532561
! HLFIR: acc.yield %[[DECLARE]]#0 : !fir.ref<!fir.array<100xf32>>
533562
! CHECK: } combiner {
@@ -565,8 +594,8 @@
565594
! CHECK-LABEL: acc.reduction.recipe @reduction_add_section_ext100xext10xext2_ref_100x10x2xi32 : !fir.ref<!fir.array<100x10x2xi32>> reduction_operator <add> init {
566595
! CHECK: ^bb0(%{{.*}}: !fir.ref<!fir.array<100x10x2xi32>>):
567596
! CHECK: %[[INIT:.*]] = arith.constant 0 : i32
568-
! CHECK: %[[ALLOCA:.*]] = fir.alloca !fir.array<100x10x2xi32>
569597
! HLFIR: %[[SHAPE:.*]] = fir.shape %{{.*}}, %{{.*}}, %{{.*}} : (index, index, index) -> !fir.shape<3>
598+
! CHECK: %[[ALLOCA:.*]] = fir.alloca !fir.array<100x10x2xi32>
570599
! HLFIR: %[[DECLARE:.*]]:2 = hlfir.declare %[[ALLOCA]](%[[SHAPE]]) {uniq_name = "acc.reduction.init"} : (!fir.ref<!fir.array<100x10x2xi32>>, !fir.shape<3>) -> (!fir.ref<!fir.array<100x10x2xi32>>, !fir.ref<!fir.array<100x10x2xi32>>)
571600
! HLFIR: acc.yield %[[DECLARE]]#0 : !fir.ref<!fir.array<100x10x2xi32>>
572601
! CHECK: } combiner {
@@ -598,8 +627,8 @@
598627
! CHECK-LABEL: acc.reduction.recipe @reduction_add_section_ext100xext10_ref_100x10xi32 : !fir.ref<!fir.array<100x10xi32>> reduction_operator <add> init {
599628
! CHECK: ^bb0(%{{.*}}: !fir.ref<!fir.array<100x10xi32>>):
600629
! CHECK: %[[INIT:.*]] = arith.constant 0 : i32
601-
! CHECK: %[[ALLOCA:.*]] = fir.alloca !fir.array<100x10xi32>
602630
! HLFIR: %[[SHAPE:.*]] = fir.shape %{{.*}}, %{{.*}} : (index, index) -> !fir.shape<2>
631+
! CHECK: %[[ALLOCA:.*]] = fir.alloca !fir.array<100x10xi32>
603632
! HLFIR: %[[DECLARE:.*]]:2 = hlfir.declare %[[ALLOCA]](%[[SHAPE]]) {uniq_name = "acc.reduction.init"} : (!fir.ref<!fir.array<100x10xi32>>, !fir.shape<2>) -> (!fir.ref<!fir.array<100x10xi32>>, !fir.ref<!fir.array<100x10xi32>>)
604633
! HLFIR: acc.yield %[[DECLARE]]#0 : !fir.ref<!fir.array<100x10xi32>>
605634
! CHECK: } combiner {
@@ -626,8 +655,8 @@
626655
! CHECK-LABEL: acc.reduction.recipe @reduction_add_section_ext100_ref_100xi32 : !fir.ref<!fir.array<100xi32>> reduction_operator <add> init {
627656
! CHECK: ^bb0(%{{.*}}: !fir.ref<!fir.array<100xi32>>):
628657
! CHECK: %[[INIT:.*]] = arith.constant 0 : i32
629-
! CHECK: %[[ALLOCA:.*]] = fir.alloca !fir.array<100xi32>
630658
! HLFIR: %[[SHAPE:.*]] = fir.shape %{{.*}} : (index) -> !fir.shape<1>
659+
! CHECK: %[[ALLOCA:.*]] = fir.alloca !fir.array<100xi32>
631660
! HLFIR: %[[DECLARE:.*]]:2 = hlfir.declare %[[ALLOCA]](%[[SHAPE]]) {uniq_name = "acc.reduction.init"} : (!fir.ref<!fir.array<100xi32>>, !fir.shape<1>) -> (!fir.ref<!fir.array<100xi32>>, !fir.ref<!fir.array<100xi32>>)
632661
! HFLIR: acc.yield %[[DECLARE]]#0 : !fir.ref<!fir.array<100xi32>>
633662
! CHECK: } combiner {
@@ -1134,13 +1163,13 @@ subroutine acc_reduction_add_dynamic_extent_add(a)
11341163
! HLFIR: %[[RED:.*]] = acc.reduction varPtr(%{{.*}} : !fir.ref<!fir.array<?xi32>>) bounds(%{{.*}}) -> !fir.ref<!fir.array<?xi32>> {name = "a"}
11351164
! HLFIR: acc.parallel reduction(@reduction_add_box_Uxi32 -> %[[RED:.*]] : !fir.ref<!fir.array<?xi32>>)
11361165

1137-
subroutine acc_reduction_add_dynamic_extent_max(a)
1166+
subroutine acc_reduction_add_assumed_shape_max(a)
11381167
real :: a(:)
11391168
!$acc parallel reduction(max:a)
11401169
!$acc end parallel
11411170
end subroutine
11421171

1143-
! CHECK-LABEL: func.func @_QPacc_reduction_add_dynamic_extent_max(
1172+
! CHECK-LABEL: func.func @_QPacc_reduction_add_assumed_shape_max(
11441173
! CHECK-SAME: %[[ARG0:.*]]: !fir.box<!fir.array<?xf32>> {fir.bindc_name = "a"})
11451174
! HLFIR: %[[DECLARG0:.*]]:2 = hlfir.declare %[[ARG0]]
11461175
! HLFIR: %[[RED:.*]] = acc.reduction varPtr(%{{.*}} : !fir.ref<!fir.array<?xf32>>) bounds(%{{.*}}) -> !fir.ref<!fir.array<?xf32>> {name = "a"}
@@ -1189,3 +1218,16 @@ subroutine acc_reduction_add_pointer_array(a)
11891218
! HLFIR: %[[BOX_ADDR:.*]] = fir.box_addr %[[BOX]] : (!fir.box<!fir.ptr<!fir.array<?xf32>>>) -> !fir.ptr<!fir.array<?xf32>>
11901219
! HLFIR: %[[RED:.*]] = acc.reduction varPtr(%[[BOX_ADDR]] : !fir.ptr<!fir.array<?xf32>>) bounds(%[[BOUND]]) -> !fir.ptr<!fir.array<?xf32>> {name = "a"}
11911220
! HLFIR: acc.parallel reduction(@reduction_max_box_ptr_Uxf32 -> %[[RED]] : !fir.ptr<!fir.array<?xf32>>)
1221+
1222+
subroutine acc_reduction_max_dynamic_extent_max(a, n)
1223+
integer :: n
1224+
real :: a(n, n)
1225+
!$acc parallel reduction(max:a)
1226+
!$acc end parallel
1227+
end subroutine
1228+
1229+
! CHECK-LABEL: func.func @_QPacc_reduction_max_dynamic_extent_max(
1230+
! CHECK-SAME: %[[ARG0:.*]]: !fir.ref<!fir.array<?x?xf32>> {fir.bindc_name = "a"}, %{{.*}}: !fir.ref<i32> {fir.bindc_name = "n"})
1231+
! HLFIR: %[[DECL_A:.*]]:2 = hlfir.declare %[[ARG0]](%{{.*}}) {uniq_name = "_QFacc_reduction_max_dynamic_extent_maxEa"} : (!fir.ref<!fir.array<?x?xf32>>, !fir.shape<2>) -> (!fir.box<!fir.array<?x?xf32>>, !fir.ref<!fir.array<?x?xf32>>)
1232+
! HLFIR: %[[RED:.*]] = acc.reduction varPtr(%[[DECL_A]]#1 : !fir.ref<!fir.array<?x?xf32>>) bounds(%{{.*}}, %{{.*}}) -> !fir.ref<!fir.array<?x?xf32>> {name = "a"}
1233+
! HLFIR: acc.parallel reduction(@reduction_max_ref_UxUxf32 -> %[[RED]] : !fir.ref<!fir.array<?x?xf32>>)

0 commit comments

Comments
 (0)