[flang-commits] [flang] dd1a4bb - [flang][openacc] Add support for complex mul reduction
Valentin Clement via flang-commits
flang-commits at lists.llvm.org
Thu Jul 13 11:18:25 PDT 2023
Author: Valentin Clement
Date: 2023-07-13T11:18:20-07:00
New Revision: dd1a4bb0d4914fb2768195763bd8065712d10216
URL: https://github.com/llvm/llvm-project/commit/dd1a4bb0d4914fb2768195763bd8065712d10216
DIFF: https://github.com/llvm/llvm-project/commit/dd1a4bb0d4914fb2768195763bd8065712d10216.diff
LOG: [flang][openacc] Add support for complex mul reduction
Add support to lower reduction with the multiply operator and
complex type.
Depends on D155007
Reviewed By: razvanlupusoru
Differential Revision: https://reviews.llvm.org/D155014
Added:
Modified:
flang/lib/Lower/OpenACC.cpp
flang/test/Lower/OpenACC/acc-reduction.f90
Removed:
################################################################################
diff --git a/flang/lib/Lower/OpenACC.cpp b/flang/lib/Lower/OpenACC.cpp
index f3195249f6bb57..60d6d56e9880ef 100644
--- a/flang/lib/Lower/OpenACC.cpp
+++ b/flang/lib/Lower/OpenACC.cpp
@@ -715,10 +715,11 @@ static mlir::Value genReductionInitValue(fir::FirOpBuilder &builder,
} else if (auto cmplxTy = mlir::dyn_cast_or_null<fir::ComplexType>(ty)) {
mlir::Type floatTy =
Fortran::lower::convertReal(builder.getContext(), cmplxTy.getFKind());
- mlir::Value init = builder.createRealConstant(
+ mlir::Value realInit = builder.createRealConstant(
loc, floatTy, getReductionInitValue<int64_t>(op, cmplxTy));
- return fir::factory::Complex{builder, loc}.createComplex(cmplxTy.getFKind(),
- init, init);
+ mlir::Value imagInit = builder.createRealConstant(loc, floatTy, 0.0);
+ return fir::factory::Complex{builder, loc}.createComplex(
+ cmplxTy.getFKind(), realInit, imagInit);
}
if (auto refTy = mlir::dyn_cast<fir::ReferenceType>(ty)) {
if (auto seqTy = mlir::dyn_cast<fir::SequenceType>(refTy.getEleTy())) {
@@ -820,6 +821,8 @@ static mlir::Value genCombiner(fir::FirOpBuilder &builder, mlir::Location loc,
return builder.create<mlir::arith::MulIOp>(loc, value1, value2);
if (mlir::isa<mlir::FloatType>(ty))
return builder.create<mlir::arith::MulFOp>(loc, value1, value2);
+ if (mlir::isa<fir::ComplexType>(ty))
+ return builder.create<fir::MulcOp>(loc, value1, value2);
TODO(loc, "reduction mul type");
}
diff --git a/flang/test/Lower/OpenACC/acc-reduction.f90 b/flang/test/Lower/OpenACC/acc-reduction.f90
index 9e6fa5c01a6a57..976562bcacc25d 100644
--- a/flang/test/Lower/OpenACC/acc-reduction.f90
+++ b/flang/test/Lower/OpenACC/acc-reduction.f90
@@ -2,12 +2,27 @@
! RUN: bbc -fopenacc -emit-fir %s -o - | FileCheck %s
+! CHECK-LABEL: acc.reduction.recipe @reduction_mul_z32 : !fir.complex<4> reduction_operator <mul> init {
+! CHECK: ^bb0(%{{.*}}: !fir.complex<4>):
+! CHECK: %[[REAL:.*]] = arith.constant 1.000000e+00 : f32
+! CHECK: %[[IMAG:.*]] = arith.constant 0.000000e+00 : f32
+! CHECK: %[[UNDEF:.*]] = fir.undefined !fir.complex<4>
+! CHECK: %[[UNDEF1:.*]] = fir.insert_value %[[UNDEF]], %[[REAL]], [0 : index] : (!fir.complex<4>, f32) -> !fir.complex<4>
+! CHECK: %[[UNDEF2:.*]] = fir.insert_value %[[UNDEF1]], %[[IMAG]], [1 : index] : (!fir.complex<4>, f32) -> !fir.complex<4>
+! CHECK: acc.yield %[[UNDEF2]] : !fir.complex<4>
+! CHECK: } combiner {
+! CHECK: ^bb0(%[[ARG0:.*]]: !fir.complex<4>, %[[ARG1:.*]]: !fir.complex<4>):
+! CHECK: %[[COMBINED:.*]] = fir.mulc %[[ARG0]], %[[ARG1]] : !fir.complex<4>
+! CHECK: acc.yield %[[COMBINED]] : !fir.complex<4>
+! CHECK: }
+
! CHECK-LABEL: acc.reduction.recipe @reduction_add_z32 : !fir.complex<4> reduction_operator <add> init {
! CHECK: ^bb0(%{{.*}}: !fir.complex<4>):
-! CHECK: %[[CST:.*]] = arith.constant 0.000000e+00 : f32
+! CHECK: %[[REAL:.*]] = arith.constant 0.000000e+00 : f32
+! CHECK: %[[IMAG:.*]] = arith.constant 0.000000e+00 : f32
! CHECK: %[[UNDEF:.*]] = fir.undefined !fir.complex<4>
-! CHECK: %[[UNDEF1:.*]] = fir.insert_value %[[UNDEF]], %[[CST]], [0 : index] : (!fir.complex<4>, f32) -> !fir.complex<4>
-! CHECK: %[[UNDEF2:.*]] = fir.insert_value %[[UNDEF1]], %[[CST]], [1 : index] : (!fir.complex<4>, f32) -> !fir.complex<4>
+! CHECK: %[[UNDEF1:.*]] = fir.insert_value %[[UNDEF]], %[[REAL]], [0 : index] : (!fir.complex<4>, f32) -> !fir.complex<4>
+! CHECK: %[[UNDEF2:.*]] = fir.insert_value %[[UNDEF1]], %[[IMAG]], [1 : index] : (!fir.complex<4>, f32) -> !fir.complex<4>
! CHECK: acc.yield %[[UNDEF2]] : !fir.complex<4>
! CHECK: } combiner {
! CHECK: ^bb0(%[[ARG0:.*]]: !fir.complex<4>, %[[ARG1:.*]]: !fir.complex<4>):
@@ -752,3 +767,13 @@ subroutine acc_reduction_add_cmplx()
! CHECK-LABEL: func.func @_QPacc_reduction_add_cmplx()
! CHECK: %[[RED:.*]] = acc.reduction varPtr(%{{.*}} : !fir.ref<!fir.complex<4>>) -> !fir.ref<!fir.complex<4>> {name = "c"}
! CHECK: acc.parallel reduction(@reduction_add_z32 -> %[[RED]] : !fir.ref<!fir.complex<4>>)
+
+subroutine acc_reduction_mul_cmplx()
+ complex :: c
+ !$acc parallel reduction(*:c)
+ !$acc end parallel
+end subroutine
+
+! CHECK-LABEL: func.func @_QPacc_reduction_mul_cmplx()
+! CHECK: %[[RED:.*]] = acc.reduction varPtr(%{{.*}} : !fir.ref<!fir.complex<4>>) -> !fir.ref<!fir.complex<4>> {name = "c"}
+! CHECK: acc.parallel reduction(@reduction_mul_z32 -> %[[RED]] : !fir.ref<!fir.complex<4>>)
More information about the flang-commits
mailing list