-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[flang][acc] Fix the indexing of the reduction initializer for multidimensional static arrays #159848
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…imensional static arrays
@llvm/pr-subscribers-openacc @llvm/pr-subscribers-flang-fir-hlfir Author: None (khaki3) ChangesSimilarly to #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:
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>>):
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! Please add a comment - otherwise the change looks good to me.
Similarly to #155536, this PR fixes incorrect coordinates for array access in the reduction initializer.