[flang-commits] [flang] 85f4593 - [flang] Add a REDUCE clause to each nested loop (#95555)
via flang-commits
flang-commits at lists.llvm.org
Mon Jun 17 09:21:33 PDT 2024
Author: khaki3
Date: 2024-06-17T09:21:30-07:00
New Revision: 85f4593e856e5034c5de1e6bbea13fb59e1995f5
URL: https://github.com/llvm/llvm-project/commit/85f4593e856e5034c5de1e6bbea13fb59e1995f5
DIFF: https://github.com/llvm/llvm-project/commit/85f4593e856e5034c5de1e6bbea13fb59e1995f5.diff
LOG: [flang] Add a REDUCE clause to each nested loop (#95555)
For DO CONCURRENT REDUCE, every nested loop should have a REDUCE clause
so that we can lower reduction without analysis.
Added:
Modified:
flang/lib/Lower/Bridge.cpp
flang/test/Lower/loops3.f90
Removed:
################################################################################
diff --git a/flang/lib/Lower/Bridge.cpp b/flang/lib/Lower/Bridge.cpp
index c73d43210a260..24a57812ba104 100644
--- a/flang/lib/Lower/Bridge.cpp
+++ b/flang/lib/Lower/Bridge.cpp
@@ -1801,14 +1801,16 @@ class FirConverter : public Fortran::lower::AbstractConverter {
std::get_if<Fortran::parser::LocalitySpec::LocalInit>(&x.u))
for (const Fortran::parser::Name &x : localInitList->v)
info.localInitSymList.push_back(x.symbol);
- if (const auto *reduceList =
- std::get_if<Fortran::parser::LocalitySpec::Reduce>(&x.u)) {
- fir::ReduceOperationEnum reduce_operation = getReduceOperationEnum(
- std::get<Fortran::parser::ReductionOperator>(reduceList->t));
- for (const Fortran::parser::Name &x :
- std::get<std::list<Fortran::parser::Name>>(reduceList->t)) {
- info.reduceSymList.push_back(
- std::make_pair(reduce_operation, x.symbol));
+ for (IncrementLoopInfo &info : incrementLoopNestInfo) {
+ if (const auto *reduceList =
+ std::get_if<Fortran::parser::LocalitySpec::Reduce>(&x.u)) {
+ fir::ReduceOperationEnum reduce_operation = getReduceOperationEnum(
+ std::get<Fortran::parser::ReductionOperator>(reduceList->t));
+ for (const Fortran::parser::Name &x :
+ std::get<std::list<Fortran::parser::Name>>(reduceList->t)) {
+ info.reduceSymList.push_back(
+ std::make_pair(reduce_operation, x.symbol));
+ }
}
}
if (const auto *sharedList =
diff --git a/flang/test/Lower/loops3.f90 b/flang/test/Lower/loops3.f90
index 2e62ee480ec8a..78f39e1013082 100644
--- a/flang/test/Lower/loops3.f90
+++ b/flang/test/Lower/loops3.f90
@@ -12,8 +12,8 @@ subroutine loop_test
! CHECK: %[[VAL_0:.*]] = fir.alloca f32 {bindc_name = "m", uniq_name = "_QFloop_testEm"}
! CHECK: %[[VAL_1:.*]] = fir.address_of(@_QFloop_testEsum) : !fir.ref<i32>
- ! CHECK: fir.do_loop %{{.*}} = %{{.*}} to %{{.*}} step %{{.*}} unordered {
- ! CHECK: fir.do_loop %{{.*}} = %{{.*}} to %{{.*}} step %{{.*}} unordered {
+ ! CHECK: fir.do_loop %{{.*}} = %{{.*}} to %{{.*}} step %{{.*}} unordered reduce(#fir.reduce_attr<add> -> %[[VAL_1:.*]] : !fir.ref<i32>, #fir.reduce_attr<max> -> %[[VAL_0:.*]] : !fir.ref<f32>) {
+ ! CHECK: fir.do_loop %{{.*}} = %{{.*}} to %{{.*}} step %{{.*}} unordered reduce(#fir.reduce_attr<add> -> %[[VAL_1:.*]] : !fir.ref<i32>, #fir.reduce_attr<max> -> %[[VAL_0:.*]] : !fir.ref<f32>) {
! CHECK: fir.do_loop %{{.*}} = %{{.*}} to %{{.*}} step %{{.*}} unordered reduce(#fir.reduce_attr<add> -> %[[VAL_1:.*]] : !fir.ref<i32>, #fir.reduce_attr<max> -> %[[VAL_0:.*]] : !fir.ref<f32>) {
do concurrent (i=1:5, j=1:5, k=1:5) local(tmp) reduce(+:sum) reduce(max:m)
tmp = i + j + k
More information about the flang-commits
mailing list