[MemRef] Remove memref.dim OffsetSizeAndStrideOpInterface folding (#169327)

OffsetSizeAndStrideOpInterface does not specify whether it's operating
on the input or output shape and in fact different ops implement this in
different ways, which is also why SubviewOp is special cased here.

This "marked as dynamic but not really dynamic" folding is better
handled by shape inference, so just remove the bad fold.
This commit is contained in:
Benjamin Kramer 2025-11-24 23:03:24 +01:00 committed by GitHub
parent ba98668dca
commit 4650f8521d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 0 additions and 20 deletions

View File

@ -1074,13 +1074,6 @@ OpFoldResult DimOp::fold(FoldAdaptor adaptor) {
return subview.getDynamicSize(sourceIndex);
}
if (auto sizeInterface =
dyn_cast_or_null<OffsetSizeAndStrideOpInterface>(definingOp)) {
assert(sizeInterface.isDynamicSize(unsignedIndex) &&
"Expected dynamic subview size");
return sizeInterface.getDynamicSize(unsignedIndex);
}
// dim(memrefcast) -> dim
if (succeeded(foldMemRefCast(*this)))
return getResult();

View File

@ -208,19 +208,6 @@ func.func @subview_negative_stride2(%arg0 : memref<7xf32>) -> memref<?xf32, stri
// -----
// CHECK-LABEL: func @dim_of_sized_view
// CHECK-SAME: %{{[a-z0-9A-Z_]+}}: memref<?xi8>
// CHECK-SAME: %[[SIZE:.[a-z0-9A-Z_]+]]: index
// CHECK: return %[[SIZE]] : index
func.func @dim_of_sized_view(%arg : memref<?xi8>, %size: index) -> index {
%c0 = arith.constant 0 : index
%0 = memref.reinterpret_cast %arg to offset: [0], sizes: [%size], strides: [1] : memref<?xi8> to memref<?xi8>
%1 = memref.dim %0, %c0 : memref<?xi8>
return %1 : index
}
// -----
// CHECK-LABEL: func @no_fold_subview_negative_size
// CHECK: %[[SUBVIEW:.+]] = memref.subview
// CHECK: return %[[SUBVIEW]]