diff --git a/flang/lib/Lower/DirectivesCommon.h b/flang/lib/Lower/DirectivesCommon.h index 662897c9e6c0..906bf355e9ea 100644 --- a/flang/lib/Lower/DirectivesCommon.h +++ b/flang/lib/Lower/DirectivesCommon.h @@ -799,13 +799,18 @@ genBoundsOps(fir::FirOpBuilder &builder, mlir::Location loc, } } } - // ub = baseLb + extent - 1 if (!ubound) { mlir::Value ext = fir::factory::readExtent(builder, loc, dataExv, dimension); - mlir::Value lbExt = - builder.create(loc, ext, baseLb); - ubound = builder.create(loc, lbExt, one); + if (defaultLb) { + // ub = extent - 1 + ubound = builder.create(loc, ext, one); + } else { + // ub = baseLb + extent - 1 + mlir::Value lbExt = + builder.create(loc, ext, baseLb); + ubound = builder.create(loc, lbExt, one); + } } mlir::Value bound = builder.create( loc, boundTy, lbound, ubound, extent, stride, strideInBytes, baseLb); diff --git a/flang/test/Lower/OpenACC/acc-enter-data.f90 b/flang/test/Lower/OpenACC/acc-enter-data.f90 index 5e18528dfc82..21847d462c2e 100644 --- a/flang/test/Lower/OpenACC/acc-enter-data.f90 +++ b/flang/test/Lower/OpenACC/acc-enter-data.f90 @@ -178,8 +178,7 @@ subroutine acc_enter_data !$acc enter data copyin(a(1:,1:5)) !CHECK: %[[ONE:.*]] = arith.constant 1 : index !CHECK: %[[LB1:.*]] = arith.constant 0 : index -!CHECK: %[[LBEXT:.*]] = arith.addi %c10{{.*}}, %[[ONE]] : index -!CHECK: %[[UB1:.*]] = arith.subi %[[LBEXT]], %[[ONE]] : index +!CHECK: %[[UB1:.*]] = arith.subi %c10{{.*}}, %[[ONE]] : index !CHECK: %[[BOUND1:.*]] = acc.bounds lowerbound(%[[LB1]] : index) upperbound(%[[UB1]] : index) stride(%[[ONE]] : index) startIdx(%c1{{.*}} : index) !CHECK: %[[LB2:.*]] = arith.constant 0 : index !CHECK: %[[UB2:.*]] = arith.constant 4 : index @@ -203,11 +202,9 @@ subroutine acc_enter_data !$acc enter data copyin(a(:,:)) !CHECK: %[[LB:.*]] = arith.constant 0 : index !CHECK: %[[ONE:.*]] = arith.constant 1 : index -!CHECK: %[[LBEXT:.*]] = arith.addi %c10{{.*}}, %[[ONE]] : index -!CHECK: %[[UB:.*]] = arith.subi %[[LBEXT]], %[[ONE]] : index +!CHECK: %[[UB:.*]] = arith.subi %c10{{.*}}, %[[ONE]] : index !CHECK: %[[BOUND1:.*]] = acc.bounds lowerbound(%[[LB]] : index) upperbound(%[[UB]] : index) stride(%[[ONE]] : index) startIdx(%[[ONE]] : index) -!CHECK: %[[LBEXT:.*]] = arith.addi %c10{{.*}}, %[[ONE]] : index -!CHECK: %[[UB:.*]] = arith.subi %[[LBEXT]], %[[ONE]] : index +!CHECK: %[[UB:.*]] = arith.subi %{{.*}}, %[[ONE]] : index !CHECK: %[[BOUND2:.*]] = acc.bounds lowerbound(%[[LB]] : index) upperbound(%[[UB]] : index) stride(%[[ONE]] : index) startIdx(%[[ONE]] : index) !FIR: %[[COPYIN_A:.*]] = acc.copyin varPtr(%[[A]] : !fir.ref>) bounds(%[[BOUND1]], %[[BOUND2]]) -> !fir.ref> {name = "a(:,:)", structured = false} !HLFIR: %[[COPYIN_A:.*]] = acc.copyin varPtr(%[[DECLA]]#1 : !fir.ref>) bounds(%[[BOUND1]], %[[BOUND2]]) -> !fir.ref> {name = "a(:,:)", structured = false} @@ -402,8 +399,7 @@ subroutine acc_enter_data_assumed(a, b, n, m) !CHECK: %[[C0:.*]] = arith.constant 0 : index !FIR: %[[DIMS1:.*]]:3 = fir.box_dims %[[A]], %[[C0]] : (!fir.box>, index) -> (index, index, index) !HLFIR: %[[DIMS1:.*]]:3 = fir.box_dims %[[DECLA]]#1, %[[C0]] : (!fir.box>, index) -> (index, index, index) -!CHECK: %[[LBEXT:.*]] = arith.addi %[[DIMS1]]#1, %[[ONE]] : index -!CHECK: %[[UB:.*]] = arith.subi %[[LBEXT]], %[[ONE]] : index +!CHECK: %[[UB:.*]] = arith.subi %[[DIMS1]]#1, %[[ONE]] : index !CHECK: %[[BOUND:.*]] = acc.bounds lowerbound(%[[LB]] : index) upperbound(%[[UB]] : index) stride(%[[DIMS0]]#2 : index) startIdx(%[[ONE]] : index) {strideInBytes = true} !FIR: %[[BOX_ADDR:.*]] = fir.box_addr %[[A]] : (!fir.box>) -> !fir.ref> !HLFIR: %[[BOX_ADDR:.*]] = fir.box_addr %[[DECLA]]#1 : (!fir.box>) -> !fir.ref> @@ -419,8 +415,7 @@ subroutine acc_enter_data_assumed(a, b, n, m) !CHECK: %[[C0:.*]] = arith.constant 0 : index !FIR: %[[DIMS1:.*]]:3 = fir.box_dims %[[A]], %[[C0]] : (!fir.box>, index) -> (index, index, index) !HLFIR: %[[DIMS1:.*]]:3 = fir.box_dims %[[DECLA]]#1, %[[C0]] : (!fir.box>, index) -> (index, index, index) -!CHECK: %[[LBEXT:.*]] = arith.addi %[[DIMS1]]#1, %[[ONE]] : index -!CHECK: %[[UB:.*]] = arith.subi %[[LBEXT]], %[[ONE]] : index +!CHECK: %[[UB:.*]] = arith.subi %[[DIMS1]]#1, %[[ONE]] : index !CHECK: %[[BOUND:.*]] = acc.bounds lowerbound(%[[LB]] : index) upperbound(%[[UB]] : index) stride(%[[DIMS0]]#2 : index) startIdx(%[[ONE]] : index) {strideInBytes = true} !FIR: %[[BOX_ADDR:.*]] = fir.box_addr %[[A]] : (!fir.box>) -> !fir.ref> !HLFIR: %[[BOX_ADDR:.*]] = fir.box_addr %[[DECLA]]#1 : (!fir.box>) -> !fir.ref> @@ -465,8 +460,7 @@ subroutine acc_enter_data_assumed(a, b, n, m) !CHECK: %[[C0:.*]] = arith.constant 0 : index !FIR: %[[DIMS:.*]]:3 = fir.box_dims %[[A]], %[[C0]] : (!fir.box>, index) -> (index, index, index) !HLFIR: %[[DIMS:.*]]:3 = fir.box_dims %[[DECLA]]#1, %[[C0]] : (!fir.box>, index) -> (index, index, index) -!CHECK: %[[LBEXT:.*]] = arith.addi %[[DIMS]]#1, %[[ONE]] : index -!CHECK: %[[UB:.*]] = arith.subi %[[LBEXT]], %[[ONE]] : index +!CHECK: %[[UB:.*]] = arith.subi %[[DIMS]]#1, %[[ONE]] : index !CHECK: %[[BOUND:.*]] = acc.bounds lowerbound(%[[LB]] : index) upperbound(%[[UB]] : index) stride(%[[DIMS0]]#2 : index) startIdx(%[[ONE]] : index) {strideInBytes = true} !FIR: %[[BOX_ADDR:.*]] = fir.box_addr %[[A]] : (!fir.box>) -> !fir.ref> !HLFIR: %[[BOX_ADDR:.*]] = fir.box_addr %[[DECLA]]#1 : (!fir.box>) -> !fir.ref> @@ -720,8 +714,7 @@ subroutine acc_enter_data_derived_type() !HLFIR: %[[ARRAY_COORD:.*]] = hlfir.designate %[[DECLA]]#0{"array"} shape %{{.*}} : (!fir.ref}>>, !fir.shape<1>) -> !fir.ref> !CHECK: %[[LB:.*]] = arith.constant 0 : index !CHECK: %[[C1:.*]] = arith.constant 1 : index -!CHECK: %[[LBEXT:.*]] = arith.addi %[[C10]], %[[C1]] : index -!CHECK: %[[UB:.*]] = arith.subi %[[LBEXT]], %[[C1]] : index +!CHECK: %[[UB:.*]] = arith.subi %[[C10]], %[[C1]] : index !CHECK: %[[BOUND:.*]] = acc.bounds lowerbound(%[[LB]] : index) upperbound(%[[UB]] : index) stride(%[[C1]] : index) startIdx(%[[C1]] : index) !CHECK: %[[CREATE:.*]] = acc.create varPtr(%[[ARRAY_COORD]] : !fir.ref>) bounds(%[[BOUND]]) -> !fir.ref> {name = "a%array(:)", structured = false} !CHECK: acc.enter_data dataOperands(%[[CREATE]] : !fir.ref>) @@ -755,8 +748,7 @@ subroutine acc_enter_data_derived_type() !HLFIR: %[[ARRAY_COORD:.*]] = hlfir.designate %[[DECLA]]#0{"array"} shape %{{.*}} : (!fir.ref}>>, !fir.shape<1>) -> !fir.ref> !CHECK: %[[ONE:.*]] = arith.constant 1 : index !CHECK: %[[LB:.*]] = arith.constant 1 : index -!CHECK: %[[LBEXT:.*]] = arith.addi %[[C10]], %[[ONE]] : index -!CHECK: %[[UB:.*]] = arith.subi %[[LBEXT]], %[[ONE]] : index +!CHECK: %[[UB:.*]] = arith.subi %[[C10]], %[[ONE]] : index !CHECK: %[[BOUND:.*]] = acc.bounds lowerbound(%[[LB]] : index) upperbound(%[[UB]] : index) stride(%[[ONE]] : index) startIdx(%[[ONE]] : index) !CHECK: %[[CREATE:.*]] = acc.create varPtr(%[[ARRAY_COORD]] : !fir.ref>) bounds(%[[BOUND]]) -> !fir.ref> {name = "a%array(2:)", structured = false} !CHECK: acc.enter_data dataOperands(%[[CREATE]] : !fir.ref>)