[flang-commits] [flang] 1581a4b - [flang][acc] Fix mappableTy.generateAccBounds to correctly handle dynamic-sized arrays (#155666)
via flang-commits
flang-commits at lists.llvm.org
Wed Aug 27 22:46:12 PDT 2025
Author: khaki3
Date: 2025-08-27T22:46:08-07:00
New Revision: 1581a4b86386193fe9044f5f7d145dddd5c17798
URL: https://github.com/llvm/llvm-project/commit/1581a4b86386193fe9044f5f7d145dddd5c17798
DIFF: https://github.com/llvm/llvm-project/commit/1581a4b86386193fe9044f5f7d145dddd5c17798.diff
LOG: [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`.
Added:
Modified:
flang/lib/Optimizer/OpenACC/Support/FIROpenACCTypeInterfaces.cpp
flang/test/Fir/OpenACC/openacc-mappable.fir
flang/test/lib/OpenACC/TestOpenACCInterfaces.cpp
Removed:
################################################################################
diff --git a/flang/lib/Optimizer/OpenACC/Support/FIROpenACCTypeInterfaces.cpp b/flang/lib/Optimizer/OpenACC/Support/FIROpenACCTypeInterfaces.cpp
index 5b6d904fb0d59..c9aff592c95a3 100644
--- a/flang/lib/Optimizer/OpenACC/Support/FIROpenACCTypeInterfaces.cpp
+++ b/flang/lib/Optimizer/OpenACC/Support/FIROpenACCTypeInterfaces.cpp
@@ -271,8 +271,6 @@ generateSeqTyAccBounds(fir::SequenceType seqType, mlir::Value var,
mlir::Value extent = val;
mlir::Value upperbound =
mlir::arith::SubIOp::create(builder, loc, extent, one);
- upperbound = mlir::arith::AddIOp::create(builder, loc, lowerbound,
- upperbound);
mlir::Value stride = one;
if (strideIncludeLowerExtent) {
stride = cummulativeExtent;
diff --git a/flang/test/Fir/OpenACC/openacc-mappable.fir b/flang/test/Fir/OpenACC/openacc-mappable.fir
index 71576f4b71075..05df35a482907 100644
--- a/flang/test/Fir/OpenACC/openacc-mappable.fir
+++ b/flang/test/Fir/OpenACC/openacc-mappable.fir
@@ -62,17 +62,26 @@ module attributes {dlti.dl_spec = #dlti.dl_spec<f16 = dense<16> : vector<2xi64>,
// CHECK: Visiting: %{{.*}} = acc.copyin varPtr(%{{.*}} : !fir.ref<!fir.array<?xf32>>) -> !fir.ref<!fir.array<?xf32>> {name = "arr1", structured = false}
// CHECK: Pointer-like and Mappable: !fir.ref<!fir.array<?xf32>>
// CHECK: Type category: array
- // CHECK: Bound[0]: %{{.*}} = acc.bounds lowerbound(%c0{{.*}} : index) upperbound(%{{.*}} : index) extent(%{{.*}} : index) stride(%c1{{.*}} : index) startIdx(%c1{{.*}} : index)
+ // CHECK: Shape: %{{.*}} = fir.shape %[[EXTENT1:.*]] : (index) -> !fir.shape<1>
+ // CHECK: Bound[0]: %{{.*}} = acc.bounds lowerbound(%[[LB1:.*]] : index) upperbound(%[[UB1:.*]] : index) extent(%{{.*}} : index) stride(%c1{{.*}} : index) startIdx(%c1{{.*}} : index)
+ // CHECK: Lower bound: %[[LB1]] = arith.constant 0 : index
+ // CHECK: Upper bound: %[[UB1]] = arith.subi %[[EXTENT1]], %c1{{.*}} : index
// CHECK: Visiting: %{{.*}} = acc.copyin varPtr(%{{.*}} : !fir.ref<!fir.array<?xf32>>) -> !fir.ref<!fir.array<?xf32>> {name = "arr2", structured = false}
// CHECK: Pointer-like and Mappable: !fir.ref<!fir.array<?xf32>>
// CHECK: Type category: array
- // CHECK: Bound[0]: %{{.*}} = acc.bounds lowerbound(%c0{{.*}} : index) upperbound(%{{.*}} : index) extent(%{{.*}} : index) stride(%c1{{.*}} : index) startIdx(%c2{{.*}} : index)
+ // CHECK: Shape: %{{.*}} = fir.shape_shift %c2{{.*}}, %[[EXTENT2:.*]] : (index, index) -> !fir.shapeshift<1>
+ // CHECK: Bound[0]: %{{.*}} = acc.bounds lowerbound(%[[LB2:.*]] : index) upperbound(%[[UB2:.*]] : index) extent(%{{.*}} : index) stride(%c1{{.*}} : index) startIdx(%c2{{.*}} : index)
+ // CHECK: Lower bound: %[[LB2]] = arith.constant 0 : index
+ // CHECK: Upper bound: %[[UB2]] = arith.subi %[[EXTENT2]], %c1{{.*}} : index
// CHECK: Visiting: %{{.*}} = acc.copyin varPtr(%{{.*}} : !fir.ref<!fir.array<10xf32>>) -> !fir.ref<!fir.array<10xf32>> {name = "arr3", structured = false}
// CHECK: Pointer-like and Mappable: !fir.ref<!fir.array<10xf32>>
// CHECK: Type category: array
// CHECK: Size: 40
// CHECK: Offset: 0
- // CHECK: Bound[0]: %{{.*}} = acc.bounds lowerbound(%c0{{.*}} : index) upperbound(%{{.*}} : index) extent(%c10{{.*}} : index) stride(%c1{{.*}} : index) startIdx(%c1{{.*}} : index)
+ // CHECK: Shape: %{{.*}} = fir.shape %[[EXTENT3:.*]] : (index) -> !fir.shape<1>
+ // CHECK: Bound[0]: %{{.*}} = acc.bounds lowerbound(%[[LB3:.*]] : index) upperbound(%[[UB3:.*]] : index) extent(%c10{{.*}} : index) stride(%c1{{.*}} : index) startIdx(%c1{{.*}} : index)
+ // CHECK: Lower bound: %[[LB3]] = arith.constant 0 : index
+ // CHECK: Upper bound: %[[UB3]] = arith.subi %[[EXTENT3]], %c1{{.*}} : index
}
diff --git a/flang/test/lib/OpenACC/TestOpenACCInterfaces.cpp b/flang/test/lib/OpenACC/TestOpenACCInterfaces.cpp
index de6cb1d09080d..9a80e3b1a9aee 100644
--- a/flang/test/lib/OpenACC/TestOpenACCInterfaces.cpp
+++ b/flang/test/lib/OpenACC/TestOpenACCInterfaces.cpp
@@ -15,6 +15,7 @@
#include "mlir/Support/LLVM.h"
#include "flang/Optimizer/Dialect/FIRDialect.h"
#include "flang/Optimizer/HLFIR/HLFIRDialect.h"
+#include "flang/Optimizer/HLFIR/HLFIROps.h"
#include "flang/Optimizer/Support/DataLayout.h"
using namespace mlir;
@@ -99,11 +100,23 @@ struct TestFIROpenACCInterfaces
}
}
+ if (auto declareOp =
+ dyn_cast_if_present<hlfir::DeclareOp>(var.getDefiningOp())) {
+ llvm::errs() << "\t\tShape: " << declareOp.getShape() << "\n";
+ }
+
builder.setInsertionPoint(op);
auto bounds = mappableTy.generateAccBounds(acc::getVar(op), builder);
if (!bounds.empty()) {
for (auto [idx, bound] : llvm::enumerate(bounds)) {
- llvm::errs() << "\t\tBound[" << idx << "]: " << bound << "\n";
+ if (auto boundOp = dyn_cast_if_present<acc::DataBoundsOp>(
+ bound.getDefiningOp())) {
+ llvm::errs() << "\t\tBound[" << idx << "]: " << bound << "\n";
+ llvm::errs()
+ << "\t\tLower bound: " << boundOp.getLowerbound() << "\n";
+ llvm::errs()
+ << "\t\tUpper bound: " << boundOp.getUpperbound() << "\n";
+ }
}
}
}
More information about the flang-commits
mailing list