llvm-project
a7bc628e - [mlir][tosa] Harden folds/canonicalizations for unranked and dynamic shapes (#188188)

Commit
2 days ago
[mlir][tosa] Harden folds/canonicalizations for unranked and dynamic shapes (#188188) This MR fixes #188187 and #187974. Tighten TOSA constant folding and identity-style folds so they do not produce invalid or type-incorrect results when the op’s result type is unranked, rank-dynamic, or otherwise not a static `RankedTensorType`. Several paths previously assumed ranked/static shapes or folded through to the operand without checking that the result type matched the value being returned. `DenseElementsAttr::get`, `SplatElementsAttr::get` and similar builders need a static shape; folding with `tensor<*xT>` or dynamic dims must not fabricate dense attributes with the wrong shape. Returning the operand from a “no-op” fold is only valid when `operand.getType() == op.getType()`; otherwise the folder would change the IR’s type semantics (e.g. ranked → unranked). Which in the bigger pipeline supposed to be handled by `-tosa-infer-shapes` Assisted-by: CLion code completion, GPT 5.3 - Codex --------- Co-authored-by: Sayan Saha <sayans@mathworks.com>
Author
Parents
Loading