diff --git a/mlir/lib/Dialect/Utils/ReshapeOpsUtils.cpp b/mlir/lib/Dialect/Utils/ReshapeOpsUtils.cpp --- a/mlir/lib/Dialect/Utils/ReshapeOpsUtils.cpp +++ b/mlir/lib/Dialect/Utils/ReshapeOpsUtils.cpp @@ -47,9 +47,9 @@ break; int64_t currTargetShape = targetShape[targetDim]; - while (sourceShape[sourceDim] != ShapedType::kDynamic && - prodOfCollapsedDims * sourceShape[sourceDim] < currTargetShape && - sourceDim < sourceShape.size()) { + while (sourceDim < sourceShape.size() && + sourceShape[sourceDim] != ShapedType::kDynamic && + prodOfCollapsedDims * sourceShape[sourceDim] < currTargetShape) { prodOfCollapsedDims *= sourceShape[sourceDim]; currIndices.push_back(sourceDim++); }