Files
llvm-project/mlir/test/Dialect/SparseTensor/codegen_invalid.mlir
Arjun Bhamra c06ea02bfd [MLIR] Graceful handling of uninitialized sparse tensor encodings with sparse-tensor-codegen (#181145)
This PR handles the case where users call the `--sparse-tensor-codegen`
pass without sufficiently lowering dense tensors to sparse ones (with
passes like `--lower-sparse-ops-to-foreach` and
`--lower-sparse-foreach-to-scf` among others). This results in dense
tensors having a null `SparseTensorEncodingAttr`, which was originally
assumed to be true in the SparseTensor's `ConvertOp` lowering, but is
now checked against.

This PR closes #177779.
2026-02-20 18:32:37 +00:00

27 lines
883 B
MLIR

// RUN: mlir-opt %s -sparse-tensor-codegen -verify-diagnostics
// NOTE: This test has valid IR, however we are testing whether
// the legalization failure occurs when important passes are
// missing. Notably, using --lower-sparse-ops-to-foreach
// followed by --lower-sparse-foreach-to-scf prior to
// sparse codegen will convert the dense tensor correctly.
#SparseVector = #sparse_tensor.encoding<{
map = (d0) -> (d0 : compressed)
}>
module {
func.func @main() -> tensor<8xf32, #SparseVector> {
%dense = arith.constant dense<[1.0, 0.0, 0.0, 2.0, 0.0, 3.0, 0.0, 0.0]>
: tensor<8xf32>
// expected-error@+1 {{failed to legalize operation 'sparse_tensor.convert' that was explicitly marked illegal}}
%sparse = sparse_tensor.convert %dense
: tensor<8xf32> to tensor<8xf32, #SparseVector>
return %sparse : tensor<8xf32, #SparseVector>
}
}
// -----