Skip to content

Commit 858c6a7

Browse files
committed
[mlir][vector] Restrict vector.shape_cast (scalable vectors)
Updates the verifier for `vector.shape_cast` so that the following incorrect cases are immediately rejected: ```mlir vector.shape_cast %vec : vector<1x1x[4]xindex> to vector<4xindex> ``` Seperately, here's a fix for the Linalg vectorizer to prevent the vectorizer from generating such shape casts (*): * llvm#100325 (*) Note, that's just one specific case that I've identified so far.
1 parent a213edd commit 858c6a7

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

mlir/lib/Dialect/Vector/IR/VectorOps.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5238,6 +5238,11 @@ static LogicalResult verifyVectorShapeCast(Operation *op,
52385238
if (!isValidShapeCast(resultShape, sourceShape))
52395239
return op->emitOpError("invalid shape cast");
52405240
}
5241+
5242+
// Check that (non-)scalability is preserved
5243+
if (sourceVectorType.isScalable() != resultVectorType.isScalable())
5244+
return op->emitOpError("non-matching scalability flags");
5245+
52415246
return success();
52425247
}
52435248

mlir/test/Dialect/Vector/invalid.mlir

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,6 +1182,13 @@ func.func @shape_cast_invalid_rank_expansion(%arg0 : vector<15x2xf32>) {
11821182

11831183
// -----
11841184

1185+
func.func @shape_cast_scalability_flag_is_dropped(%arg0 : vector<15x[2]xf32>) {
1186+
// expected-error@+1 {{non-matching scalability flags}}
1187+
%0 = vector.shape_cast %arg0 : vector<15x[2]xf32> to vector<30xf32>
1188+
}
1189+
1190+
// -----
1191+
11851192
func.func @bitcast_not_vector(%arg0 : vector<5x1x3x2xf32>) {
11861193
// expected-error@+1 {{'vector.bitcast' invalid kind of type specified}}
11871194
%0 = vector.bitcast %arg0 : vector<5x1x3x2xf32> to f32

0 commit comments

Comments
 (0)