diff --git a/flang/lib/Lower/OpenACC.cpp b/flang/lib/Lower/OpenACC.cpp --- a/flang/lib/Lower/OpenACC.cpp +++ b/flang/lib/Lower/OpenACC.cpp @@ -107,7 +107,7 @@ const std::list &subscripts, std::stringstream &asFortran, const Fortran::parser::Name &name) { int dimension = 0; - mlir::Type i64Ty = builder.getI64Type(); + mlir::Type idxTy = builder.getIndexType(); mlir::Type boundTy = builder.getType(); llvm::SmallVector bounds; for (const auto &subscript : subscripts) { @@ -121,7 +121,7 @@ if (lower) { lval = Fortran::semantics::GetIntValue(lower); if (lval) { - lbound = builder.createIntegerConstant(loc, i64Ty, *lval); + lbound = builder.createIntegerConstant(loc, idxTy, *lval - 1); asFortran << *lval; } else { TODO(loc, "non constant lower bound in array section"); @@ -132,7 +132,7 @@ if (upper) { uval = Fortran::semantics::GetIntValue(upper); if (uval) { - ubound = builder.createIntegerConstant(loc, i64Ty, *uval); + ubound = builder.createIntegerConstant(loc, idxTy, *uval - 1); asFortran << *uval; } else { TODO(loc, "non constant upper bound in array section"); @@ -151,13 +151,15 @@ } } } + mlir::Value one = builder.createIntegerConstant(loc, idxTy, 1); if (!ubound) { fir::ExtendedValue x = converter.getSymbolExtendedValue(*name.symbol); - extent = fir::factory::readExtent(builder, loc, x, dimension); + mlir::Value ext = fir::factory::readExtent(builder, loc, x, dimension); + extent = builder.create(loc, ext, one); } mlir::Value empty; mlir::Value bound = builder.create( - loc, boundTy, lbound, ubound, extent, empty, false, empty); + loc, boundTy, lbound, ubound, extent, empty, false, one); bounds.push_back(bound); ++dimension; } diff --git a/flang/test/Lower/OpenACC/acc-enter-data.f90 b/flang/test/Lower/OpenACC/acc-enter-data.f90 --- a/flang/test/Lower/OpenACC/acc-enter-data.f90 +++ b/flang/test/Lower/OpenACC/acc-enter-data.f90 @@ -88,32 +88,43 @@ !CHECK: acc.enter_data wait_devnum(%[[WAIT6]] : i32) wait(%[[WAIT4]], %[[WAIT5]] : i32, i32) dataOperands(%[[CREATE_A]] : !fir.ref>) !$acc enter data copyin(a(1:10,1:5)) -!CHECK: %[[LB1:.*]] = arith.constant 1 : i64 -!CHECK: %[[UB1:.*]] = arith.constant 10 : i64 -!CHECK: %[[BOUND1:.*]] = acc.bounds lowerbound(%[[LB1]] : i64) upperbound(%[[UB1]] : i64) -!CHECK: %[[LB2:.*]] = arith.constant 1 : i64 -!CHECK: %[[UB2:.*]] = arith.constant 5 : i64 -!CHECK: %[[BOUND2:.*]] = acc.bounds lowerbound(%[[LB2]] : i64) upperbound(%[[UB2]] : i64) +!CHECK: %[[LB1:.*]] = arith.constant 0 : index +!CHECK: %[[UB1:.*]] = arith.constant 9 : index +!CHECK: %[[BOUND1:.*]] = acc.bounds lowerbound(%[[LB1]] : index) upperbound(%[[UB1]] : index) startIdx(%c1{{.*}} : index) +!CHECK: %[[LB2:.*]] = arith.constant 0 : index +!CHECK: %[[UB2:.*]] = arith.constant 4 : index +!CHECK: %[[BOUND2:.*]] = acc.bounds lowerbound(%[[LB2]] : index) upperbound(%[[UB2]] : index) startIdx(%c1{{.*}} : index) !CHECK: %[[COPYIN_A:.*]] = acc.copyin varPtr(%[[A]] : !fir.ref>) bounds(%[[BOUND1]], %[[BOUND2]]) -> !fir.ref> {name = "a(1:10,1:5)", structured = false} !CHECK: acc.enter_data dataOperands(%[[COPYIN_A]] : !fir.ref>) !$acc enter data copyin(a(1:,1:5)) -!CHECK: %[[LB1:.*]] = arith.constant 1 : i64 -!CHECK: %[[BOUND1:.*]] = acc.bounds lowerbound(%[[LB1]] : i64) extent(%[[EXTENT_C10]] : index) -!CHECK: %[[LB2:.*]] = arith.constant 1 : i64 -!CHECK: %[[UB2:.*]] = arith.constant 5 : i64 -!CHECK: %[[BOUND2:.*]] = acc.bounds lowerbound(%[[LB2]] : i64) upperbound(%[[UB2]] : i64) -!CHECK: %[[COPYIN_A:.*]] = acc.copyin varPtr(%[[A]] : !fir.ref>) bounds(%[[BOUND1]], %[[BOUND2]]) -> !fir.ref> {name = "a(1:,1:5)", structured = false} +!CHECK: %[[LB1:.*]] = arith.constant 0 : index +!CHECK: %[[EXTENT:.*]] = arith.subi %[[EXTENT_C10:.*]], %c1{{.*}} : index +!CHECK: %[[BOUND1:.*]] = acc.bounds lowerbound(%[[LB1]] : index) extent(%[[EXTENT]] : index) startIdx(%c1{{.*}} : index) +!CHECK: %[[LB2:.*]] = arith.constant 0 : index +!CHECK: %[[UB2:.*]] = arith.constant 4 : index +!CHECK: %[[BOUND2:.*]] = acc.bounds lowerbound(%[[LB2]] : index) upperbound(%[[UB2]] : index) startIdx(%c1{{.*}} : index) +!CHECK: %[[COPYIN_A:.*]] = acc.copyin varPtr(%[[A]] : !fir.ref>) bounds(%[[BOUND1]], %[[BOUND2]]) -> !fir.ref> {name = "a(1:,1:5)", structured = false} !CHECK: acc.enter_data dataOperands(%[[COPYIN_A]] : !fir.ref>) !$acc enter data copyin(a(:10,1:5)) -!CHECK: %[[UB1:.*]] = arith.constant 10 : i64 -!CHECK: %[[BOUND1:.*]] = acc.bounds upperbound(%[[UB1]] : i64) -!CHECK: %[[LB2:.*]] = arith.constant 1 : i64 -!CHECK: %[[UB2:.*]] = arith.constant 5 : i64 -!CHECK: %[[BOUND2:.*]] = acc.bounds lowerbound(%[[LB2]] : i64) upperbound(%[[UB2]] : i64) -!CHECK: %[[COPYIN_A:.*]] = acc.copyin varPtr(%[[A]] : !fir.ref>) bounds(%[[BOUND1]], %[[BOUND2]]) -> !fir.ref> {name = "a(:10,1:5)", structured = false} -!CHECK: acc.enter_data dataOperands(%[[COPYIN_A]] : !fir.ref>) +!CHECK: %[[UB1:.*]] = arith.constant 9 : index +!CHECK: %[[BOUND1:.*]] = acc.bounds upperbound(%[[UB1]] : index) +!CHECK: %[[LB2:.*]] = arith.constant 0 : index +!CHECK: %[[UB2:.*]] = arith.constant 4 : index +!CHECK: %[[BOUND2:.*]] = acc.bounds lowerbound(%[[LB2]] : index) upperbound(%[[UB2]] : index) startIdx(%c1{{.*}} : index) +!CHECK: %[[COPYIN_A:.*]] = acc.copyin varPtr(%[[A]] : !fir.ref>) bounds(%[[BOUND1]], %[[BOUND2]]) -> !fir.ref> {name = "a(:10,1:5)", structured = false} +!CHECK: acc.enter_data dataOperands(%[[COPYIN_A]] : !fir.ref>) + + !$acc enter data copyin(a(:,:)) +!CHECK: %[[C1:.*]] = arith.constant 1 : index +!CHECK: %[[EXT:.*]] = arith.subi %c10{{.*}}, %[[C1]] : index +!CHECK: %[[BOUND1:.*]] = acc.bounds extent(%[[EXT]] : index) startIdx(%[[C1]] : index) +!CHECK: %[[C1:.*]] = arith.constant 1 : index +!CHECK: %[[EXT:.*]] = arith.subi %c10{{.*}}, %[[C1]] : index +!CHECK: %[[BOUND2:.*]] = acc.bounds extent(%[[EXT]] : index) startIdx(%[[C1]] : index) +!CHECK: %[[COPYIN_A:.*]] = acc.copyin varPtr(%[[A]] : !fir.ref>) bounds(%[[BOUND1]], %[[BOUND2]]) -> !fir.ref> {name = "a(:,:)", structured = false} +!CHECK: acc.enter_data dataOperands(%[[COPYIN_A]] : !fir.ref>) end subroutine acc_enter_data @@ -125,10 +136,10 @@ !CHECK-SAME: %[[A:.*]]: !fir.ref> {fir.bindc_name = "a"} !$acc enter data create(a(5:10)) -!CHECK: %[[LB1:.*]] = arith.constant 5 : i64 -!CHECK: %[[UB1:.*]] = arith.constant 10 : i64 -!CHECK: %[[BOUND1:.*]] = acc.bounds lowerbound(%[[LB1]] : i64) upperbound(%[[UB1]] : i64) -!CHECK: %[[CREATE1:.*]] = acc.create varPtr(%[[A]] : !fir.ref>) bounds(%[[BOUND1]]) -> !fir.ref> {name = "a(5:10)", structured = false} -!CHECK: acc.enter_data dataOperands(%[[CREATE1]] : !fir.ref>) +!CHECK: %[[LB1:.*]] = arith.constant 4 : index +!CHECK: %[[UB1:.*]] = arith.constant 9 : index +!CHECK: %[[BOUND1:.*]] = acc.bounds lowerbound(%[[LB1]] : index) upperbound(%[[UB1]] : index) startIdx(%c1{{.*}} : index) +!CHECK: %[[CREATE1:.*]] = acc.create varPtr(%[[A]] : !fir.ref>) bounds(%[[BOUND1]]) -> !fir.ref> {name = "a(5:10)", structured = false} +!CHECK: acc.enter_data dataOperands(%[[CREATE1]] : !fir.ref>) end subroutine