Skip to content

Commit ef5a710

Browse files
authored
[mlir][vector] Skip 0D vectors in vector linearization. (llvm#87577)
1 parent 622851a commit ef5a710

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

mlir/lib/Dialect/Vector/Transforms/VectorLinearize.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ static bool isLessThanTargetBitWidth(Operation *op, unsigned targetBitWidth) {
2626
// Reject index since getElementTypeBitWidth will abort for Index types.
2727
if (!vecType || vecType.getElementType().isIndex())
2828
return false;
29+
// There are no dimension to fold if it is a 0-D vector.
30+
if (vecType.getRank() == 0)
31+
return false;
2932
unsigned trailingVecDimBitWidth =
3033
vecType.getShape().back() * vecType.getElementTypeBitWidth();
3134
if (trailingVecDimBitWidth >= targetBitWidth)

mlir/test/Dialect/Vector/linearize.mlir

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,16 @@ func.func @test_scalable_no_linearize(%arg0: vector<[2]x[2]xf32>) -> vector<[2]x
146146

147147
// -----
148148

149+
// ALL-LABEL: func.func @test_0d_vector
150+
func.func @test_0d_vector() -> vector<f32> {
151+
// ALL: %[[CST:.+]] = arith.constant dense<0.000000e+00> : vector<f32>
152+
%0 = arith.constant dense<0.0> : vector<f32>
153+
// ALL: return %[[CST]]
154+
return %0 : vector<f32>
155+
}
156+
157+
// -----
158+
149159
func.func @test_scalable_no_linearize(%arg0: vector<2x[2]xf32>) -> vector<2x[2]xf32> {
150160
// expected-error@+1 {{failed to legalize operation 'arith.constant' that was explicitly marked illegal}}
151161
%0 = arith.constant dense<[[1., 1.], [3., 3.]]> : vector<2x[2]xf32>

0 commit comments

Comments
 (0)