diff --git a/flang/test/Lower/OpenACC/acc-data-operands.f90 b/flang/test/Lower/OpenACC/acc-data-operands.f90 --- a/flang/test/Lower/OpenACC/acc-data-operands.f90 +++ b/flang/test/Lower/OpenACC/acc-data-operands.f90 @@ -113,12 +113,88 @@ end subroutine -subroutine acc_operand_array_section2(a) - real, dimension(100) :: a +! Testing array sections on allocatable array +subroutine acc_operand_array_section_allocatable() + real, allocatable :: a(:) + + allocate(a(100)) + + !$acc data copyin(a(1:50)) copyout(a(51:100)) + !$acc end data + + !CHECK: %[[ARR_HEAP:.*]] = fir.alloca !fir.heap> {uniq_name = "_QMacc_data_operandFacc_operand_array_section_allocatableEa.addr"} + + !CHECK: %[[LOAD_ARR0:.*]] = fir.load %[[ARR_HEAP]] : !fir.ref>> + !CHECK: %[[C1_I32:.*]] = arith.constant 1 : i32 + !CHECK: %[[C1_I64:.*]] = fir.convert %[[C1_I32]] : (i32) -> i64 + !CHECK: %[[LB0:.*]] = fir.convert %[[C1_I64]] : (i64) -> index + !CHECK: %[[C1_STEP:.*]] = arith.constant 1 : i64 + !CHECK: %[[STEP0:.*]] = fir.convert %[[C1_STEP]] : (i64) -> index + !CHECK: %[[C50_I32:.*]] = arith.constant 50 : i32 + !CHECK: %[[C50_I64:.*]] = fir.convert %[[C50_I32]] : (i32) -> i64 + !CHECK: %[[UB0:.*]] = fir.convert %[[C50_I64]] : (i64) -> index + !CHECK: %[[SHAPE_SHIFT0:.*]] = fir.shape_shift %{{.*}}, %{{.*}} : (index, index) -> !fir.shapeshift<1> + !CHECK: %[[SLICE0:.*]] = fir.slice %[[LB0]], %[[UB0]], %[[STEP0]] : (index, index, index) -> !fir.slice<1> + !CHECK: %[[ARR_SECTION0:.*]] = fir.embox %[[LOAD_ARR0]](%[[SHAPE_SHIFT0]]) [%[[SLICE0]]] : (!fir.heap>, !fir.shapeshift<1>, !fir.slice<1>) -> !fir.box> + !CHECK: %[[MEM0:.*]] = fir.alloca !fir.box> + !CHECK: fir.store %[[ARR_SECTION0]] to %[[MEM0]] : !fir.ref>> + + !CHECK: %[[LOAD_ARR1:.*]] = fir.load %[[ARR_HEAP]] : !fir.ref>> + !CHECK: %[[C51_I32:.*]] = arith.constant 51 : i32 + !CHECK: %[[C51_I64:.*]] = fir.convert %[[C51_I32]] : (i32) -> i64 + !CHECK: %[[LB1:.*]] = fir.convert %[[C51_I64]] : (i64) -> index + !CHECK: %[[C1_STEP:.*]] = arith.constant 1 : i64 + !CHECK: %[[STEP1:.*]] = fir.convert %[[C1_STEP]] : (i64) -> index + !CHECK: %[[C100_I32:.*]] = arith.constant 100 : i32 + !CHECK: %[[C100_I64:.*]] = fir.convert %[[C100_I32]] : (i32) -> i64 + !CHECK: %[[UB1:.*]] = fir.convert %[[C100_I64]] : (i64) -> index + !CHECK: %[[SHAPE_SHIFT1:.*]] = fir.shape_shift %{{.*}}, %{{.*}} : (index, index) -> !fir.shapeshift<1> + !CHECK: %[[SLICE1:.*]] = fir.slice %[[LB1]], %[[UB1]], %[[STEP1]] : (index, index, index) -> !fir.slice<1> + !CHECK: %[[ARR_SECTION1:.*]] = fir.embox %[[LOAD_ARR1]](%[[SHAPE_SHIFT1]]) [%[[SLICE1]]] : (!fir.heap>, !fir.shapeshift<1>, !fir.slice<1>) -> !fir.box> + !CHECK: %[[MEM1:.*]] = fir.alloca !fir.box> + !CHECK: fir.store %[[ARR_SECTION1]] to %[[MEM1]] : !fir.ref>> + + !CHECK: acc.data copyin(%[[MEM0]] : !fir.ref>>) copyout(%[[MEM1]] : !fir.ref>>) + + deallocate(a) +end subroutine - !$acc data copyin(a) + +! Testing array sections on pointer array +subroutine acc_operand_array_section_pointer() + real, target :: a(100) + real, pointer :: p(:) + + p => a + + !$acc data copyin(p(1:50)) !$acc end data + !CHECK: %[[C100:.*]] = arith.constant 100 : index + !CHECK: %[[ARR:.*]] = fir.alloca !fir.array<100xf32> {bindc_name = "a", fir.target, uniq_name = "_QMacc_data_operandFacc_operand_array_section_pointerEa"} + !CHECK: %[[PTR:.*]] = fir.alloca !fir.box>> {bindc_name = "p", uniq_name = "_QMacc_data_operandFacc_operand_array_section_pointerEp"} + !CHECK: %[[SHAPE0:.*]] = fir.shape %[[C100]] : (index) -> !fir.shape<1> + !CHECK: %[[EMBOX0:.*]] = fir.embox %[[ARR]](%[[SHAPE0]]) : (!fir.ref>, !fir.shape<1>) -> !fir.box>> + !CHECK: fir.store %[[EMBOX0]] to %[[PTR]] : !fir.ref>>> + !CHECK: %[[PTR_LOAD:.*]] = fir.load %[[PTR]] : !fir.ref>>> + !CHECK: %[[C0:.*]] = arith.constant 0 : index + !CHECK: %[[BOX_DIMS:.*]]:3 = fir.box_dims %[[PTR_LOAD]], %[[C0]] : (!fir.box>>, index) -> (index, index, index) + !CHECK: %[[C1_I32:.*]] = arith.constant 1 : i32 + !CHECK: %[[C1_I64:.*]] = fir.convert %[[C1_I32]] : (i32) -> i64 + !CHECK: %[[LB0:.*]] = fir.convert %[[C1_I64]] : (i64) -> index + !CHECK: %[[C1_STEP:.*]] = arith.constant 1 : i64 + !CHECK: %[[STEP0:.*]] = fir.convert %[[C1_STEP]] : (i64) -> index + !CHECK: %[[C50_I32:.*]] = arith.constant 50 : i32 + !CHECK: %[[C50_I64:.*]] = fir.convert %[[C50_I32]] : (i32) -> i64 + !CHECK: %[[UB0:.*]] = fir.convert %[[C50_I64]] : (i64) -> index + !CHECK: %[[SHIFT0:.*]] = fir.shift %[[BOX_DIMS]]#0 : (index) -> !fir.shift<1> + !CHECK: %[[SLICE0:.*]] = fir.slice %[[LB0]], %[[UB0]], %[[STEP0]] : (index, index, index) -> !fir.slice<1> + !CHECK: %[[REBOX0:.*]] = fir.rebox %7(%[[SHIFT0]]) [%[[SLICE0]]] : (!fir.box>>, !fir.shift<1>, !fir.slice<1>) -> !fir.box> + !CHECK: %[[MEM0:.*]] = fir.alloca !fir.box> + !CHECK: fir.store %[[REBOX0]] to %[[MEM0]] : !fir.ref>> + + !CHECK: acc.data copyin(%[[MEM0]] : !fir.ref>>) { + end subroutine end module