Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2401,6 +2401,11 @@ computeCollapsedLayoutMap(MemRefType srcType,
auto trailingReassocs = ArrayRef<int64_t>(reassoc).drop_front();
auto stride = SaturatedInteger::wrap(resultStrides[resultStrideIndex--]);
for (int64_t idx : llvm::reverse(trailingReassocs)) {
// Dimensions of size 1 should be skipped, because their strides are
// meaningless and could have any arbitrary value.
if (srcShape[idx - 1] == 1)
continue;

stride = stride * SaturatedInteger::wrap(srcShape[idx]);

// Both source and result stride must have the same static value. In that
Expand All @@ -2415,11 +2420,6 @@ computeCollapsedLayoutMap(MemRefType srcType,
if (strict && (stride.saturated || srcStride.saturated))
return failure();

// Dimensions of size 1 should be skipped, because their strides are
// meaningless and could have any arbitrary value.
if (srcShape[idx - 1] == 1)
continue;

if (!stride.saturated && !srcStride.saturated && stride != srcStride)
return failure();
}
Expand Down
7 changes: 6 additions & 1 deletion mlir/test/Dialect/MemRef/ops.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,8 @@ func.func @expand_collapse_shape_dynamic(%arg0: memref<?x?x?xf32>,
%arg4: index,
%arg5: index,
%arg6: index,
%arg7: memref<4x?x4xf32>) {
%arg7: memref<4x?x4xf32>,
%arg8: memref<1x1x18x?xsi8, strided<[?, ?, ?, 1], offset: ?>>) {
// CHECK: memref.collapse_shape {{.*}} {{\[}}[0, 1], [2]]
// CHECK-SAME: memref<?x?x?xf32> into memref<?x?xf32>
%0 = memref.collapse_shape %arg0 [[0, 1], [2]] :
Expand Down Expand Up @@ -480,6 +481,10 @@ func.func @expand_collapse_shape_dynamic(%arg0: memref<?x?x?xf32>,
// CHECK: memref.expand_shape {{.*}} {{\[}}[0, 1], [2], [3, 4]]
%4 = memref.expand_shape %arg7 [[0, 1], [2], [3, 4]] output_shape [2, 2, %arg4, 2, 2]
: memref<4x?x4xf32> into memref<2x2x?x2x2xf32>

// CHECK: memref.collapse_shape {{.*}} {{\[}}[0, 1], [2], [3]]
// CHECK-SAME: memref<1x1x18x?xsi8, strided<[?, ?, ?, 1], offset: ?>> into memref<1x18x?xsi8, strided<[?, ?, 1], offset: ?>>
%5 = memref.collapse_shape %arg8 [[0, 1], [2], [3]] : memref<1x1x18x?xsi8, strided<[?, ?, ?, 1], offset: ?>> into memref<1x18x?xsi8, strided<[?, ?, 1], offset: ?>>
return
}

Expand Down