[flang-commits] [flang] 4b57d03 - [flang][openacc] Set extent to 0 when it is undefined (#71108)
via flang-commits
flang-commits at lists.llvm.org
Thu Nov 2 15:00:26 PDT 2023
Author: Valentin Clement (バレンタイン クレメン)
Date: 2023-11-02T15:00:22-07:00
New Revision: 4b57d03a495727e22e1ea7dd6ae9f3c8a729b38d
URL: https://github.com/llvm/llvm-project/commit/4b57d03a495727e22e1ea7dd6ae9f3c8a729b38d
DIFF: https://github.com/llvm/llvm-project/commit/4b57d03a495727e22e1ea7dd6ae9f3c8a729b38d.diff
LOG: [flang][openacc] Set extent to 0 when it is undefined (#71108)
Set upperbound to lowerbound value and extent to zero when extent is
undefined.
Added:
Modified:
flang/lib/Lower/DirectivesCommon.h
flang/test/Lower/OpenACC/acc-bounds.f90
Removed:
################################################################################
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