<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/70030>70030</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[mlir][tensor] Purpose of the `dest` operand is unclear
</td>
</tr>
<tr>
<th>Labels</th>
<td>
mlir
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
rikhuijzer
</td>
</tr>
</table>
<pre>
Multiple tensor operations have an operand `dest`, but it's not so clear from the documentation of `tensor.pack` and `tensor.unpack` what the purpose of that operand is. The ops don't describe the operand apart from a description of its type. My assumption is that `dest` is mutated by the op because, for example, `tensor.insert` [states](https://mlir.llvm.org/docs/Dialects/TensorOps/#tensorinsert-tensorinsertop):
> The `tensor.insert` op inserts a scalar into a ranked tensor `dest` as specified by the operation’s indices.
That means that `dest` is mutated? This matches some tests that I see where the `dest` variable is returned.
If that's true, then there seems to be a bug with the canonicalizers. They don't assume the operands to be mutated. For example:
`mlir-opt -canonicalize` on the following code
```mlir
func.func @main(%dest : tensor<8x16x8x32xf32>) -> tensor<8x16x8x32xf32> {
%cst = arith.constant dense<1.000000e-01> : tensor<64x128xf32>
%0 = tensor.pack %cst outer_dims_perm = [1, 0] inner_dims_pos = [0, 1]
inner_tiles = [8, 32] into %dest : tensor<64x128xf32> -> tensor<8x16x8x32xf32>
return %dest : tensor<8x16x8x32xf32>
}
```
returns
```mlir
func.func @main(%arg0: tensor<8x16x8x32xf32>) -> tensor<8x16x8x32xf32> {
return %arg0 : tensor<8x16x8x32xf32>
}
```
and for
```mlir
func.func @main(%t: tensor<?xf32>, %idx: index, %f: f32) -> (tensor<?xf32>)
{
%0 = tensor.insert %f into %t[%idx] : tensor<?xf32>
return %t : tensor<?xf32>
}
```
it returns
```mlir
func.func @main(%arg0: tensor<?xf32>, %arg1: index, %arg2: f32) -> tensor<?xf32> {
return %arg0 : tensor<?xf32>
}
```
</pre>
<img width="1px" height="1px" alt="" src="http://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