Skip to content

Commit 1581a4b

Browse files
authored
[flang][acc] Fix mappableTy.generateAccBounds to correctly handle dynamic-sized arrays (#155666)
We currently see the misuse of the `upperbound` operand for the `acc::DataBoundsOp` generation in `generateSeqTyAccBounds`. This PR keeps setting `lowerbound` to zero for all cases and adjusts `upperbound` to be `extent - 1`.
1 parent b8aeec1 commit 1581a4b

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

flang/lib/Optimizer/OpenACC/Support/FIROpenACCTypeInterfaces.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,6 @@ generateSeqTyAccBounds(fir::SequenceType seqType, mlir::Value var,
271271
mlir::Value extent = val;
272272
mlir::Value upperbound =
273273
mlir::arith::SubIOp::create(builder, loc, extent, one);
274-
upperbound = mlir::arith::AddIOp::create(builder, loc, lowerbound,
275-
upperbound);
276274
mlir::Value stride = one;
277275
if (strideIncludeLowerExtent) {
278276
stride = cummulativeExtent;

flang/test/Fir/OpenACC/openacc-mappable.fir

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,26 @@ module attributes {dlti.dl_spec = #dlti.dl_spec<f16 = dense<16> : vector<2xi64>,
6262
// CHECK: Visiting: %{{.*}} = acc.copyin varPtr(%{{.*}} : !fir.ref<!fir.array<?xf32>>) -> !fir.ref<!fir.array<?xf32>> {name = "arr1", structured = false}
6363
// CHECK: Pointer-like and Mappable: !fir.ref<!fir.array<?xf32>>
6464
// CHECK: Type category: array
65-
// CHECK: Bound[0]: %{{.*}} = acc.bounds lowerbound(%c0{{.*}} : index) upperbound(%{{.*}} : index) extent(%{{.*}} : index) stride(%c1{{.*}} : index) startIdx(%c1{{.*}} : index)
65+
// CHECK: Shape: %{{.*}} = fir.shape %[[EXTENT1:.*]] : (index) -> !fir.shape<1>
66+
// CHECK: Bound[0]: %{{.*}} = acc.bounds lowerbound(%[[LB1:.*]] : index) upperbound(%[[UB1:.*]] : index) extent(%{{.*}} : index) stride(%c1{{.*}} : index) startIdx(%c1{{.*}} : index)
67+
// CHECK: Lower bound: %[[LB1]] = arith.constant 0 : index
68+
// CHECK: Upper bound: %[[UB1]] = arith.subi %[[EXTENT1]], %c1{{.*}} : index
6669

6770
// CHECK: Visiting: %{{.*}} = acc.copyin varPtr(%{{.*}} : !fir.ref<!fir.array<?xf32>>) -> !fir.ref<!fir.array<?xf32>> {name = "arr2", structured = false}
6871
// CHECK: Pointer-like and Mappable: !fir.ref<!fir.array<?xf32>>
6972
// CHECK: Type category: array
70-
// CHECK: Bound[0]: %{{.*}} = acc.bounds lowerbound(%c0{{.*}} : index) upperbound(%{{.*}} : index) extent(%{{.*}} : index) stride(%c1{{.*}} : index) startIdx(%c2{{.*}} : index)
73+
// CHECK: Shape: %{{.*}} = fir.shape_shift %c2{{.*}}, %[[EXTENT2:.*]] : (index, index) -> !fir.shapeshift<1>
74+
// CHECK: Bound[0]: %{{.*}} = acc.bounds lowerbound(%[[LB2:.*]] : index) upperbound(%[[UB2:.*]] : index) extent(%{{.*}} : index) stride(%c1{{.*}} : index) startIdx(%c2{{.*}} : index)
75+
// CHECK: Lower bound: %[[LB2]] = arith.constant 0 : index
76+
// CHECK: Upper bound: %[[UB2]] = arith.subi %[[EXTENT2]], %c1{{.*}} : index
7177

7278
// CHECK: Visiting: %{{.*}} = acc.copyin varPtr(%{{.*}} : !fir.ref<!fir.array<10xf32>>) -> !fir.ref<!fir.array<10xf32>> {name = "arr3", structured = false}
7379
// CHECK: Pointer-like and Mappable: !fir.ref<!fir.array<10xf32>>
7480
// CHECK: Type category: array
7581
// CHECK: Size: 40
7682
// CHECK: Offset: 0
77-
// CHECK: Bound[0]: %{{.*}} = acc.bounds lowerbound(%c0{{.*}} : index) upperbound(%{{.*}} : index) extent(%c10{{.*}} : index) stride(%c1{{.*}} : index) startIdx(%c1{{.*}} : index)
83+
// CHECK: Shape: %{{.*}} = fir.shape %[[EXTENT3:.*]] : (index) -> !fir.shape<1>
84+
// CHECK: Bound[0]: %{{.*}} = acc.bounds lowerbound(%[[LB3:.*]] : index) upperbound(%[[UB3:.*]] : index) extent(%c10{{.*}} : index) stride(%c1{{.*}} : index) startIdx(%c1{{.*}} : index)
85+
// CHECK: Lower bound: %[[LB3]] = arith.constant 0 : index
86+
// CHECK: Upper bound: %[[UB3]] = arith.subi %[[EXTENT3]], %c1{{.*}} : index
7887
}

flang/test/lib/OpenACC/TestOpenACCInterfaces.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "mlir/Support/LLVM.h"
1616
#include "flang/Optimizer/Dialect/FIRDialect.h"
1717
#include "flang/Optimizer/HLFIR/HLFIRDialect.h"
18+
#include "flang/Optimizer/HLFIR/HLFIROps.h"
1819
#include "flang/Optimizer/Support/DataLayout.h"
1920

2021
using namespace mlir;
@@ -99,11 +100,23 @@ struct TestFIROpenACCInterfaces
99100
}
100101
}
101102

103+
if (auto declareOp =
104+
dyn_cast_if_present<hlfir::DeclareOp>(var.getDefiningOp())) {
105+
llvm::errs() << "\t\tShape: " << declareOp.getShape() << "\n";
106+
}
107+
102108
builder.setInsertionPoint(op);
103109
auto bounds = mappableTy.generateAccBounds(acc::getVar(op), builder);
104110
if (!bounds.empty()) {
105111
for (auto [idx, bound] : llvm::enumerate(bounds)) {
106-
llvm::errs() << "\t\tBound[" << idx << "]: " << bound << "\n";
112+
if (auto boundOp = dyn_cast_if_present<acc::DataBoundsOp>(
113+
bound.getDefiningOp())) {
114+
llvm::errs() << "\t\tBound[" << idx << "]: " << bound << "\n";
115+
llvm::errs()
116+
<< "\t\tLower bound: " << boundOp.getLowerbound() << "\n";
117+
llvm::errs()
118+
<< "\t\tUpper bound: " << boundOp.getUpperbound() << "\n";
119+
}
107120
}
108121
}
109122
}

0 commit comments

Comments
 (0)