diff --git a/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp b/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp --- a/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp +++ b/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp @@ -1137,7 +1137,8 @@ // If there are no dimensions in the target to match, then append the // `currIndices` to the last element of the reassociationMap. if (targetDim == targetShape.size()) { - reassociationMap.back().append(currIndices.begin(), currIndices.end()); + if (!reassociationMap.empty()) + reassociationMap.back().append(currIndices.begin(), currIndices.end()); // Break out of the loops. We should be done here. break; }