[flang-commits] [flang] [flang][openacc] Set extent to 0 when it is undefined (PR #71108)
Valentin Clement バレンタイン クレメン via flang-commits
flang-commits at lists.llvm.org
Thu Nov 2 13:56:08 PDT 2023
https://github.com/clementval created https://github.com/llvm/llvm-project/pull/71108
Set upperbound to lowerbound value and extent to zero when extent is undefined.
>From 158bb085b7655d64d232c874a72a2b71427736a0 Mon Sep 17 00:00:00 2001
From: Valentin Clement <clementval at gmail.com>
Date: Thu, 2 Nov 2023 13:54:09 -0700
Subject: [PATCH] [flang][openacc] Set extent to 0 when it is undefined
---
flang/lib/Lower/DirectivesCommon.h | 15 +++++++++++----
flang/test/Lower/OpenACC/acc-bounds.f90 | 16 ++++++++++++++++
2 files changed, 27 insertions(+), 4 deletions(-)
diff --git a/flang/lib/Lower/DirectivesCommon.h b/flang/lib/Lower/DirectivesCommon.h
index 86787961382441f..2ea4f53e94081f6 100644
--- a/flang/lib/Lower/DirectivesCommon.h
+++ b/flang/lib/Lower/DirectivesCommon.h
@@ -632,11 +632,18 @@ genBaseBoundsOps(fir::FirOpBuilder &builder, mlir::Location loc,
for (std::size_t dim = 0; dim < dataExv.rank(); ++dim) {
mlir::Value baseLb =
fir::factory::readLowerBound(builder, loc, dataExv, dim, one);
+ mlir::Value zero = builder.createIntegerConstant(loc, idxTy, 0);
+ mlir::Value ub;
+ mlir::Value lb = zero;
mlir::Value ext = fir::factory::readExtent(builder, loc, dataExv, dim);
- mlir::Value lb = builder.createIntegerConstant(loc, idxTy, 0);
+ if (mlir::isa<fir::UndefOp>(ext.getDefiningOp())) {
+ ext = zero;
+ ub = lb;
+ } else {
+ // ub = extent - 1
+ ub = builder.create<mlir::arith::SubIOp>(loc, ext, one);
+ }
- // ub = extent - 1
- mlir::Value ub = builder.create<mlir::arith::SubIOp>(loc, ext, one);
mlir::Value bound =
builder.create<BoundsOp>(loc, boundTy, lb, ub, ext, one, false, baseLb);
bounds.push_back(bound);
@@ -738,7 +745,7 @@ genBoundsOps(fir::FirOpBuilder &builder, mlir::Location loc,
const auto &strideExpr{std::get<2>(triplet->t)};
if (strideExpr) {
mlir::emitError(loc, "stride cannot be specified on "
- "an OpenMP array section");
+ "an array section");
break;
}
}
diff --git a/flang/test/Lower/OpenACC/acc-bounds.f90 b/flang/test/Lower/OpenACC/acc-bounds.f90
index c63c9aacf5c2c16..86fb4d8c5284e45 100644
--- a/flang/test/Lower/OpenACC/acc-bounds.f90
+++ b/flang/test/Lower/OpenACC/acc-bounds.f90
@@ -86,4 +86,20 @@ subroutine acc_derived_type_component_allocatable_array()
! CHECK: return
! CHECK: }
+ subroutine acc_undefined_extent(a)
+ real, dimension(1:*) :: a
+
+ !$acc kernels present(a)
+ !$acc end kernels
+ end subroutine
+! CHECK-LABEL: func.func @_QMopenacc_boundsPacc_undefined_extent(
+! CHECK-SAME: %[[ARG0:.*]]: !fir.ref<!fir.array<?xf32>> {fir.bindc_name = "a"}) {
+! HLFIR: %[[DECL_ARG0:.*]]:2 = hlfir.declare %[[ARG0]](%{{.*}}) {uniq_name = "_QMopenacc_boundsFacc_undefined_extentEa"} : (!fir.ref<!fir.array<?xf32>>, !fir.shape<1>) -> (!fir.box<!fir.array<?xf32>>, !fir.ref<!fir.array<?xf32>>)
+! CHECK: %[[ONE:.*]] = arith.constant 1 : index
+! CHECK: %[[ZERO:.*]] = arith.constant 0 : index
+! CHECK: %[[BOUND:.*]] = acc.bounds lowerbound(%[[ZERO]] : index) upperbound(%[[ZERO]] : index) extent(%[[ZERO]] : index) stride(%[[ONE]] : index) startIdx(%[[ONE]] : index)
+! FIR: %[[PRESENT:.*]] = acc.present varPtr(%[[ARG0]] : !fir.ref<!fir.array<?xf32>>) bounds(%[[BOUND]]) -> !fir.ref<!fir.array<?xf32>> {name = "a"}
+! HLFIR: %[[PRESENT:.*]] = acc.present varPtr(%[[DECL_ARG0]]#1 : !fir.ref<!fir.array<?xf32>>) bounds(%[[BOUND]]) -> !fir.ref<!fir.array<?xf32>> {name = "a"}
+! CHECK: acc.kernels dataOperands(%[[PRESENT]] : !fir.ref<!fir.array<?xf32>>)
+
end module
More information about the flang-commits
mailing list