[Mlir-commits] [mlir] [mlir][tosa] Fix crash in TosaInferShapes when while_loop carries sparse tensors (PR #183943)

Luke Hutton llvmlistbot at llvm.org
Mon Mar 2 03:33:25 PST 2026


https://github.com/lhutton1 commented:

Thanks for the fix @joker-eph. The resulting IR looks a little strange to me:
```
    %2 = tosa.while_loop (%arg0 = %1) : (tensor<1xi32, #sparse>) -> tensor<1xi32> {
      %cast = tensor.cast %arg0 : tensor<1xi32> to tensor<1xi32, #sparse>
      %4 = sparse_tensor.convert %cast : tensor<1xi32, #sparse> to tensor<1xi32>
```
the cast that's inserted is casting from `tensor<1xi32>` to `tensor<1xi32, #sparse>` yet `%arg0` is said to be of type `tensor<1xi32, #sparse>`. I'm surprised this isn't considered invalid IR, but maybe I'm missing something?

Overall, I think the problem here is that creation of [`ValueKnowledge`](https://github.com/llvm/llvm-project/blob/5550c821897ab77e664977121a0e90ad5be1ff59/mlir/include/mlir/Dialect/Tosa/Utils/ShapeUtils.h#L33) drops the tensor encoding. If this is maintained, we shouldn't require a cast to be inserted.

https://github.com/llvm/llvm-project/pull/183943


More information about the Mlir-commits mailing list