Skip to content

Commit ddb1190

Browse files
d0kaadeshps-mcw
authored andcommitted
[MemRef] Remove memref.dim OffsetSizeAndStrideOpInterface folding (llvm#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.
1 parent 362885c commit ddb1190

File tree

2 files changed

+0
-20
lines changed

2 files changed

+0
-20
lines changed

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,13 +1074,6 @@ OpFoldResult DimOp::fold(FoldAdaptor adaptor) {
10741074
return subview.getDynamicSize(sourceIndex);
10751075
}
10761076

1077-
if (auto sizeInterface =
1078-
dyn_cast_or_null<OffsetSizeAndStrideOpInterface>(definingOp)) {
1079-
assert(sizeInterface.isDynamicSize(unsignedIndex) &&
1080-
"Expected dynamic subview size");
1081-
return sizeInterface.getDynamicSize(unsignedIndex);
1082-
}
1083-
10841077
// dim(memrefcast) -> dim
10851078
if (succeeded(foldMemRefCast(*this)))
10861079
return getResult();

mlir/test/Dialect/MemRef/canonicalize.mlir

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -208,19 +208,6 @@ func.func @subview_negative_stride2(%arg0 : memref<7xf32>) -> memref<?xf32, stri
208208

209209
// -----
210210

211-
// CHECK-LABEL: func @dim_of_sized_view
212-
// CHECK-SAME: %{{[a-z0-9A-Z_]+}}: memref<?xi8>
213-
// CHECK-SAME: %[[SIZE:.[a-z0-9A-Z_]+]]: index
214-
// CHECK: return %[[SIZE]] : index
215-
func.func @dim_of_sized_view(%arg : memref<?xi8>, %size: index) -> index {
216-
%c0 = arith.constant 0 : index
217-
%0 = memref.reinterpret_cast %arg to offset: [0], sizes: [%size], strides: [1] : memref<?xi8> to memref<?xi8>
218-
%1 = memref.dim %0, %c0 : memref<?xi8>
219-
return %1 : index
220-
}
221-
222-
// -----
223-
224211
// CHECK-LABEL: func @no_fold_subview_negative_size
225212
// CHECK: %[[SUBVIEW:.+]] = memref.subview
226213
// CHECK: return %[[SUBVIEW]]

0 commit comments

Comments
 (0)