[flang-commits] [flang] 425c574 - [flang][openacc] Support ieor reduction operator

Valentin Clement via flang-commits flang-commits at lists.llvm.org
Tue Jul 11 08:58:45 PDT 2023


Author: Valentin Clement
Date: 2023-07-11T08:58:36-07:00
New Revision: 425c57489283adcaa28e916c5b1c2826e7a0e042

URL: https://github.com/llvm/llvm-project/commit/425c57489283adcaa28e916c5b1c2826e7a0e042
DIFF: https://github.com/llvm/llvm-project/commit/425c57489283adcaa28e916c5b1c2826e7a0e042.diff

LOG: [flang][openacc] Support ieor reduction operator

Add support for `ieor` reduction operator in
OpenACC lowering.

Depends on D154887

Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D154888

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 78d36714d35e0c..b36d81b94114da 100644
--- a/flang/lib/Lower/OpenACC.cpp
+++ b/flang/lib/Lower/OpenACC.cpp
@@ -650,7 +650,8 @@ static mlir::Value genReductionInitValue(fir::FirOpBuilder &builder,
       op != mlir::acc::ReductionOperator::AccMin &&
       op != mlir::acc::ReductionOperator::AccMax &&
       op != mlir::acc::ReductionOperator::AccIand &&
-      op != mlir::acc::ReductionOperator::AccIor)
+      op != mlir::acc::ReductionOperator::AccIor &&
+      op != mlir::acc::ReductionOperator::AccXor)
     TODO(loc, "reduction operator");
 
   if (ty.isIntOrIndex())
@@ -760,6 +761,9 @@ static mlir::Value genCombiner(fir::FirOpBuilder &builder, mlir::Location loc,
   if (op == mlir::acc::ReductionOperator::AccIor)
     return builder.create<mlir::arith::OrIOp>(loc, value1, value2);
 
+  if (op == mlir::acc::ReductionOperator::AccXor)
+    return builder.create<mlir::arith::XOrIOp>(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 9148a302c6a434..0171ce1fa84453 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_xor_i32 : i32 reduction_operator <xor> init {
+! CHECK: ^bb0(%{{.*}}: i32):
+! CHECK:   %[[CST:.*]] = arith.constant 0 : i32
+! CHECK:   acc.yield %[[CST]] : i32
+! CHECK: } combiner {
+! CHECK: ^bb0(%[[ARG0:.*]]: i32, %[[ARG1:.*]]: i32):
+! CHECK:   %[[COMBINED:.*]] = arith.xori %[[ARG0]], %[[ARG1]] : i32
+! CHECK:   acc.yield %[[COMBINED]] : i32
+! CHECK: }
+
 ! CHECK-LABEL: acc.reduction.recipe @reduction_ior_i32 : i32 reduction_operator <ior> init {
 ! CHECK: ^bb0(%{{.*}}: i32):
 ! CHECK:   %[[CST:.*]] = arith.constant 0 : i32
@@ -617,3 +627,13 @@ subroutine acc_reduction_ior()
 ! CHECK-LABEL: func.func @_QPacc_reduction_ior()
 ! CHECK: %[[RED:.*]] = acc.reduction varPtr(%{{.*}} : !fir.ref<i32>)   -> !fir.ref<i32> {name = "i"}
 ! CHECK: acc.parallel reduction(@reduction_ior_i32 -> %[[RED]] : !fir.ref<i32>)
+
+subroutine acc_reduction_ieor()
+  integer :: i
+  !$acc parallel reduction(ieor:i)
+  !$acc end parallel
+end subroutine
+
+! CHECK-LABEL: func.func @_QPacc_reduction_ieor()
+! CHECK: %[[RED:.*]] = acc.reduction varPtr(%{{.*}} : !fir.ref<i32>) -> !fir.ref<i32> {name = "i"}
+! CHECK: acc.parallel reduction(@reduction_xor_i32 -> %[[RED]] : !fir.ref<i32>)


        


More information about the flang-commits mailing list