Index: flang/lib/Optimizer/CodeGen/CodeGen.cpp =================================================================== --- flang/lib/Optimizer/CodeGen/CodeGen.cpp +++ flang/lib/Optimizer/CodeGen/CodeGen.cpp @@ -2073,13 +2073,8 @@ const bool isSliced = !coor.slice().empty(); const bool baseIsBoxed = coor.memref().getType().isa(); - auto indexOps = coor.indices().begin(); - auto shapeOps = coor.shape().begin(); - auto shiftOps = coor.shift().begin(); - auto sliceOps = coor.slice().begin(); // For each dimension of the array, generate the offset calculation. - for (unsigned i = 0; i < rank; - ++i, ++indexOps, ++shapeOps, ++shiftOps, sliceOps += 3) { + for (unsigned i = 0; i < rank; ++i) { mlir::Value index = integerCast(loc, rewriter, idxTy, operands[coor.indicesOffset() + i]); mlir::Value lb = isShifted ? integerCast(loc, rewriter, idxTy, @@ -2090,10 +2085,11 @@ // Compute zero based index in dimension i of the element, applying // potential triplets and lower bounds. if (isSliced) { - mlir::Value ub = *(sliceOps + 1); + mlir::Value ub = operands[coor.sliceOffset() + i + 1]; normalSlice = !mlir::isa_and_nonnull(ub.getDefiningOp()); if (normalSlice) - step = integerCast(loc, rewriter, idxTy, *(sliceOps + 2)); + step = integerCast(loc, rewriter, idxTy, + operands[coor.sliceOffset() + i + 2]); } auto idx = rewriter.create(loc, idxTy, index, lb); mlir::Value diff = Index: flang/test/Fir/convert-to-llvm.fir =================================================================== --- flang/test/Fir/convert-to-llvm.fir +++ flang/test/Fir/convert-to-llvm.fir @@ -2054,6 +2054,28 @@ // CHECK: %[[BITCAST:.*]] = llvm.bitcast %[[ARG0]] : !llvm.ptr> to !llvm.ptr // CHECK: %{{.*}} = llvm.getelementptr %[[BITCAST]][%[[OFFSET]]] : (!llvm.ptr, i64) -> !llvm.ptr +// Conversion with index type shape and slice + +func.func @ext_array_coor5(%arg0: !fir.ref>, %idx1 : index, %idx2 : index, %idx3 : index, %idx4 : index, %idx5 : index) { + %1 = fircg.ext_array_coor %arg0(%idx1)[%idx2, %idx3, %idx4]<%idx5> : (!fir.ref>, index, index, index, index, index) -> !fir.ref + return +} + +// CHECK-LABEL: llvm.func @ext_array_coor5( +// CHECK-SAME: %[[VAL_0:.*]]: !llvm.ptr, %[[VAL_1:.*]]: i64, %[[VAL_2:.*]]: i64, %[[VAL_3:.*]]: i64, %[[VAL_4:.*]]: i64, %[[VAL_5:.*]]: i64) { +// CHECK: %[[VAL_6:.*]] = llvm.mlir.constant(1 : i64) : i64 +// CHECK: %[[VAL_7:.*]] = llvm.mlir.constant(0 : i64) : i64 +// CHECK: %[[VAL_8:.*]] = llvm.sub %[[VAL_5]], %[[VAL_6]] : i64 +// CHECK: %[[VAL_9:.*]] = llvm.mul %[[VAL_8]], %[[VAL_4]] : i64 +// CHECK: %[[VAL_10:.*]] = llvm.sub %[[VAL_2]], %[[VAL_6]] : i64 +// CHECK: %[[VAL_11:.*]] = llvm.add %[[VAL_9]], %[[VAL_10]] : i64 +// CHECK: %[[VAL_12:.*]] = llvm.mul %[[VAL_11]], %[[VAL_6]] : i64 +// CHECK: %[[VAL_13:.*]] = llvm.add %[[VAL_12]], %[[VAL_7]] : i64 +// CHECK: %[[VAL_14:.*]] = llvm.mul %[[VAL_6]], %[[VAL_1]] : i64 +// CHECK: %[[VAL_15:.*]] = llvm.bitcast %[[VAL_0]] : !llvm.ptr to !llvm.ptr +// CHECK: %[[VAL_16:.*]] = llvm.getelementptr %[[VAL_15]][%[[VAL_13]]] : (!llvm.ptr, i64) -> !llvm.ptr +// CHECK: } + // ----- // Check `fircg.ext_rebox` conversion to LLVM IR dialect