Skip to content

Commit 7f08f44

Browse files
committed
[flang][openacc][NFC] Add test for scalar allocatable and pointer reduction
Add test for simple scalar allocatable or pointer. Set up the TODO to be triggered when the allocatable or pointer are arrays. Support for pointer/allocatable arrays will come next. Reviewed By: razvanlupusoru Differential Revision: https://reviews.llvm.org/D155230
1 parent 45ff63b commit 7f08f44

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

flang/lib/Lower/OpenACC.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -929,7 +929,10 @@ genReductions(const Fortran::parser::AccObjectListWithReduction &objectList,
929929
if (auto seqTy = mlir::dyn_cast<fir::SequenceType>(reductionTy))
930930
reductionTy = seqTy.getEleTy();
931931

932-
if (!fir::isa_trivial(reductionTy))
932+
if (!fir::isa_trivial(reductionTy) &&
933+
((fir::isAllocatableType(reductionTy) ||
934+
fir::isPointerType(reductionTy)) &&
935+
!bounds.empty()))
933936
TODO(operandLocation, "reduction with unsupported type");
934937

935938
auto op = createDataEntryOp<mlir::acc::ReductionOp>(

flang/test/Lower/OpenACC/acc-reduction.f90

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -777,3 +777,30 @@ subroutine acc_reduction_mul_cmplx()
777777
! CHECK-LABEL: func.func @_QPacc_reduction_mul_cmplx()
778778
! CHECK: %[[RED:.*]] = acc.reduction varPtr(%{{.*}} : !fir.ref<!fir.complex<4>>) -> !fir.ref<!fir.complex<4>> {name = "c"}
779779
! CHECK: acc.parallel reduction(@reduction_mul_z32 -> %[[RED]] : !fir.ref<!fir.complex<4>>)
780+
781+
subroutine acc_reduction_add_alloc()
782+
integer, allocatable :: i
783+
allocate(i)
784+
!$acc parallel reduction(+:i)
785+
!$acc end parallel
786+
end subroutine
787+
788+
! CHECK-LABEL: func.func @_QPacc_reduction_add_alloc()
789+
! CHECK: %[[ALLOCA:.*]] = fir.alloca !fir.box<!fir.heap<i32>> {bindc_name = "i", uniq_name = "_QFacc_reduction_add_allocEi"}
790+
! CHECK: %[[LOAD:.*]] = fir.load %[[ALLOCA]] : !fir.ref<!fir.box<!fir.heap<i32>>>
791+
! CHECK: %[[BOX_ADDR:.*]] = fir.box_addr %[[LOAD]] : (!fir.box<!fir.heap<i32>>) -> !fir.heap<i32>
792+
! CHECK: %[[RED:.*]] = acc.reduction varPtr(%[[BOX_ADDR]] : !fir.heap<i32>) -> !fir.heap<i32> {name = "i"}
793+
! CHECK: acc.parallel reduction(@reduction_add_i32 -> %[[RED]] : !fir.heap<i32>)
794+
795+
subroutine acc_reduction_add_pointer(i)
796+
integer, pointer :: i
797+
!$acc parallel reduction(+:i)
798+
!$acc end parallel
799+
end subroutine
800+
801+
! CHECK-LABEL: func.func @_QPacc_reduction_add_pointer(
802+
! CHECK-SAME: %[[ARG0:.*]]: !fir.ref<!fir.box<!fir.ptr<i32>>> {fir.bindc_name = "i"})
803+
! CHECK: %[[LOAD:.*]] = fir.load %[[ARG0]] : !fir.ref<!fir.box<!fir.ptr<i32>>>
804+
! CHECK: %[[BOX_ADDR:.*]] = fir.box_addr %[[LOAD]] : (!fir.box<!fir.ptr<i32>>) -> !fir.ptr<i32>
805+
! CHECK: %[[RED:.*]] = acc.reduction varPtr(%[[BOX_ADDR]] : !fir.ptr<i32>) -> !fir.ptr<i32> {name = "i"}
806+
! CHECK: acc.parallel reduction(@reduction_add_i32 -> %[[RED]] : !fir.ptr<i32>)

0 commit comments

Comments
 (0)