From bb6a1eb003320cdfd4a5887ad2cd8577275c2f95 Mon Sep 17 00:00:00 2001 From: Valentin Clement Date: Tue, 9 May 2023 12:59:14 -0700 Subject: Revert "[flang][openacc] Fix lowerbound when there is no subscripts" This reverts commit 626aa8518d873c5760cd033fe49b1809c9de3494. --- flang/lib/Lower/OpenACC.cpp | 8 ++++--- flang/test/Lower/OpenACC/acc-enter-data.f90 | 36 ++++++++++++++--------------- 2 files changed, 23 insertions(+), 21 deletions(-) (limited to 'flang') diff --git a/flang/lib/Lower/OpenACC.cpp b/flang/lib/Lower/OpenACC.cpp index 187b8e9ccad9..faf1b7c02467 100644 --- a/flang/lib/Lower/OpenACC.cpp +++ b/flang/lib/Lower/OpenACC.cpp @@ -146,10 +146,12 @@ genBaseBoundsOps(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value baseLb = fir::factory::readLowerBound(builder, loc, dataExv, dim, one); mlir::Value ext = fir::factory::readExtent(builder, loc, dataExv, dim); - mlir::Value lb = builder.createIntegerConstant(loc, idxTy, 0); + mlir::Value lb = + baseLb == one ? builder.createIntegerConstant(loc, idxTy, 0) : baseLb; - // ub = extent - 1 - mlir::Value ub = builder.create(loc, ext, one); + // ub = baseLb + extent - 1 + mlir::Value lbExt = builder.create(loc, ext, baseLb); + mlir::Value ub = builder.create(loc, lbExt, one); mlir::Value bound = builder.create( loc, boundTy, lb, ub, mlir::Value(), one, false, baseLb); bounds.push_back(bound); diff --git a/flang/test/Lower/OpenACC/acc-enter-data.f90 b/flang/test/Lower/OpenACC/acc-enter-data.f90 index a6ee866e5ebb..1aa7f579945a 100644 --- a/flang/test/Lower/OpenACC/acc-enter-data.f90 +++ b/flang/test/Lower/OpenACC/acc-enter-data.f90 @@ -18,10 +18,12 @@ subroutine acc_enter_data !$acc enter data create(a) !CHECK: %[[ONE:.*]] = arith.constant 1 : index !CHECK: %[[LB:.*]] = arith.constant 0 : index -!CHECK: %[[UB:.*]] = arith.subi %[[C10]], %[[ONE]] : index +!CHECK: %[[LBEXT:.*]] = arith.addi %[[C10]], %[[ONE]] : index +!CHECK: %[[UB:.*]] = arith.subi %[[LBEXT]], %[[ONE]] : index !CHECK: %[[BOUND0:.*]] = acc.bounds lowerbound(%[[LB]] : index) upperbound(%[[UB]] : index) stride(%[[ONE]] : index) startIdx(%[[ONE]] : index) !CHECK: %[[LB:.*]] = arith.constant 0 : index -!CHECK: %[[UB:.*]] = arith.subi %[[EXTENT_C10]], %[[ONE]] : index +!CHECK: %[[LBEXT:.*]] = arith.addi %[[EXTENT_C10]], %[[ONE]] : index +!CHECK: %[[UB:.*]] = arith.subi %[[LBEXT]], %[[ONE]] : index !CHECK: %[[BOUND1:.*]] = acc.bounds lowerbound(%[[LB]] : index) upperbound(%[[UB]] : index) stride(%[[ONE]] : index) startIdx(%[[ONE]] : index) !CHECK: %[[CREATE_A:.*]] = acc.create varPtr(%[[A]] : !fir.ref>) bounds(%[[BOUND0]], %[[BOUND1]]) -> !fir.ref> {name = "a", structured = false} !CHECK: acc.enter_data dataOperands(%[[CREATE_A]] : !fir.ref>){{$}} @@ -29,10 +31,12 @@ subroutine acc_enter_data !$acc enter data create(a) if(.true.) !CHECK: %[[ONE:.*]] = arith.constant 1 : index !CHECK: %[[LB:.*]] = arith.constant 0 : index -!CHECK: %[[UB:.*]] = arith.subi %[[C10]], %[[ONE]] : index +!CHECK: %[[LBEXT:.*]] = arith.addi %[[C10]], %[[ONE]] : index +!CHECK: %[[UB:.*]] = arith.subi %[[LBEXT]], %[[ONE]] : index !CHECK: %[[BOUND0:.*]] = acc.bounds lowerbound(%[[LB]] : index) upperbound(%[[UB]] : index) stride(%[[ONE]] : index) startIdx(%[[ONE]] : index) !CHECK: %[[LB:.*]] = arith.constant 0 : index -!CHECK: %[[UB:.*]] = arith.subi %[[EXTENT_C10]], %[[ONE]] : index +!CHECK: %[[LBEXT:.*]] = arith.addi %[[EXTENT_C10]], %[[ONE]] : index +!CHECK: %[[UB:.*]] = arith.subi %[[LBEXT]], %[[ONE]] : index !CHECK: %[[BOUND1:.*]] = acc.bounds lowerbound(%[[LB]] : index) upperbound(%[[UB]] : index) stride(%[[ONE]] : index) startIdx(%[[ONE]] : index) !CHECK: %[[CREATE_A:.*]] = acc.create varPtr(%[[A]] : !fir.ref>) bounds(%[[BOUND0]], %[[BOUND1]]) -> !fir.ref> {name = "a", structured = false} !CHECK: [[IF1:%.*]] = arith.constant true @@ -41,10 +45,12 @@ subroutine acc_enter_data !$acc enter data create(a) if(ifCondition) !CHECK: %[[ONE:.*]] = arith.constant 1 : index !CHECK: %[[LB:.*]] = arith.constant 0 : index -!CHECK: %[[UB:.*]] = arith.subi %[[C10]], %[[ONE]] : index +!CHECK: %[[LBEXT:.*]] = arith.addi %[[C10]], %[[ONE]] : index +!CHECK: %[[UB:.*]] = arith.subi %[[LBEXT]], %[[ONE]] : index !CHECK: %[[BOUND0:.*]] = acc.bounds lowerbound(%[[LB]] : index) upperbound(%[[UB]] : index) stride(%[[ONE]] : index) startIdx(%[[ONE]] : index) !CHECK: %[[LB:.*]] = arith.constant 0 : index -!CHECK: %[[UB:.*]] = arith.subi %[[EXTENT_C10]], %[[ONE]] : index +!CHECK: %[[LBEXT:.*]] = arith.addi %[[EXTENT_C10]], %[[ONE]] : index +!CHECK: %[[UB:.*]] = arith.subi %[[LBEXT]], %[[ONE]] : index !CHECK: %[[BOUND1:.*]] = acc.bounds lowerbound(%[[LB]] : index) upperbound(%[[UB]] : index) stride(%[[ONE]] : index) startIdx(%[[ONE]] : index) !CHECK: %[[CREATE_A:.*]] = acc.create varPtr(%[[A]] : !fir.ref>) bounds(%[[BOUND0]], %[[BOUND1]]) -> !fir.ref> {name = "a", structured = false} !CHECK: [[IFCOND:%.*]] = fir.load %{{.*}} : !fir.ref> @@ -260,7 +266,6 @@ end subroutine ! Test lowering of array section for non default lower bound. subroutine acc_enter_data_non_default_lb() integer :: a(0:9) - integer :: b(11:20) !CHECK-LABEL: func.func @_QPacc_enter_data_non_default_lb() { !CHECK: %[[BASELB:.*]] = arith.constant 0 : index @@ -301,14 +306,6 @@ subroutine acc_enter_data_non_default_lb() !CHECK: %[[UB:.*]] = arith.subi %[[LBEXT]], %[[ONE]] : index !CHECK: %[[BOUND:.*]] = acc.bounds lowerbound(%[[LB]] : index) upperbound(%[[UB]] : index) stride(%[[ONE]] : index) startIdx(%[[BASELB]] : index) !CHECK: %[[CREATE:.*]] = acc.create varPtr(%[[A]] : !fir.ref>) bounds(%[[BOUND]]) -> !fir.ref> {name = "a(4:)", structured = false} -!CHECK: acc.enter_data dataOperands(%[[CREATE]] : !fir.ref>) - - !$acc enter data create(b) -!CHECK: %[[ONE:.*]] = arith.constant 1 : index -!CHECK: %[[LB:.*]] = arith.constant 0 : index -!CHECK: %[[UB:.*]] = arith.subi %c10{{.*}}, %[[ONE]] : index -!CHECK: %[[BOUND:.*]] = acc.bounds lowerbound(%[[LB]] : index) upperbound(%[[UB]] : index) stride(%[[ONE]] : index) startIdx(%c11{{.*}} : index) -!CHECK: %[[CREATE:.*]] = acc.create varPtr(%1 : !fir.ref>) bounds(%[[BOUND]]) -> !fir.ref> {name = "b", structured = false} !CHECK: acc.enter_data dataOperands(%[[CREATE]] : !fir.ref>) end subroutine @@ -601,7 +598,8 @@ subroutine acc_enter_data_derived_type() !CHECK: %[[C10:.*]] = arith.constant 10 : index !CHECK: %[[C1:.*]] = arith.constant 1 : index !CHECK: %[[LB:.*]] = arith.constant 0 : index -!CHECK: %[[UB:.*]] = arith.subi %[[C10]], %[[C1]] : index +!CHECK: %[[LBEXT:.*]] = arith.addi %[[C10]], %[[C1]] : index +!CHECK: %[[UB:.*]] = arith.subi %[[LBEXT]], %[[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>) @@ -657,7 +655,8 @@ subroutine acc_enter_data_derived_type() !CHECK: %[[C10:.*]] = arith.constant 10 : index !CHECK: %[[C1:.*]] = arith.constant 1 : index !CHECK: %[[LB:.*]] = arith.constant 0 : index -!CHECK: %[[UB:.*]] = arith.subi %[[C10]], %[[C1]] : index +!CHECK: %[[LBEXT:.*]] = arith.addi %[[C10]], %[[C1]] : index +!CHECK: %[[UB:.*]] = arith.subi %[[LBEXT]], %[[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 = "b%d%array", structured = false} @@ -688,7 +687,8 @@ subroutine acc_enter_data_derived_type() !CHECK: %[[C10:.*]] = arith.constant 10 : index !CHECK: %[[C1:.*]] = arith.constant 1 : index !CHECK: %[[LB:.*]] = arith.constant 0 : index -!CHECK: %[[UB:.*]] = arith.subi %[[C10]], %[[C1]] : index +!CHECK: %[[LBEXT:.*]] = arith.addi %[[C10]], %[[C1]] : index +!CHECK: %[[UB:.*]] = arith.subi %[[LBEXT]], %[[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 = "d%d(1_8)%array", structured = false} !CHECK: acc.enter_data dataOperands(%[[CREATE]] : !fir.ref>) -- cgit v1.2.1