Skip to content

Commit 85f4593

Browse files
authored
[flang] Add a REDUCE clause to each nested loop (llvm#95555)
For DO CONCURRENT REDUCE, every nested loop should have a REDUCE clause so that we can lower reduction without analysis.
1 parent fae31e2 commit 85f4593

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

flang/lib/Lower/Bridge.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1801,14 +1801,16 @@ class FirConverter : public Fortran::lower::AbstractConverter {
18011801
std::get_if<Fortran::parser::LocalitySpec::LocalInit>(&x.u))
18021802
for (const Fortran::parser::Name &x : localInitList->v)
18031803
info.localInitSymList.push_back(x.symbol);
1804-
if (const auto *reduceList =
1805-
std::get_if<Fortran::parser::LocalitySpec::Reduce>(&x.u)) {
1806-
fir::ReduceOperationEnum reduce_operation = getReduceOperationEnum(
1807-
std::get<Fortran::parser::ReductionOperator>(reduceList->t));
1808-
for (const Fortran::parser::Name &x :
1809-
std::get<std::list<Fortran::parser::Name>>(reduceList->t)) {
1810-
info.reduceSymList.push_back(
1811-
std::make_pair(reduce_operation, x.symbol));
1804+
for (IncrementLoopInfo &info : incrementLoopNestInfo) {
1805+
if (const auto *reduceList =
1806+
std::get_if<Fortran::parser::LocalitySpec::Reduce>(&x.u)) {
1807+
fir::ReduceOperationEnum reduce_operation = getReduceOperationEnum(
1808+
std::get<Fortran::parser::ReductionOperator>(reduceList->t));
1809+
for (const Fortran::parser::Name &x :
1810+
std::get<std::list<Fortran::parser::Name>>(reduceList->t)) {
1811+
info.reduceSymList.push_back(
1812+
std::make_pair(reduce_operation, x.symbol));
1813+
}
18121814
}
18131815
}
18141816
if (const auto *sharedList =

flang/test/Lower/loops3.f90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ subroutine loop_test
1212

1313
! CHECK: %[[VAL_0:.*]] = fir.alloca f32 {bindc_name = "m", uniq_name = "_QFloop_testEm"}
1414
! CHECK: %[[VAL_1:.*]] = fir.address_of(@_QFloop_testEsum) : !fir.ref<i32>
15-
! CHECK: fir.do_loop %{{.*}} = %{{.*}} to %{{.*}} step %{{.*}} unordered {
16-
! CHECK: fir.do_loop %{{.*}} = %{{.*}} to %{{.*}} step %{{.*}} unordered {
15+
! 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>) {
16+
! 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>) {
1717
! 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>) {
1818
do concurrent (i=1:5, j=1:5, k=1:5) local(tmp) reduce(+:sum) reduce(max:m)
1919
tmp = i + j + k

0 commit comments

Comments
 (0)