Skip to content

Commit 32adf97

Browse files
committed
Allow zero sizes
1 parent 8f90ae9 commit 32adf97

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2849,8 +2849,8 @@ LogicalResult SubViewOp::verify() {
28492849
<< offset;
28502850
}
28512851
for (int64_t size : getStaticSizes()) {
2852-
if (size < 1 && !ShapedType::isDynamic(size))
2853-
return emitError("expected subview sizes to be positive, but got ")
2852+
if (size < 0 && !ShapedType::isDynamic(size))
2853+
return emitError("expected subview sizes to be non-negative, but got ")
28542854
<< size;
28552855
}
28562856

@@ -3103,6 +3103,7 @@ struct SubViewReturnTypeCanonicalizer {
31033103
MemRefType operator()(SubViewOp op, ArrayRef<OpFoldResult> mixedOffsets,
31043104
ArrayRef<OpFoldResult> mixedSizes,
31053105
ArrayRef<OpFoldResult> mixedStrides) {
3106+
31063107
// Infer a memref type without taking into account any rank reductions.
31073108
MemRefType nonReducedType = cast<MemRefType>(SubViewOp::inferResultType(
31083109
op.getSourceType(), mixedOffsets, mixedSizes, mixedStrides));

mlir/test/Dialect/MemRef/invalid.mlir

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -620,8 +620,8 @@ func.func @invalid_subview(%input: memref<4x1024xf32>) -> memref<2x256xf32, stri
620620
// -----
621621

622622
func.func @invalid_subview(%input: memref<4x1024xf32>) -> memref<2x256xf32, strided<[1024, 1], offset: 2304>> {
623-
// expected-error@+1 {{expected subview sizes to be positive, but got 0}}
624-
%0 = memref.subview %input[2, 256] [0, 256] [1, 1] : memref<4x1024xf32> to memref<2x256xf32, strided<[1024, 1], offset: 2304>>
623+
// expected-error@+1 {{expected subview sizes to be non-negative, but got -1}}
624+
%0 = memref.subview %input[2, 256] [-1, 256] [1, 1] : memref<4x1024xf32> to memref<2x256xf32, strided<[1024, 1], offset: 2304>>
625625
return %0 : memref<2x256xf32, strided<[1024, 1], offset: 2304>>
626626
}
627627

0 commit comments

Comments
 (0)