diff --git a/flang/lib/Optimizer/OpenACC/Support/FIROpenACCTypeInterfaces.cpp b/flang/lib/Optimizer/OpenACC/Support/FIROpenACCTypeInterfaces.cpp index 7d3d0d7d383f8..684de4b2fd4a5 100644 --- a/flang/lib/Optimizer/OpenACC/Support/FIROpenACCTypeInterfaces.cpp +++ b/flang/lib/Optimizer/OpenACC/Support/FIROpenACCTypeInterfaces.cpp @@ -587,6 +587,8 @@ mlir::Value OpenACCMappableModel::generatePrivateInit( loops.push_back(loop); ivs.push_back(loop.getInductionVar()); } + // Reverse IVs to match CoordinateOp's canonical index order. + 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.shape<3>) -> (!fir.ref>, !fir.ref>) +! 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>, index, index, index) -> !fir.ref +! CHECK: fir.store %[[INIT]] to %[[COORD]] : !fir.ref ! CHECK: acc.yield %[[DECLARE]]#0 : !fir.ref> ! CHECK: } combiner { ! CHECK: ^bb0(%[[ARG0:.*]]: !fir.ref>, %[[ARG1:.*]]: !fir.ref>): 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.shape<3>) -> (!fir.ref>, !fir.ref>) +! 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>, index, index, index) -> !fir.ref +! CHECK: fir.store %[[INIT]] to %[[COORD]] : !fir.ref ! CHECK: acc.yield %[[DECLARE]]#0 : !fir.ref> ! CHECK: } combiner { ! CHECK: ^bb0(%[[ARG0:.*]]: !fir.ref>, %[[ARG1:.*]]: !fir.ref>):