[Mlir-commits] [mlir] [mlir][sparse] Fix crash in sparse_tensor.new with unsupported element type (PR #183898)

Hocky Yudhiono llvmlistbot at llvm.org
Mon Jul 13 03:09:43 PDT 2026


hockyy wrote:

IMO, this doesn't look like a very robust fix.

```
bool mlir::sparse_tensor::isValidPrimaryType(Type elemTp) {
  if (elemTp.isF64() || elemTp.isF32() || elemTp.isF16() || elemTp.isBF16() ||
      elemTp.isInteger(64) || elemTp.isInteger(32) || elemTp.isInteger(16) ||
      elemTp.isInteger(8))
    return true;
  if (auto complexTp = dyn_cast<ComplexType>(elemTp)) {
    Type elt = complexTp.getElementType();
    return elt.isF64() || elt.isF32();
  }
  return false;
}
```

https://github.com/llvm/llvm-project/pull/208913#discussion_r3569696086 <- There are errors in other patterns that needs this check in prior

I'm thinking of changing this function's signature `PrimaryType mlir::sparse_tensor::primaryTypeEncoding(Type elemTp)` instead to `failureOr<PrimaryType>`

so we don't need to update both the same time and adding validPrimaryType check everywhere

@joker-eph wdyt?

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


More information about the Mlir-commits mailing list