Skip to content

Tensor Dialect canonicalizer FoldTensorCastProducerOp can produce invalid IR #91265

Closed
@christopherbate

Description

@christopherbate

Reproducer:

// RUN: mlir-opt -canonicalize
func.func @materialize_in_destination_tensor_cast(%arg0: tensor<4xf32>, %arg1: index) -> tensor<?xf32> {
  %0 = bufferization.alloc_tensor(%arg1) : tensor<?xf32>
  %1 = tensor.cast %arg0 : tensor<4xf32> to tensor<?xf32>
  %2 = bufferization.materialize_in_destination %1 in %0 : (tensor<?xf32>, tensor<?xf32>) -> tensor<?xf32>
  return %2 : tensor<?xf32>
}

FoldTensorCastProducerOp defined in lib/Dialect/Tensor/IR/TensorOps.cpp assumes that any operand of an op that implements DestinationStyleOpInterface can absorb a tensor.cast operation that is erasing information from the type. However, that assumption is not encoded anywhere in the spec of DestinationStyleOpInterface. For example, bufferization.materialize_in_destination` requires that the shapes of its DPS input and DPS output operands match, and therefore the canonicalizer will produce IR that fails verification :

within split at test/Dialect/Bufferization/canonicalize.mlir:392 offset :6:8: error: 'bufferization.materialize_in_destination' op failed to verify that all of {source, dest} have same shape
  %2 = bufferization.materialize_in_destination %1 in %0 : (tensor<?xf32>, tensor<?xf32>) -> tensor<?xf32>
       ^
within split at test/Dialect/Bufferization/canonicalize.mlir:392 offset :6:8: note: see current operation: %1 = "bufferization.materialize_in_destination"(%arg0, %0) : (tensor<4xf32>, tensor<?xf32>) -> tensor<?xf32>

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions