[flang-commits] [flang] 1aa22fe - [flang][openacc] Support iand reduction operator
Valentin Clement via flang-commits
flang-commits at lists.llvm.org
Tue Jul 11 08:50:54 PDT 2023
Author: Valentin Clement
Date: 2023-07-11T08:50:48-07:00
New Revision: 1aa22fe5cee079e7131bcd77f001ff5e500c19f3
URL: https://github.com/llvm/llvm-project/commit/1aa22fe5cee079e7131bcd77f001ff5e500c19f3
DIFF: https://github.com/llvm/llvm-project/commit/1aa22fe5cee079e7131bcd77f001ff5e500c19f3.diff
LOG: [flang][openacc] Support iand reduction operator
Add support for `iand` reduction operator in
OpenACC lowering.
Reviewed By: razvanlupusoru
Differential Revision: https://reviews.llvm.org/D154886
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 d8bde8b177b01f..3627a1ceb455be 100644
--- a/flang/lib/Lower/OpenACC.cpp
+++ b/flang/lib/Lower/OpenACC.cpp
@@ -615,6 +615,12 @@ static R getReductionInitValue(mlir::acc::ReductionOperator op, mlir::Type ty) {
return llvm::APFloat::getSmallest(floatTy.getFloatSemantics(),
/*negative=*/true);
}
+ } else if (op == mlir::acc::ReductionOperator::AccIand) {
+ if constexpr (std::is_same_v<R, llvm::APInt>) {
+ assert(ty.isIntOrIndex() && "expect integer type");
+ unsigned bits = ty.getIntOrFloatBitWidth();
+ return llvm::APInt::getAllOnes(bits);
+ }
} else {
// +, ior, ieor init value -> 0
// * init value -> 1
@@ -642,7 +648,8 @@ static mlir::Value genReductionInitValue(fir::FirOpBuilder &builder,
if (op != mlir::acc::ReductionOperator::AccAdd &&
op != mlir::acc::ReductionOperator::AccMul &&
op != mlir::acc::ReductionOperator::AccMin &&
- op != mlir::acc::ReductionOperator::AccMax)
+ op != mlir::acc::ReductionOperator::AccMax &&
+ op != mlir::acc::ReductionOperator::AccIand)
TODO(loc, "reduction operator");
if (ty.isIntOrIndex())
@@ -746,6 +753,9 @@ static mlir::Value genCombiner(fir::FirOpBuilder &builder, mlir::Location loc,
if (op == mlir::acc::ReductionOperator::AccMax)
return fir::genMax(builder, loc, {value1, value2});
+ if (op == mlir::acc::ReductionOperator::AccIand)
+ return builder.create<mlir::arith::AndIOp>(loc, value1, value2);
+
TODO(loc, "reduction operator");
}
diff --git a/flang/test/Lower/OpenACC/acc-reduction.f90 b/flang/test/Lower/OpenACC/acc-reduction.f90
index 0f64e9e43b541e..bdb25619bc5727 100644
--- a/flang/test/Lower/OpenACC/acc-reduction.f90
+++ b/flang/test/Lower/OpenACC/acc-reduction.f90
@@ -2,6 +2,16 @@
! RUN: bbc -fopenacc -emit-fir %s -o - | FileCheck %s
+! CHECK-LABEL: acc.reduction.recipe @reduction_iand_i32 : i32 reduction_operator <iand> init {
+! CHECK: ^bb0(%{{.*}}: i32):
+! CHECK: %[[CST:.*]] = arith.constant -1 : i32
+! CHECK: acc.yield %[[CST]] : i32
+! CHECK: } combiner {
+! CHECK: ^bb0(%[[ARG0:.*]]: i32, %[[ARG1:.*]]: i32):
+! CHECK: %[[COMBINED:.*]] = arith.andi %[[ARG0]], %[[ARG1]] : i32
+! CHECK: acc.yield %[[COMBINED]] : i32
+! CHECK: }
+
! CHECK-LABEL: acc.reduction.recipe @reduction_max_ref_100xf32 : !fir.ref<!fir.array<100xf32>> reduction_operator <max> init {
! CHECK: ^bb0(%{{.*}}: !fir.ref<!fir.array<100xf32>>):
! CHECK: %[[CST:.*]] = arith.constant dense<-1.401300e-45> : vector<100xf32>
@@ -578,3 +588,12 @@ subroutine acc_reduction_max_float_array1d(a, b)
! CHECK: %[[RED_ARG1:.*]] = acc.reduction varPtr(%[[ARG1]] : !fir.ref<!fir.array<100xf32>>) bounds(%{{.*}}) -> !fir.ref<!fir.array<100xf32>> {name = "b"}
! CHECK: acc.loop reduction(@reduction_max_ref_100xf32 -> %[[RED_ARG1]] : !fir.ref<!fir.array<100xf32>>) {
+subroutine acc_reduction_iand()
+ integer :: i
+ !$acc parallel reduction(iand:i)
+ !$acc end parallel
+end subroutine
+
+! CHECK-LABEL: func.func @_QPacc_reduction_iand()
+! CHECK: %[[RED:.*]] = acc.reduction varPtr(%{{.*}} : !fir.ref<i32>) -> !fir.ref<i32> {name = "i"}
+! CHECK: acc.parallel reduction(@reduction_iand_i32 -> %[[RED]] : !fir.ref<i32>)
More information about the flang-commits
mailing list