[Mlir-commits] [mlir] [mlir][vector] Add verification for incorrect vector.extract (PR #115824)
Diego Caballero
llvmlistbot at llvm.org
Tue Nov 12 15:22:08 PST 2024
================
@@ -1349,13 +1349,33 @@ LogicalResult vector::ExtractOp::verify() {
"corresponding dynamic position) -- this can only happen due to an "
"incorrect fold/rewrite");
auto position = getMixedPosition();
- if (position.size() > static_cast<unsigned>(getSourceVectorType().getRank()))
+ VectorType srcVecType = getSourceVectorType();
+ int64_t srcRank = srcVecType.getRank();
+ if (position.size() > static_cast<unsigned>(srcRank))
return emitOpError(
"expected position attribute of rank no greater than vector rank");
+
+ VectorType dstVecType = dyn_cast<VectorType>(getResult().getType());
+ if (dstVecType) {
+ int64_t srcRankMinusIndices = srcRank - getNumIndices();
+ int64_t dstRank = dstVecType.getRank();
+ if ((srcRankMinusIndices == 0 && dstRank != 1) ||
+ (srcRankMinusIndices != 0 && srcRankMinusIndices != dstRank)) {
+ return emitOpError(
+ "expected source rank minus number of indices to match "
+ "destination vector rank");
+ }
+ } else {
+ // Scalar result.
+ if (srcRank != getNumIndices())
+ return emitOpError("expected source rank to match number of indices "
+ "for scalar result");
+ }
+
----------------
dcaballe wrote:
I actually was able to refactor the code for both ops. I also added a bunch of new tests. Some cases that currently pass as valid may need some refinement, but I don't want to make the verification too complex. We should iterate on this.
https://github.com/llvm/llvm-project/pull/115824
More information about the Mlir-commits
mailing list