[mlir][tensor/memref] Disallow Collapse/ExpandShapeOps that do not reduce/increase the rank

CollapseShapeOp/ExpandShapeOp that do not change the rank (or increase/reduce it) are invalid.

Differential Revision: https://reviews.llvm.org/D138498
This commit is contained in:
Matthias Springer
2022-11-23 09:19:00 +01:00
parent 7a69a9d7ae
commit b9745ad812
4 changed files with 57 additions and 9 deletions

View File

@@ -1398,10 +1398,22 @@ static LogicalResult verifyTensorReshapeOp(TensorReshapeOp op,
}
LogicalResult ExpandShapeOp::verify() {
auto srcType = getSrcType();
auto resultType = getResultType();
if (srcType.getRank() >= resultType.getRank())
return emitOpError("expected rank expansion, but found source rank ")
<< srcType.getRank() << " >= result rank " << resultType.getRank();
return verifyTensorReshapeOp(*this, getResultType(), getSrcType());
}
LogicalResult CollapseShapeOp::verify() {
auto srcType = getSrcType();
auto resultType = getResultType();
if (srcType.getRank() <= resultType.getRank())
return emitOpError("expected rank reduction, but found source rank ")
<< srcType.getRank() << " <= result rank " << resultType.getRank();
return verifyTensorReshapeOp(*this, getSrcType(), getResultType());
}