Index: mlir/lib/Dialect/MemRef/Transforms/FoldSubViewOps.cpp =================================================================== --- mlir/lib/Dialect/MemRef/Transforms/FoldSubViewOps.cpp +++ mlir/lib/Dialect/MemRef/Transforms/FoldSubViewOps.cpp @@ -107,12 +107,11 @@ AffineMap currPermutationMap) { llvm::SmallDenseSet unusedDims = subViewOp.getDroppedDims(); SmallVector exprs; - unsigned resultIdx = 0; int64_t sourceRank = subViewOp.getSourceType().getRank(); for (auto dim : llvm::seq(0, sourceRank)) { if (unusedDims.count(dim)) continue; - exprs.push_back(getAffineDimExpr(resultIdx++, context)); + exprs.push_back(getAffineDimExpr(dim, context)); } auto resultDimToSourceDimMap = AffineMap::get(sourceRank, 0, exprs, context); return currPermutationMap.compose(resultDimToSourceDimMap); Index: mlir/test/Dialect/MemRef/fold-subview-ops.mlir =================================================================== --- mlir/test/Dialect/MemRef/fold-subview-ops.mlir +++ mlir/test/Dialect/MemRef/fold-subview-ops.mlir @@ -177,7 +177,6 @@ } // CHECK-DAG: #[[MAP0:.+]] = affine_map<(d0, d1, d2)[s0, s1, s2, s3] -> (d0 * s1 + s0 + d1 * s2 + d2 * s3)> // CHECK-DAG: #[[MAP1:.+]] = affine_map<(d0)[s0] -> (d0 + s0)> -// CHECK-DAG: #[[MAP2:.+]] = affine_map<(d0, d1, d2) -> (d1)> // CHECK: func @fold_vector_transfer_read_with_rank_reduced_subview // CHECK-SAME: %[[ARG0:[a-zA-Z0-9]+]]: memref // CHECK-SAME: %[[ARG1:[a-zA-Z0-9]+]]: index @@ -189,8 +188,7 @@ // CHECK-DAG: %[[C0:.+]] = constant 0 : index // CHECK-DAG: %[[IDX0:.+]] = affine.apply #[[MAP1]](%[[ARG5]])[%[[ARG1]]] // CHECK-DAG: %[[IDX1:.+]] = affine.apply #[[MAP1]](%[[ARG6]])[%[[ARG2]]] -// CHECK: vector.transfer_read %[[ARG0]][%[[C0]], %[[IDX0]], %[[IDX1]]] -// CHECK-SAME: permutation_map = #[[MAP2]] +// CHECK: vector.transfer_read %[[ARG0]][%[[C0]], %[[IDX0]], %[[IDX1]]], %{{.*}} : memref (d0 * s1 + s0 + d1 * s2 + d2 * s3)> // CHECK-DAG: #[[MAP1:.+]] = affine_map<(d0)[s0] -> (d0 + s0)> -// CHECK-DAG: #[[MAP2:.+]] = affine_map<(d0, d1, d2) -> (d1)> // CHECK: func @fold_vector_transfer_write_with_rank_reduced_subview // CHECK-SAME: %[[ARG0:[a-zA-Z0-9]+]]: memref // CHECK-SAME: %[[ARG1:[a-zA-Z0-9]+]]: vector<4xf32> @@ -221,5 +218,4 @@ // CHECK-DAG: %[[C0:.+]] = constant 0 : index // CHECK-DAG: %[[IDX0:.+]] = affine.apply #[[MAP1]](%[[ARG6]])[%[[ARG2]]] // CHECK-DAG: %[[IDX1:.+]] = affine.apply #[[MAP1]](%[[ARG7]])[%[[ARG3]]] -// CHECK-DAG: vector.transfer_write %[[ARG1]], %[[ARG0]][%[[C0]], %[[IDX0]], %[[IDX1]]] -// CHECK-SAME: permutation_map = #[[MAP2]] +// CHECK-DAG: vector.transfer_write %[[ARG1]], %[[ARG0]][%[[C0]], %[[IDX0]], %[[IDX1]]] {in_bounds = [true]} : vector<4xf32>, memref