[flang-commits] [flang] [flang][acc] Fix the indexing of the reduction initializer for multidimensional static arrays (PR #159848)
via flang-commits
flang-commits at lists.llvm.org
Fri Sep 19 13:54:52 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-fir-hlfir
Author: None (khaki3)
<details>
<summary>Changes</summary>
Similarly to https://github.com/llvm/llvm-project/pull/155536, this PR fixes incorrect coordinates for array access in the reduction initializer.
---
Full diff: https://github.com/llvm/llvm-project/pull/159848.diff
3 Files Affected:
- (modified) flang/lib/Optimizer/OpenACC/Support/FIROpenACCTypeInterfaces.cpp (+1)
- (modified) flang/test/Lower/OpenACC/acc-reduction-unwrap-defaultbounds.f90 (+14)
- (modified) flang/test/Lower/OpenACC/acc-reduction.f90 (+14)
``````````diff
diff --git a/flang/lib/Optimizer/OpenACC/Support/FIROpenACCTypeInterfaces.cpp b/flang/lib/Optimizer/OpenACC/Support/FIROpenACCTypeInterfaces.cpp
index 7d3d0d7d383f8..b1f13acf45732 100644
--- a/flang/lib/Optimizer/OpenACC/Support/FIROpenACCTypeInterfaces.cpp
+++ b/flang/lib/Optimizer/OpenACC/Support/FIROpenACCTypeInterfaces.cpp
@@ -587,6 +587,7 @@ mlir::Value OpenACCMappableModel<Ty>::generatePrivateInit(
loops.push_back(loop);
ivs.push_back(loop.getInductionVar());
}
+ std::reverse(ivs.begin(), ivs.end());
auto coord = fir::CoordinateOp::create(firBuilder, loc, refTy,
declareOp.getBase(), ivs);
fir::StoreOp::create(firBuilder, loc, initVal, coord);
diff --git a/flang/test/Lower/OpenACC/acc-reduction-unwrap-defaultbounds.f90 b/flang/test/Lower/OpenACC/acc-reduction-unwrap-defaultbounds.f90
index 02a152c9d7ae2..b48f530473740 100644
--- a/flang/test/Lower/OpenACC/acc-reduction-unwrap-defaultbounds.f90
+++ b/flang/test/Lower/OpenACC/acc-reduction-unwrap-defaultbounds.f90
@@ -597,6 +597,20 @@
! CHECK: %[[SHAPE:.*]] = fir.shape %{{.*}}, %{{.*}}, %{{.*}} : (index, index, index) -> !fir.shape<3>
! CHECK: %[[ALLOCA:.*]] = fir.alloca !fir.array<100x10x2xi32>
! CHECK: %[[DECLARE:.*]]:2 = hlfir.declare %[[ALLOCA]](%[[SHAPE]]) {uniq_name = "acc.reduction.init"} : (!fir.ref<!fir.array<100x10x2xi32>>, !fir.shape<3>) -> (!fir.ref<!fir.array<100x10x2xi32>>, !fir.ref<!fir.array<100x10x2xi32>>)
+! CHECK: %[[LB0:.*]] = arith.constant 0 : index
+! CHECK: %[[UB0:.*]] = arith.constant 1 : index
+! CHECK: %[[STEP0:.*]] = arith.constant 1 : index
+! CHECK: fir.do_loop %[[IV0:.*]] = %[[LB0]] to %[[UB0]] step %[[STEP0]] {
+! CHECK: %[[LB1:.*]] = arith.constant 0 : index
+! CHECK: %[[UB1:.*]] = arith.constant 9 : index
+! CHECK: %[[STEP1:.*]] = arith.constant 1 : index
+! CHECK: fir.do_loop %[[IV1:.*]] = %[[LB1]] to %[[UB1]] step %[[STEP1]] {
+! CHECK: %[[LB2:.*]] = arith.constant 0 : index
+! CHECK: %[[UB2:.*]] = arith.constant 99 : index
+! CHECK: %[[STEP2:.*]] = arith.constant 1 : index
+! CHECK: fir.do_loop %[[IV2:.*]] = %[[LB2]] to %[[UB2]] step %[[STEP2]] {
+! CHECK: %[[COORD]] = fir.coordinate_of %[[DECLARE]]#0, %[[IV2]], %[[IV1]], %[[IV0]] : (!fir.ref<!fir.array<100x10x2xi32>>, index, index, index) -> !fir.ref<i32>
+! CHECK: fir.store %[[INIT]] to %[[COORD]] : !fir.ref<i32>
! CHECK: acc.yield %[[DECLARE]]#0 : !fir.ref<!fir.array<100x10x2xi32>>
! CHECK: } combiner {
! CHECK: ^bb0(%[[ARG0:.*]]: !fir.ref<!fir.array<100x10x2xi32>>, %[[ARG1:.*]]: !fir.ref<!fir.array<100x10x2xi32>>):
diff --git a/flang/test/Lower/OpenACC/acc-reduction.f90 b/flang/test/Lower/OpenACC/acc-reduction.f90
index 2a896c6b8d771..6cb8bdf6b511a 100644
--- a/flang/test/Lower/OpenACC/acc-reduction.f90
+++ b/flang/test/Lower/OpenACC/acc-reduction.f90
@@ -646,6 +646,20 @@
! CHECK: %[[SHAPE:.*]] = fir.shape %{{.*}}, %{{.*}}, %{{.*}} : (index, index, index) -> !fir.shape<3>
! CHECK: %[[ALLOCA:.*]] = fir.alloca !fir.array<100x10x2xi32>
! CHECK: %[[DECLARE:.*]]:2 = hlfir.declare %[[ALLOCA]](%[[SHAPE]]) {uniq_name = "acc.reduction.init"} : (!fir.ref<!fir.array<100x10x2xi32>>, !fir.shape<3>) -> (!fir.ref<!fir.array<100x10x2xi32>>, !fir.ref<!fir.array<100x10x2xi32>>)
+! CHECK: %[[LB0:.*]] = arith.constant 0 : index
+! CHECK: %[[UB0:.*]] = arith.constant 1 : index
+! CHECK: %[[STEP0:.*]] = arith.constant 1 : index
+! CHECK: fir.do_loop %[[IV0:.*]] = %[[LB0]] to %[[UB0]] step %[[STEP0]] {
+! CHECK: %[[LB1:.*]] = arith.constant 0 : index
+! CHECK: %[[UB1:.*]] = arith.constant 9 : index
+! CHECK: %[[STEP1:.*]] = arith.constant 1 : index
+! CHECK: fir.do_loop %[[IV1:.*]] = %[[LB1]] to %[[UB1]] step %[[STEP1]] {
+! CHECK: %[[LB2:.*]] = arith.constant 0 : index
+! CHECK: %[[UB2:.*]] = arith.constant 99 : index
+! CHECK: %[[STEP2:.*]] = arith.constant 1 : index
+! CHECK: fir.do_loop %[[IV2:.*]] = %[[LB2]] to %[[UB2]] step %[[STEP2]] {
+! CHECK: %[[COORD]] = fir.coordinate_of %[[DECLARE]]#0, %[[IV2]], %[[IV1]], %[[IV0]] : (!fir.ref<!fir.array<100x10x2xi32>>, index, index, index) -> !fir.ref<i32>
+! CHECK: fir.store %[[INIT]] to %[[COORD]] : !fir.ref<i32>
! CHECK: acc.yield %[[DECLARE]]#0 : !fir.ref<!fir.array<100x10x2xi32>>
! CHECK: } combiner {
! CHECK: ^bb0(%[[ARG0:.*]]: !fir.ref<!fir.array<100x10x2xi32>>, %[[ARG1:.*]]: !fir.ref<!fir.array<100x10x2xi32>>):
``````````
</details>
https://github.com/llvm/llvm-project/pull/159848
More information about the flang-commits
mailing list