[flang-commits] [flang] 0e54374 - [flang][openacc] Support .eqv. reduction operator
Valentin Clement via flang-commits
flang-commits at lists.llvm.org
Wed Jul 12 13:00:25 PDT 2023
Author: Valentin Clement
Date: 2023-07-12T13:00:10-07:00
New Revision: 0e543747ab42b49bf7ca2e78a76639ac9bc1fda8
URL: https://github.com/llvm/llvm-project/commit/0e543747ab42b49bf7ca2e78a76639ac9bc1fda8
DIFF: https://github.com/llvm/llvm-project/commit/0e543747ab42b49bf7ca2e78a76639ac9bc1fda8.diff
LOG: [flang][openacc] Support .eqv. reduction operator
Add support for the `.eqv.` reduction operator for
Flang/OpenACC lowering.
Depends on D154898
Reviewed By: razvanlupusoru
Differential Revision: https://reviews.llvm.org/D154900
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 ac4858551ce043..dc7bd872282d57 100644
--- a/flang/lib/Lower/OpenACC.cpp
+++ b/flang/lib/Lower/OpenACC.cpp
@@ -754,6 +754,18 @@ static mlir::Value genLogicalCombiner(fir::FirOpBuilder &builder,
return builder.create<fir::ConvertOp>(loc, value1.getType(), add);
}
+static mlir::Value genComparisonCombiner(fir::FirOpBuilder &builder,
+ mlir::Location loc,
+ mlir::arith::CmpIPredicate pred,
+ mlir::Value value1,
+ mlir::Value value2) {
+ mlir::Type i1 = builder.getI1Type();
+ mlir::Value v1 = builder.create<fir::ConvertOp>(loc, i1, value1);
+ mlir::Value v2 = builder.create<fir::ConvertOp>(loc, i1, value2);
+ mlir::Value add = builder.create<mlir::arith::CmpIOp>(loc, pred, v1, v2);
+ return builder.create<fir::ConvertOp>(loc, value1.getType(), add);
+}
+
static mlir::Value genCombiner(fir::FirOpBuilder &builder, mlir::Location loc,
mlir::acc::ReductionOperator op, mlir::Type ty,
mlir::Value value1, mlir::Value value2) {
@@ -831,6 +843,10 @@ static mlir::Value genCombiner(fir::FirOpBuilder &builder, mlir::Location loc,
if (op == mlir::acc::ReductionOperator::AccLor)
return genLogicalCombiner<mlir::arith::OrIOp>(builder, loc, value1, value2);
+ if (op == mlir::acc::ReductionOperator::AccEqv)
+ return genComparisonCombiner(builder, loc, mlir::arith::CmpIPredicate::eq,
+ 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 9fda6711dd0d73..e01b0b45eaebfe 100644
--- a/flang/test/Lower/OpenACC/acc-reduction.f90
+++ b/flang/test/Lower/OpenACC/acc-reduction.f90
@@ -2,6 +2,19 @@
! RUN: bbc -fopenacc -emit-fir %s -o - | FileCheck %s
+! CHECK-LABEL: acc.reduction.recipe @reduction_eqv_l32 : !fir.logical<4> reduction_operator <eqv> init {
+! CHECK: ^bb0(%{{.*}}: !fir.logical<4>):
+! CHECK: %[[CST:.*]] = arith.constant true
+! CHECK: acc.yield %[[CST]] : i1
+! CHECK: } combiner {
+! CHECK: ^bb0(%[[ARG0:.*]]: !fir.logical<4>, %[[ARG1:.*]]: !fir.logical<4>):
+! CHECK: %[[V1:.*]] = fir.convert %[[ARG0]] : (!fir.logical<4>) -> i1
+! CHECK: %[[V2:.*]] = fir.convert %[[ARG1]] : (!fir.logical<4>) -> i1
+! CHECK: %[[EQV:.*]] = arith.cmpi eq, %[[V1]], %[[V2]] : i1
+! CHECK: %[[CONV:.*]] = fir.convert %[[EQV]] : (i1) -> !fir.logical<4>
+! CHECK: acc.yield %[[CONV]] : !fir.logical<4>
+! CHECK: }
+
! CHECK-LABEL: acc.reduction.recipe @reduction_lor_l32 : !fir.logical<4> reduction_operator <lor> init {
! CHECK: ^bb0(%{{.*}}: !fir.logical<4>):
! CHECK: %[[CST:.*]] = arith.constant false
@@ -683,3 +696,13 @@ subroutine acc_reduction_or()
! CHECK-LABEL: func.func @_QPacc_reduction_or()
! CHECK: %[[RED:.*]] = acc.reduction varPtr(%{{.*}} : !fir.ref<!fir.logical<4>>) -> !fir.ref<!fir.logical<4>> {name = "l"}
! CHECK: acc.parallel reduction(@reduction_lor_l32 -> %[[RED]] : !fir.ref<!fir.logical<4>>)
+
+subroutine acc_reduction_eqv()
+ logical :: l
+ !$acc parallel reduction(.eqv.:l)
+ !$acc end parallel
+end subroutine
+
+! CHECK-LABEL: func.func @_QPacc_reduction_eqv()
+! CHECK: %[[RED:.*]] = acc.reduction varPtr(%{{.*}} : !fir.ref<!fir.logical<4>>) -> !fir.ref<!fir.logical<4>> {name = "l"}
+! CHECK: acc.parallel reduction(@reduction_eqv_l32 -> %[[RED]] : !fir.ref<!fir.logical<4>>)
More information about the flang-commits
mailing list