Skip to content

[mlir] Fix bufferization.alloc_tensor canonicalization crash #70891

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 5 additions & 1 deletion mlir/lib/Dialect/Bufferization/IR/BufferizationOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,11 @@ struct ReplaceStaticShapeDims : OpRewritePattern<AllocTensorOp> {
Value value = op.getDynamicSizes()[dynValCounter++];
APInt intVal;
if (matchPattern(value, m_ConstantInt(&intVal))) {
newShape[i] = intVal.getSExtValue();
int64_t dim = intVal.getSExtValue();
if (dim >= 0)
newShape[i] = intVal.getSExtValue();
else
newDynamicSizes.push_back(value);
} else {
newDynamicSizes.push_back(value);
}
Expand Down
13 changes: 13 additions & 0 deletions mlir/test/Dialect/Bufferization/canonicalize.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -351,3 +351,16 @@ func.func @dealloc_base_memref_extract_of_alloc(%arg0: memref<2xi32>) {
// CHECK-SAME:([[ARG0:%.+]]: memref<2xi32>)
// CHECK-NOT: memref.alloc(
// CHECK: bufferization.dealloc ([[ARG0]] : memref<2xi32>) if (%true

// -----

// CHECK-LABEL: func @negative_input
func.func @negative_input() -> tensor<?x?x?xf16> {
%idx27 = index.constant 27
%idx-3 = index.constant -3 // negative integer?
%c10 = arith.constant 10 : index
// CHECK: bufferization.alloc_tensor
// CHECK-SAME: tensor<10x?x27xf16>
%11 = bufferization.alloc_tensor(%c10, %idx-3, %idx27) : tensor<?x?x?xf16>
return %11 : tensor<?x?x?xf16>
}