Skip to content

Commit 626aa85

Browse files
committed
[flang][openacc] Fix lowerbound when there is no subscripts
The lowerbound was not correctly normalized to 0 when the bound are generated for an array without subscripts. ``` integer :: a(11:20) !$acc enter data create(a) ``` Reviewed By: razvanlupusoru Differential Revision: https://reviews.llvm.org/D150208
1 parent e956974 commit 626aa85

File tree

2 files changed

+21
-23
lines changed

2 files changed

+21
-23
lines changed

flang/lib/Lower/OpenACC.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,10 @@ genBaseBoundsOps(fir::FirOpBuilder &builder, mlir::Location loc,
146146
mlir::Value baseLb =
147147
fir::factory::readLowerBound(builder, loc, dataExv, dim, one);
148148
mlir::Value ext = fir::factory::readExtent(builder, loc, dataExv, dim);
149-
mlir::Value lb =
150-
baseLb == one ? builder.createIntegerConstant(loc, idxTy, 0) : baseLb;
149+
mlir::Value lb = builder.createIntegerConstant(loc, idxTy, 0);
151150

152-
// ub = baseLb + extent - 1
153-
mlir::Value lbExt = builder.create<mlir::arith::AddIOp>(loc, ext, baseLb);
154-
mlir::Value ub = builder.create<mlir::arith::SubIOp>(loc, lbExt, one);
151+
// ub = extent - 1
152+
mlir::Value ub = builder.create<mlir::arith::SubIOp>(loc, ext, one);
155153
mlir::Value bound = builder.create<mlir::acc::DataBoundsOp>(
156154
loc, boundTy, lb, ub, mlir::Value(), one, false, baseLb);
157155
bounds.push_back(bound);

flang/test/Lower/OpenACC/acc-enter-data.f90

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,21 @@ subroutine acc_enter_data
1818
!$acc enter data create(a)
1919
!CHECK: %[[ONE:.*]] = arith.constant 1 : index
2020
!CHECK: %[[LB:.*]] = arith.constant 0 : index
21-
!CHECK: %[[LBEXT:.*]] = arith.addi %[[C10]], %[[ONE]] : index
22-
!CHECK: %[[UB:.*]] = arith.subi %[[LBEXT]], %[[ONE]] : index
21+
!CHECK: %[[UB:.*]] = arith.subi %[[C10]], %[[ONE]] : index
2322
!CHECK: %[[BOUND0:.*]] = acc.bounds lowerbound(%[[LB]] : index) upperbound(%[[UB]] : index) stride(%[[ONE]] : index) startIdx(%[[ONE]] : index)
2423
!CHECK: %[[LB:.*]] = arith.constant 0 : index
25-
!CHECK: %[[LBEXT:.*]] = arith.addi %[[EXTENT_C10]], %[[ONE]] : index
26-
!CHECK: %[[UB:.*]] = arith.subi %[[LBEXT]], %[[ONE]] : index
24+
!CHECK: %[[UB:.*]] = arith.subi %[[EXTENT_C10]], %[[ONE]] : index
2725
!CHECK: %[[BOUND1:.*]] = acc.bounds lowerbound(%[[LB]] : index) upperbound(%[[UB]] : index) stride(%[[ONE]] : index) startIdx(%[[ONE]] : index)
2826
!CHECK: %[[CREATE_A:.*]] = acc.create varPtr(%[[A]] : !fir.ref<!fir.array<10x10xf32>>) bounds(%[[BOUND0]], %[[BOUND1]]) -> !fir.ref<!fir.array<10x10xf32>> {name = "a", structured = false}
2927
!CHECK: acc.enter_data dataOperands(%[[CREATE_A]] : !fir.ref<!fir.array<10x10xf32>>){{$}}
3028

3129
!$acc enter data create(a) if(.true.)
3230
!CHECK: %[[ONE:.*]] = arith.constant 1 : index
3331
!CHECK: %[[LB:.*]] = arith.constant 0 : index
34-
!CHECK: %[[LBEXT:.*]] = arith.addi %[[C10]], %[[ONE]] : index
35-
!CHECK: %[[UB:.*]] = arith.subi %[[LBEXT]], %[[ONE]] : index
32+
!CHECK: %[[UB:.*]] = arith.subi %[[C10]], %[[ONE]] : index
3633
!CHECK: %[[BOUND0:.*]] = acc.bounds lowerbound(%[[LB]] : index) upperbound(%[[UB]] : index) stride(%[[ONE]] : index) startIdx(%[[ONE]] : index)
3734
!CHECK: %[[LB:.*]] = arith.constant 0 : index
38-
!CHECK: %[[LBEXT:.*]] = arith.addi %[[EXTENT_C10]], %[[ONE]] : index
39-
!CHECK: %[[UB:.*]] = arith.subi %[[LBEXT]], %[[ONE]] : index
35+
!CHECK: %[[UB:.*]] = arith.subi %[[EXTENT_C10]], %[[ONE]] : index
4036
!CHECK: %[[BOUND1:.*]] = acc.bounds lowerbound(%[[LB]] : index) upperbound(%[[UB]] : index) stride(%[[ONE]] : index) startIdx(%[[ONE]] : index)
4137
!CHECK: %[[CREATE_A:.*]] = acc.create varPtr(%[[A]] : !fir.ref<!fir.array<10x10xf32>>) bounds(%[[BOUND0]], %[[BOUND1]]) -> !fir.ref<!fir.array<10x10xf32>> {name = "a", structured = false}
4238
!CHECK: [[IF1:%.*]] = arith.constant true
@@ -45,12 +41,10 @@ subroutine acc_enter_data
4541
!$acc enter data create(a) if(ifCondition)
4642
!CHECK: %[[ONE:.*]] = arith.constant 1 : index
4743
!CHECK: %[[LB:.*]] = arith.constant 0 : index
48-
!CHECK: %[[LBEXT:.*]] = arith.addi %[[C10]], %[[ONE]] : index
49-
!CHECK: %[[UB:.*]] = arith.subi %[[LBEXT]], %[[ONE]] : index
44+
!CHECK: %[[UB:.*]] = arith.subi %[[C10]], %[[ONE]] : index
5045
!CHECK: %[[BOUND0:.*]] = acc.bounds lowerbound(%[[LB]] : index) upperbound(%[[UB]] : index) stride(%[[ONE]] : index) startIdx(%[[ONE]] : index)
5146
!CHECK: %[[LB:.*]] = arith.constant 0 : index
52-
!CHECK: %[[LBEXT:.*]] = arith.addi %[[EXTENT_C10]], %[[ONE]] : index
53-
!CHECK: %[[UB:.*]] = arith.subi %[[LBEXT]], %[[ONE]] : index
47+
!CHECK: %[[UB:.*]] = arith.subi %[[EXTENT_C10]], %[[ONE]] : index
5448
!CHECK: %[[BOUND1:.*]] = acc.bounds lowerbound(%[[LB]] : index) upperbound(%[[UB]] : index) stride(%[[ONE]] : index) startIdx(%[[ONE]] : index)
5549
!CHECK: %[[CREATE_A:.*]] = acc.create varPtr(%[[A]] : !fir.ref<!fir.array<10x10xf32>>) bounds(%[[BOUND0]], %[[BOUND1]]) -> !fir.ref<!fir.array<10x10xf32>> {name = "a", structured = false}
5650
!CHECK: [[IFCOND:%.*]] = fir.load %{{.*}} : !fir.ref<!fir.logical<4>>
@@ -266,6 +260,7 @@ subroutine acc_enter_data_dummy(a, b, n, m)
266260
! Test lowering of array section for non default lower bound.
267261
subroutine acc_enter_data_non_default_lb()
268262
integer :: a(0:9)
263+
integer :: b(11:20)
269264

270265
!CHECK-LABEL: func.func @_QPacc_enter_data_non_default_lb() {
271266
!CHECK: %[[BASELB:.*]] = arith.constant 0 : index
@@ -306,6 +301,14 @@ subroutine acc_enter_data_non_default_lb()
306301
!CHECK: %[[UB:.*]] = arith.subi %[[LBEXT]], %[[ONE]] : index
307302
!CHECK: %[[BOUND:.*]] = acc.bounds lowerbound(%[[LB]] : index) upperbound(%[[UB]] : index) stride(%[[ONE]] : index) startIdx(%[[BASELB]] : index)
308303
!CHECK: %[[CREATE:.*]] = acc.create varPtr(%[[A]] : !fir.ref<!fir.array<10xi32>>) bounds(%[[BOUND]]) -> !fir.ref<!fir.array<10xi32>> {name = "a(4:)", structured = false}
304+
!CHECK: acc.enter_data dataOperands(%[[CREATE]] : !fir.ref<!fir.array<10xi32>>)
305+
306+
!$acc enter data create(b)
307+
!CHECK: %[[ONE:.*]] = arith.constant 1 : index
308+
!CHECK: %[[LB:.*]] = arith.constant 0 : index
309+
!CHECK: %[[UB:.*]] = arith.subi %c10{{.*}}, %[[ONE]] : index
310+
!CHECK: %[[BOUND:.*]] = acc.bounds lowerbound(%[[LB]] : index) upperbound(%[[UB]] : index) stride(%[[ONE]] : index) startIdx(%c11{{.*}} : index)
311+
!CHECK: %[[CREATE:.*]] = acc.create varPtr(%1 : !fir.ref<!fir.array<10xi32>>) bounds(%[[BOUND]]) -> !fir.ref<!fir.array<10xi32>> {name = "b", structured = false}
309312
!CHECK: acc.enter_data dataOperands(%[[CREATE]] : !fir.ref<!fir.array<10xi32>>)
310313

311314
end subroutine
@@ -598,8 +601,7 @@ subroutine acc_enter_data_derived_type()
598601
!CHECK: %[[C10:.*]] = arith.constant 10 : index
599602
!CHECK: %[[C1:.*]] = arith.constant 1 : index
600603
!CHECK: %[[LB:.*]] = arith.constant 0 : index
601-
!CHECK: %[[LBEXT:.*]] = arith.addi %[[C10]], %[[C1]] : index
602-
!CHECK: %[[UB:.*]] = arith.subi %[[LBEXT]], %[[C1]] : index
604+
!CHECK: %[[UB:.*]] = arith.subi %[[C10]], %[[C1]] : index
603605
!CHECK: %[[BOUND:.*]] = acc.bounds lowerbound(%[[LB]] : index) upperbound(%[[UB]] : index) stride(%[[C1]] : index) startIdx(%[[C1]] : index)
604606
!CHECK: %[[CREATE:.*]] = acc.create varPtr(%[[ARRAY_COORD]] : !fir.ref<!fir.array<10xf32>>) bounds(%[[BOUND]]) -> !fir.ref<!fir.array<10xf32>> {name = "a%array", structured = false}
605607
!CHECK: acc.enter_data dataOperands(%[[CREATE]] : !fir.ref<!fir.array<10xf32>>)
@@ -655,8 +657,7 @@ subroutine acc_enter_data_derived_type()
655657
!CHECK: %[[C10:.*]] = arith.constant 10 : index
656658
!CHECK: %[[C1:.*]] = arith.constant 1 : index
657659
!CHECK: %[[LB:.*]] = arith.constant 0 : index
658-
!CHECK: %[[LBEXT:.*]] = arith.addi %[[C10]], %[[C1]] : index
659-
!CHECK: %[[UB:.*]] = arith.subi %[[LBEXT]], %[[C1]] : index
660+
!CHECK: %[[UB:.*]] = arith.subi %[[C10]], %[[C1]] : index
660661
!CHECK: %[[BOUND:.*]] = acc.bounds lowerbound(%[[LB]] : index) upperbound(%[[UB]] : index) stride(%[[C1]] : index) startIdx(%[[C1]] : index)
661662
!CHECK: %[[CREATE:.*]] = acc.create varPtr(%[[ARRAY_COORD]] : !fir.ref<!fir.array<10xf32>>) bounds(%[[BOUND]]) -> !fir.ref<!fir.array<10xf32>> {name = "b%d%array", structured = false}
662663

@@ -687,8 +688,7 @@ subroutine acc_enter_data_derived_type()
687688
!CHECK: %[[C10:.*]] = arith.constant 10 : index
688689
!CHECK: %[[C1:.*]] = arith.constant 1 : index
689690
!CHECK: %[[LB:.*]] = arith.constant 0 : index
690-
!CHECK: %[[LBEXT:.*]] = arith.addi %[[C10]], %[[C1]] : index
691-
!CHECK: %[[UB:.*]] = arith.subi %[[LBEXT]], %[[C1]] : index
691+
!CHECK: %[[UB:.*]] = arith.subi %[[C10]], %[[C1]] : index
692692
!CHECK: %[[BOUND:.*]] = acc.bounds lowerbound(%[[LB]] : index) upperbound(%[[UB]] : index) stride(%[[C1]] : index) startIdx(%[[C1]] : index)
693693
!CHECK: %[[CREATE:.*]] = acc.create varPtr(%[[ARRAY_COORD]] : !fir.ref<!fir.array<10xf32>>) bounds(%[[BOUND]]) -> !fir.ref<!fir.array<10xf32>> {name = "d%d(1_8)%array", structured = false}
694694
!CHECK: acc.enter_data dataOperands(%[[CREATE]] : !fir.ref<!fir.array<10xf32>>)

0 commit comments

Comments
 (0)