[flang-commits] [flang] [Flang][OpenMP] Process reduction only once for parallel do (PR #70844)

Kiran Chandramohan via flang-commits flang-commits at lists.llvm.org
Tue Oct 31 11:01:10 PDT 2023


https://github.com/kiranchandramohan created https://github.com/llvm/llvm-project/pull/70844

None

>From 2773551850ce629f0ac2aa121709837b38511459 Mon Sep 17 00:00:00 2001
From: Kiran Chandramohan <kiran.chandramohan at arm.com>
Date: Tue, 31 Oct 2023 17:56:42 +0000
Subject: [PATCH] [Flang][OpenMP] Process reduction only once for parallel do

---
 flang/lib/Lower/OpenMP.cpp                       |  3 ++-
 .../Lower/OpenMP/parallel-wsloop-reduction.f90   | 16 ++++++++++++++++
 2 files changed, 18 insertions(+), 1 deletion(-)
 create mode 100644 flang/test/Lower/OpenMP/parallel-wsloop-reduction.f90

diff --git a/flang/lib/Lower/OpenMP.cpp b/flang/lib/Lower/OpenMP.cpp
index 0faaae6c08e0476..5b66219b2dd49e6 100644
--- a/flang/lib/Lower/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP.cpp
@@ -2268,7 +2268,8 @@ genParallelOp(Fortran::lower::AbstractConverter &converter,
   cp.processProcBind(procBindKindAttr);
   cp.processDefault();
   cp.processAllocate(allocatorOperands, allocateOperands);
-  cp.processReduction(currentLocation, reductionVars, reductionDeclSymbols);
+  if (!outerCombined)
+    cp.processReduction(currentLocation, reductionVars, reductionDeclSymbols);
 
   return genOpWithBody<mlir::omp::ParallelOp>(
       converter, eval, currentLocation, outerCombined, &clauseList,
diff --git a/flang/test/Lower/OpenMP/parallel-wsloop-reduction.f90 b/flang/test/Lower/OpenMP/parallel-wsloop-reduction.f90
new file mode 100644
index 000000000000000..c13ec2bc4aec82a
--- /dev/null
+++ b/flang/test/Lower/OpenMP/parallel-wsloop-reduction.f90
@@ -0,0 +1,16 @@
+! Check that for parallel do, reduction is only processed for the loop
+
+! RUN: bbc -fopenmp -emit-hlfir %s -o - | FileCheck %s
+! RUN: flang-new -fc1 -fopenmp -emit-hlfir %s -o - | FileCheck %s
+
+! CHECK: omp.parallel {
+! CHECK: omp.wsloop reduction(@add_reduction_i_32
+subroutine sb
+  integer :: x
+  x = 0
+  !$omp parallel do reduction(+:x)
+  do i=1,100
+    x = x + 1
+  end do
+  !$omp end parallel do
+end subroutine



More information about the flang-commits mailing list