Skip to content

Commit 18bf0c3

Browse files
authored
[flang][OpenMP] fix reduction of arrays with non-default lower bounds (#89611)
It turned out that `hlfir::genVariableBox` didn't add lower bounds to the boxes it created. Using a shapeshift instead of only a shape adds the lower bounds information to the thread-local copy of the box. Fixes #89259
1 parent 486ea1e commit 18bf0c3

9 files changed

+174
-45
lines changed

flang/lib/Lower/OpenMP/ReductionProcessor.cpp

Lines changed: 49 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,33 @@ mlir::Value ReductionProcessor::createScalarCombiner(
295295
return reductionOp;
296296
}
297297

298+
/// Generate a fir::ShapeShift op describing the provided boxed array.
299+
static fir::ShapeShiftOp getShapeShift(fir::FirOpBuilder &builder,
300+
mlir::Location loc, mlir::Value box) {
301+
fir::SequenceType sequenceType = mlir::cast<fir::SequenceType>(
302+
hlfir::getFortranElementOrSequenceType(box.getType()));
303+
const unsigned rank = sequenceType.getDimension();
304+
llvm::SmallVector<mlir::Value> lbAndExtents;
305+
lbAndExtents.reserve(rank * 2);
306+
307+
mlir::Type idxTy = builder.getIndexType();
308+
for (unsigned i = 0; i < rank; ++i) {
309+
// TODO: ideally we want to hoist box reads out of the critical section.
310+
// We could do this by having box dimensions in block arguments like
311+
// OpenACC does
312+
mlir::Value dim = builder.createIntegerConstant(loc, idxTy, i);
313+
auto dimInfo =
314+
builder.create<fir::BoxDimsOp>(loc, idxTy, idxTy, idxTy, box, dim);
315+
lbAndExtents.push_back(dimInfo.getLowerBound());
316+
lbAndExtents.push_back(dimInfo.getExtent());
317+
}
318+
319+
auto shapeShiftTy = fir::ShapeShiftType::get(builder.getContext(), rank);
320+
auto shapeShift =
321+
builder.create<fir::ShapeShiftOp>(loc, shapeShiftTy, lbAndExtents);
322+
return shapeShift;
323+
}
324+
298325
/// Create reduction combiner region for reduction variables which are boxed
299326
/// arrays
300327
static void genBoxCombiner(fir::FirOpBuilder &builder, mlir::Location loc,
@@ -330,29 +357,7 @@ static void genBoxCombiner(fir::FirOpBuilder &builder, mlir::Location loc,
330357
return;
331358
}
332359

333-
const unsigned rank = seqTy.getDimension();
334-
llvm::SmallVector<mlir::Value> extents;
335-
extents.reserve(rank);
336-
llvm::SmallVector<mlir::Value> lbAndExtents;
337-
lbAndExtents.reserve(rank * 2);
338-
339-
// Get box lowerbounds and extents:
340-
mlir::Type idxTy = builder.getIndexType();
341-
for (unsigned i = 0; i < rank; ++i) {
342-
// TODO: ideally we want to hoist box reads out of the critical section.
343-
// We could do this by having box dimensions in block arguments like
344-
// OpenACC does
345-
mlir::Value dim = builder.createIntegerConstant(loc, idxTy, i);
346-
auto dimInfo =
347-
builder.create<fir::BoxDimsOp>(loc, idxTy, idxTy, idxTy, lhs, dim);
348-
extents.push_back(dimInfo.getExtent());
349-
lbAndExtents.push_back(dimInfo.getLowerBound());
350-
lbAndExtents.push_back(dimInfo.getExtent());
351-
}
352-
353-
auto shapeShiftTy = fir::ShapeShiftType::get(builder.getContext(), rank);
354-
auto shapeShift =
355-
builder.create<fir::ShapeShiftOp>(loc, shapeShiftTy, lbAndExtents);
360+
fir::ShapeShiftOp shapeShift = getShapeShift(builder, loc, lhs);
356361

357362
// Iterate over array elements, applying the equivalent scalar reduction:
358363

@@ -364,8 +369,8 @@ static void genBoxCombiner(fir::FirOpBuilder &builder, mlir::Location loc,
364369
// loop nest directly.
365370
// This function already controls all of the code in this region so we
366371
// know this won't miss any opportuinties for clever elemental inlining
367-
hlfir::LoopNest nest =
368-
hlfir::genLoopNest(loc, builder, extents, /*isUnordered=*/true);
372+
hlfir::LoopNest nest = hlfir::genLoopNest(
373+
loc, builder, shapeShift.getExtents(), /*isUnordered=*/true);
369374
builder.setInsertionPointToStart(nest.innerLoop.getBody());
370375
mlir::Type refTy = fir::ReferenceType::get(seqTy.getEleTy());
371376
auto lhsEleAddr = builder.create<fir::ArrayCoorOp>(
@@ -561,7 +566,8 @@ createReductionInitRegion(fir::FirOpBuilder &builder, mlir::Location loc,
561566
}
562567

563568
// Create the private copy from the initial fir.box:
564-
hlfir::Entity source = hlfir::Entity{blockArg};
569+
mlir::Value loadedBox = builder.loadIfRef(loc, blockArg);
570+
hlfir::Entity source = hlfir::Entity{loadedBox};
565571

566572
// Allocating on the heap in case the whole reduction is nested inside of a
567573
// loop
@@ -585,11 +591,23 @@ createReductionInitRegion(fir::FirOpBuilder &builder, mlir::Location loc,
585591
}
586592

587593
// Put the temporary inside of a box:
588-
hlfir::Entity box = hlfir::genVariableBox(loc, builder, temp);
589-
// hlfir::genVariableBox removes fir.heap<> around the element type
590-
mlir::Value convertedBox = builder.createConvert(loc, ty, box.getBase());
591-
builder.create<hlfir::AssignOp>(loc, initValue, convertedBox);
592-
builder.create<fir::StoreOp>(loc, convertedBox, boxAlloca);
594+
// hlfir::genVariableBox doesn't handle non-default lower bounds
595+
mlir::Value box;
596+
fir::ShapeShiftOp shapeShift = getShapeShift(builder, loc, loadedBox);
597+
mlir::Type boxType = loadedBox.getType();
598+
if (mlir::isa<fir::BaseBoxType>(temp.getType()))
599+
// the box created by the declare form createTempFromMold is missing lower
600+
// bounds info
601+
box = builder.create<fir::ReboxOp>(loc, boxType, temp, shapeShift,
602+
/*shift=*/mlir::Value{});
603+
else
604+
box = builder.create<fir::EmboxOp>(
605+
loc, boxType, temp, shapeShift,
606+
/*slice=*/mlir::Value{},
607+
/*typeParams=*/llvm::ArrayRef<mlir::Value>{});
608+
609+
builder.create<hlfir::AssignOp>(loc, initValue, box);
610+
builder.create<fir::StoreOp>(loc, box, boxAlloca);
593611
if (ifUnallocated)
594612
builder.setInsertionPointAfter(ifUnallocated);
595613
return boxAlloca;

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,12 @@ program reduce
3737
! CHECK: %[[VAL_6:.*]] = fir.allocmem !fir.array<?xi32>, %[[VAL_4]]#1 {bindc_name = ".tmp", uniq_name = ""}
3838
! CHECK: %[[VAL_7:.*]] = arith.constant true
3939
! CHECK: %[[VAL_8:.*]]:2 = hlfir.declare %[[VAL_6]](%[[VAL_5]]) {uniq_name = ".tmp"} : (!fir.heap<!fir.array<?xi32>>, !fir.shape<1>) -> (!fir.box<!fir.array<?xi32>>, !fir.heap<!fir.array<?xi32>>)
40-
! CHECK: %[[VAL_9:.*]] = fir.convert %[[VAL_8]]#0 : (!fir.box<!fir.array<?xi32>>) -> !fir.box<!fir.heap<!fir.array<?xi32>>>
41-
! CHECK: hlfir.assign %[[VAL_1]] to %[[VAL_9]] : i32, !fir.box<!fir.heap<!fir.array<?xi32>>>
42-
! CHECK: fir.store %[[VAL_9]] to %[[VAL_10]] : !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>
40+
! CHECK: %[[C0:.*]] = arith.constant 0 : index
41+
! CHECK: %[[DIMS:.*]]:3 = fir.box_dims %[[VAL_2]], %[[C0]] : (!fir.box<!fir.heap<!fir.array<?xi32>>>, index) -> (index, index, index)
42+
! CHECK: %[[SHIFT:.*]] = fir.shape_shift %[[DIMS]]#0, %[[DIMS]]#1 : (index, index) -> !fir.shapeshift<1>
43+
! CHECK: %[[REBOX:.*]] = fir.rebox %[[VAL_8]]#0(%[[SHIFT]]) : (!fir.box<!fir.array<?xi32>>, !fir.shapeshift<1>) -> !fir.box<!fir.heap<!fir.array<?xi32>>>
44+
! 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>>>>
4346
! CHECK: }
4447
! CHECK: omp.yield(%[[VAL_10]] : !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>)
4548
! CHECK: } combiner {
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
! RUN: bbc -emit-hlfir -fopenmp -o - %s 2>&1 | FileCheck %s
2+
! RUN: %flang_fc1 -emit-hlfir -fopenmp -o - %s 2>&1 | FileCheck %s
3+
4+
program reduce
5+
integer, dimension(2:4, 2) :: i = 0
6+
7+
!$omp parallel reduction(+:i)
8+
i(3, 1) = 3
9+
!$omp end parallel
10+
11+
print *,i
12+
13+
end program
14+
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>>>):
17+
! CHECK: %[[VAL_1:.*]] = arith.constant 0 : i32
18+
! 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>>
20+
! CHECK: %[[VAL_3:.*]] = arith.constant 3 : index
21+
! CHECK: %[[VAL_4:.*]] = arith.constant 2 : index
22+
! CHECK: %[[VAL_5:.*]] = fir.shape %[[VAL_3]], %[[VAL_4]] : (index, index) -> !fir.shape<2>
23+
! CHECK: %[[VAL_6:.*]] = fir.allocmem !fir.array<3x2xi32> {bindc_name = ".tmp", uniq_name = ""}
24+
! CHECK: %[[VAL_7:.*]] = arith.constant true
25+
! CHECK: %[[VAL_8:.*]]:2 = hlfir.declare %[[VAL_6]](%[[VAL_5]]) {uniq_name = ".tmp"} : (!fir.heap<!fir.array<3x2xi32>>, !fir.shape<2>) -> (!fir.heap<!fir.array<3x2xi32>>, !fir.heap<!fir.array<3x2xi32>>)
26+
! CHECK: %[[VAL_9:.*]] = arith.constant 0 : index
27+
! CHECK: %[[VAL_10:.*]]:3 = fir.box_dims %[[VAL_2]], %[[VAL_9]] : (!fir.box<!fir.array<3x2xi32>>, index) -> (index, index, index)
28+
! CHECK: %[[VAL_11:.*]] = arith.constant 1 : index
29+
! CHECK: %[[VAL_12:.*]]:3 = fir.box_dims %[[VAL_2]], %[[VAL_11]] : (!fir.box<!fir.array<3x2xi32>>, index) -> (index, index, index)
30+
! 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>
31+
! CHECK: %[[VAL_14:.*]] = fir.embox %[[VAL_8]]#0(%[[VAL_13]]) : (!fir.heap<!fir.array<3x2xi32>>, !fir.shapeshift<2>) -> !fir.box<!fir.array<3x2xi32>>
32+
! 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: } combiner {
36+
! CHECK: ^bb0(%[[VAL_0:.*]]: !fir.ref<!fir.box<!fir.array<3x2xi32>>>, %[[VAL_1:.*]]: !fir.ref<!fir.box<!fir.array<3x2xi32>>>):
37+
! CHECK: %[[VAL_2:.*]] = fir.load %[[VAL_0]] : !fir.ref<!fir.box<!fir.array<3x2xi32>>>
38+
! CHECK: %[[VAL_3:.*]] = fir.load %[[VAL_1]] : !fir.ref<!fir.box<!fir.array<3x2xi32>>>
39+
! CHECK: %[[VAL_4:.*]] = arith.constant 0 : index
40+
! CHECK: %[[VAL_5:.*]]:3 = fir.box_dims %[[VAL_2]], %[[VAL_4]] : (!fir.box<!fir.array<3x2xi32>>, index) -> (index, index, index)
41+
! CHECK: %[[VAL_6:.*]] = arith.constant 1 : index
42+
! CHECK: %[[VAL_7:.*]]:3 = fir.box_dims %[[VAL_2]], %[[VAL_6]] : (!fir.box<!fir.array<3x2xi32>>, index) -> (index, index, index)
43+
! CHECK: %[[VAL_8:.*]] = fir.shape_shift %[[VAL_5]]#0, %[[VAL_5]]#1, %[[VAL_7]]#0, %[[VAL_7]]#1 : (index, index, index, index) -> !fir.shapeshift<2>
44+
! CHECK: %[[VAL_9:.*]] = arith.constant 1 : index
45+
! CHECK: fir.do_loop %[[VAL_10:.*]] = %[[VAL_9]] to %[[VAL_7]]#1 step %[[VAL_9]] unordered {
46+
! CHECK: fir.do_loop %[[VAL_11:.*]] = %[[VAL_9]] to %[[VAL_5]]#1 step %[[VAL_9]] unordered {
47+
! CHECK: %[[VAL_12:.*]] = fir.array_coor %[[VAL_2]](%[[VAL_8]]) %[[VAL_11]], %[[VAL_10]] : (!fir.box<!fir.array<3x2xi32>>, !fir.shapeshift<2>, index, index) -> !fir.ref<i32>
48+
! CHECK: %[[VAL_13:.*]] = fir.array_coor %[[VAL_3]](%[[VAL_8]]) %[[VAL_11]], %[[VAL_10]] : (!fir.box<!fir.array<3x2xi32>>, !fir.shapeshift<2>, index, index) -> !fir.ref<i32>
49+
! CHECK: %[[VAL_14:.*]] = fir.load %[[VAL_12]] : !fir.ref<i32>
50+
! CHECK: %[[VAL_15:.*]] = fir.load %[[VAL_13]] : !fir.ref<i32>
51+
! CHECK: %[[VAL_16:.*]] = arith.addi %[[VAL_14]], %[[VAL_15]] : i32
52+
! CHECK: fir.store %[[VAL_16]] to %[[VAL_12]] : !fir.ref<i32>
53+
! CHECK: }
54+
! CHECK: }
55+
! CHECK: omp.yield(%[[VAL_0]] : !fir.ref<!fir.box<!fir.array<3x2xi32>>>)
56+
! CHECK: } cleanup {
57+
! CHECK: ^bb0(%[[VAL_0:.*]]: !fir.ref<!fir.box<!fir.array<3x2xi32>>>):
58+
! CHECK: %[[VAL_1:.*]] = fir.load %[[VAL_0]] : !fir.ref<!fir.box<!fir.array<3x2xi32>>>
59+
! CHECK: %[[VAL_2:.*]] = fir.box_addr %[[VAL_1]] : (!fir.box<!fir.array<3x2xi32>>) -> !fir.ref<!fir.array<3x2xi32>>
60+
! CHECK: %[[VAL_3:.*]] = fir.convert %[[VAL_2]] : (!fir.ref<!fir.array<3x2xi32>>) -> i64
61+
! CHECK: %[[VAL_4:.*]] = arith.constant 0 : i64
62+
! CHECK: %[[VAL_5:.*]] = arith.cmpi ne, %[[VAL_3]], %[[VAL_4]] : i64
63+
! CHECK: fir.if %[[VAL_5]] {
64+
! CHECK: %[[VAL_6:.*]] = fir.convert %[[VAL_2]] : (!fir.ref<!fir.array<3x2xi32>>) -> !fir.heap<!fir.array<3x2xi32>>
65+
! CHECK: fir.freemem %[[VAL_6]] : !fir.heap<!fir.array<3x2xi32>>
66+
! CHECK: }
67+
! CHECK: omp.yield
68+
! CHECK: }
69+
70+
! CHECK-LABEL: func.func @_QQmain() attributes {fir.bindc_name = "reduce"} {
71+
! CHECK: %[[VAL_0:.*]] = fir.address_of(@_QFEi) : !fir.ref<!fir.array<3x2xi32>>
72+
! CHECK: %[[VAL_1:.*]] = arith.constant 2 : index
73+
! CHECK: %[[VAL_2:.*]] = arith.constant 3 : index
74+
! CHECK: %[[VAL_3:.*]] = arith.constant 1 : index
75+
! CHECK: %[[VAL_4:.*]] = arith.constant 2 : index
76+
! CHECK: %[[VAL_5:.*]] = fir.shape_shift %[[VAL_1]], %[[VAL_2]], %[[VAL_3]], %[[VAL_4]] : (index, index, index, index) -> !fir.shapeshift<2>
77+
! CHECK: %[[VAL_6:.*]]:2 = hlfir.declare %[[VAL_0]](%[[VAL_5]]) {uniq_name = "_QFEi"} : (!fir.ref<!fir.array<3x2xi32>>, !fir.shapeshift<2>) -> (!fir.box<!fir.array<3x2xi32>>, !fir.ref<!fir.array<3x2xi32>>)
78+
! CHECK: %[[VAL_7:.*]] = fir.alloca !fir.box<!fir.array<3x2xi32>>
79+
! CHECK: fir.store %[[VAL_6]]#0 to %[[VAL_7]] : !fir.ref<!fir.box<!fir.array<3x2xi32>>>
80+
! CHECK: omp.parallel byref reduction(@add_reduction_byref_box_3x2xi32 %[[VAL_7]] -> %[[VAL_8:.*]] : !fir.ref<!fir.box<!fir.array<3x2xi32>>>) {
81+
! CHECK: %[[VAL_9:.*]]:2 = hlfir.declare %[[VAL_8]] {uniq_name = "_QFEi"} : (!fir.ref<!fir.box<!fir.array<3x2xi32>>>) -> (!fir.ref<!fir.box<!fir.array<3x2xi32>>>, !fir.ref<!fir.box<!fir.array<3x2xi32>>>)
82+
! CHECK: %[[VAL_10:.*]] = arith.constant 3 : i32
83+
! CHECK: %[[VAL_11:.*]] = fir.load %[[VAL_9]]#0 : !fir.ref<!fir.box<!fir.array<3x2xi32>>>
84+
! CHECK: %[[VAL_12:.*]] = arith.constant 3 : index
85+
! CHECK: %[[VAL_13:.*]] = arith.constant 1 : index
86+
! CHECK: %[[VAL_14:.*]] = hlfir.designate %[[VAL_11]] (%[[VAL_12]], %[[VAL_13]]) : (!fir.box<!fir.array<3x2xi32>>, index, index) -> !fir.ref<i32>
87+
! CHECK: hlfir.assign %[[VAL_10]] to %[[VAL_14]] : i32, !fir.ref<i32>
88+
! CHECK: omp.terminator
89+
! CHECK: }
90+

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ program reduce
2424
! CHECK: %[[TRUE:.*]] = arith.constant true
2525
! CHECK: %[[VAL_6:.*]]:2 = hlfir.declare %[[VAL_1]](%[[VAL_5]]) {uniq_name = ".tmp"} : (!fir.heap<!fir.array<3xi32>>,
2626
!fir.shape<1>) -> (!fir.heap<!fir.array<3xi32>>, !fir.heap<!fir.array<3xi32>>)
27-
! CHECK: %[[VAL_7:.*]] = fir.embox %[[VAL_6]]#0(%[[VAL_5]]) : (!fir.heap<!fir.array<3xi32>>, !fir.shape<1>) -> !fir.box<!fir.array<3xi32>>
27+
! CHECK: %[[C0:.*]] = arith.constant 0 : index
28+
! CHECK: %[[DIMS:.*]]:3 = fir.box_dims %[[VAL_3]], %[[C0]] : (!fir.box<!fir.array<3xi32>>, index) -> (index, index, index)
29+
! CHECK: %[[SHIFT:.*]] = fir.shape_shift %[[DIMS]]#0, %[[DIMS]]#1 : (index, index) -> !fir.shapeshift<1>
30+
! CHECK: %[[VAL_7:.*]] = fir.embox %[[VAL_6]]#0(%[[SHIFT]]) : (!fir.heap<!fir.array<3xi32>>, !fir.shapeshift<1>) -> !fir.box<!fir.array<3xi32>>
2831
! CHECK: hlfir.assign %[[VAL_2]] to %[[VAL_7]] : i32, !fir.box<!fir.array<3xi32>>
2932
! CHECK: fir.store %[[VAL_7]] to %[[VAL_8]] : !fir.ref<!fir.box<!fir.array<3xi32>>>
3033
! CHECK: omp.yield(%[[VAL_8]] : !fir.ref<!fir.box<!fir.array<3xi32>>>)

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ program reduce
2222
! CHECK: %[[VAL_5:.*]] = fir.shape %[[VAL_4]] : (index) -> !fir.shape<1>
2323
! CHECK: %[[VAL_1:.*]] = fir.allocmem !fir.array<3xi32>
2424
! CHECK: %[[TRUE:.*]] = arith.constant true
25-
! CHECK: %[[VAL_6:.*]]:2 = hlfir.declare %[[VAL_1]](%[[VAL_5]]) {uniq_name = ".tmp"} : (!fir.heap<!fir.array<3xi32>>,
26-
!fir.shape<1>) -> (!fir.heap<!fir.array<3xi32>>, !fir.heap<!fir.array<3xi32>>)
27-
! CHECK: %[[VAL_7:.*]] = fir.embox %[[VAL_6]]#0(%[[VAL_5]]) : (!fir.heap<!fir.array<3xi32>>, !fir.shape<1>) -> !fir.box<!fir.array<3xi32>>
25+
! CHECK: %[[VAL_6:.*]]:2 = hlfir.declare %[[VAL_1]](%[[VAL_5]]) {uniq_name = ".tmp"} : (!fir.heap<!fir.array<3xi32>>, !fir.shape<1>) -> (!fir.heap<!fir.array<3xi32>>, !fir.heap<!fir.array<3xi32>>)
26+
! CHECK: %[[C0:.*]] = arith.constant 0 : index
27+
! CHECK: %[[DIMS:.*]]:3 = fir.box_dims %[[VAL_3]], %[[C0]] : (!fir.box<!fir.array<3xi32>>, index) -> (index, index, index)
28+
! CHECK: %[[SHIFT:.*]] = fir.shape_shift %[[DIMS]]#0, %[[DIMS]]#1 : (index, index) -> !fir.shapeshift<1>
29+
! CHECK: %[[VAL_7:.*]] = fir.embox %[[VAL_6]]#0(%[[SHIFT]]) : (!fir.heap<!fir.array<3xi32>>, !fir.shapeshift<1>) -> !fir.box<!fir.array<3xi32>>
2830
! CHECK: hlfir.assign %[[VAL_2]] to %[[VAL_7]] : i32, !fir.box<!fir.array<3xi32>>
2931
! CHECK: fir.store %[[VAL_7]] to %[[VAL_8]] : !fir.ref<!fir.box<!fir.array<3xi32>>>
3032
! CHECK: omp.yield(%[[VAL_8]] : !fir.ref<!fir.box<!fir.array<3xi32>>>)

flang/test/Lower/OpenMP/parallel-reduction3.f90

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,12 @@
1212
! CHECK: %[[VAL_6:.*]] = fir.allocmem !fir.array<?xi32>, %[[VAL_4]]#1 {bindc_name = ".tmp", uniq_name = ""}
1313
! CHECK: %[[TRUE:.*]] = arith.constant true
1414
! CHECK: %[[VAL_7:.*]]:2 = hlfir.declare %[[VAL_6]](%[[VAL_5]]) {uniq_name = ".tmp"} : (!fir.heap<!fir.array<?xi32>>, !fir.shape<1>) -> (!fir.box<!fir.array<?xi32>>, !fir.heap<!fir.array<?xi32>>)
15-
! CHECK: hlfir.assign %[[VAL_1]] to %[[VAL_7]]#0 : i32, !fir.box<!fir.array<?xi32>>
16-
! CHECK: fir.store %[[VAL_7]]#0 to %[[VAL_8]] : !fir.ref<!fir.box<!fir.array<?xi32>>>
15+
! CHECK: %[[C0:.*]] = arith.constant 0 : index
16+
! CHECK: %[[DIMS:.*]]:3 = fir.box_dims %[[VAL_2]], %[[C0]] : (!fir.box<!fir.array<?xi32>>, index) -> (index, index, index)
17+
! CHECK: %[[SHIFT:.*]] = fir.shape_shift %[[DIMS]]#0, %[[DIMS]]#1 : (index, index) -> !fir.shapeshift<1>
18+
! CHECK: %[[REBOX:.*]] = fir.rebox %[[VAL_7]]#0(%[[SHIFT]]) : (!fir.box<!fir.array<?xi32>>, !fir.shapeshift<1>) -> !fir.box<!fir.array<?xi32>>
19+
! CHECK: hlfir.assign %[[VAL_1]] to %[[REBOX]] : i32, !fir.box<!fir.array<?xi32>>
20+
! CHECK: fir.store %[[REBOX]] to %[[VAL_8]] : !fir.ref<!fir.box<!fir.array<?xi32>>>
1721
! CHECK: omp.yield(%[[VAL_8]] : !fir.ref<!fir.box<!fir.array<?xi32>>>)
1822
! CHECK: } combiner {
1923
! CHECK: ^bb0(%[[VAL_0:.*]]: !fir.ref<!fir.box<!fir.array<?xi32>>>, %[[VAL_1:.*]]: !fir.ref<!fir.box<!fir.array<?xi32>>>):

flang/test/Lower/OpenMP/wsloop-reduction-array-assumed-shape.f90

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,13 @@ subroutine reduce(r)
3333
! CHECK: %[[VAL_6:.*]] = fir.allocmem !fir.array<?xf64>, %[[VAL_4]]#1 {bindc_name = ".tmp", uniq_name = ""}
3434
! CHECK: %[[TRUE:.*]] = arith.constant true
3535
! CHECK: %[[VAL_7:.*]]:2 = hlfir.declare %[[VAL_6]](%[[VAL_5]]) {uniq_name = ".tmp"} : (!fir.heap<!fir.array<?xf64>>, !fir.shape<1>) -> (!fir.box<!fir.array<?xf64>>, !fir.heap<!fir.array<?xf64>>)
36-
! CHECK: hlfir.assign %[[VAL_1]] to %[[VAL_7]]#0 : f64, !fir.box<!fir.array<?xf64>>
37-
! CHECK: fir.store %[[VAL_7]]#0 to %[[VAL_8]] : !fir.ref<!fir.box<!fir.array<?xf64>>>
36+
! CHECK: %[[C0:.*]] = arith.constant 0 : index
37+
! CHECK: %[[DIMS:.*]]:3 = fir.box_dims %[[VAL_2]], %[[C0]] : (!fir.box<!fir.array<?xf64>>, index) -> (index, index, index)
38+
! CHECK: %[[SHIFT:.*]] = fir.shape_shift %[[DIMS]]#0, %[[DIMS]]#1 : (index, index) -> !fir.shapeshift<1>
39+
! CHECK: %[[REBOX:.*]] = fir.rebox %[[VAL_7]]#0(%[[SHIFT]]) : (!fir.box<!fir.array<?xf64>>, !fir.shapeshift<1>) -> !fir.box<!fir.array<?xf64>
40+
! CHECK: hlfir.assign %[[VAL_1]] to %[[REBOX]] : f64, !fir.box<!fir.array<?xf64>>
41+
! CHECK: fir.store %[[REBOX]] to %[[VAL_8]] : !fir.ref<!fir.box<!fir.array<?xf64>>>
3842
! CHECK: omp.yield(%[[VAL_8]] : !fir.ref<!fir.box<!fir.array<?xf64>>>)
39-
4043
! CHECK-LABEL: } combiner {
4144
! CHECK: ^bb0(%[[VAL_0:.*]]: !fir.ref<!fir.box<!fir.array<?xf64>>>, %[[VAL_1:.*]]: !fir.ref<!fir.box<!fir.array<?xf64>>>):
4245
! CHECK: %[[VAL_2:.*]] = fir.load %[[VAL_0]] : !fir.ref<!fir.box<!fir.array<?xf64>>>

0 commit comments

Comments
 (0)