1// RUN: mlir-opt %s  --canonicalize --cse | FileCheck %s
2
3#SparseVector = #sparse_tensor.encoding<{dimLevelType = ["compressed"]}>
4
5// CHECK-LABEL: func @sparse_nop_convert(
6//  CHECK-SAME: %[[A:.*]]: tensor<64xf32, #sparse_tensor.encoding<{{{.*}}}>>)
7//   CHECK-NOT: sparse_tensor.convert
8//       CHECK: return %[[A]] : tensor<64xf32, #sparse_tensor.encoding<{{{.*}}}>>
9func.func @sparse_nop_convert(%arg0: tensor<64xf32, #SparseVector>) -> tensor<64xf32, #SparseVector> {
10  %0 = sparse_tensor.convert %arg0 : tensor<64xf32, #SparseVector> to tensor<64xf32, #SparseVector>
11  return %0 : tensor<64xf32, #SparseVector>
12}
13
14// CHECK-LABEL: func @sparse_dce_convert(
15//  CHECK-SAME: %[[A:.*]]: tensor<64xf32>)
16//   CHECK-NOT: sparse_tensor.convert
17//       CHECK: return
18func.func @sparse_dce_convert(%arg0: tensor<64xf32>) {
19  %0 = sparse_tensor.convert %arg0 : tensor<64xf32> to tensor<64xf32, #SparseVector>
20  return
21}
22
23// CHECK-LABEL: func @sparse_dce_getters(
24//  CHECK-SAME: %[[A:.*]]: tensor<64xf32, #sparse_tensor.encoding<{{{.*}}}>>)
25//   CHECK-NOT: sparse_tensor.pointers
26//   CHECK-NOT: sparse_tensor.indices
27//   CHECK-NOT: sparse_tensor.values
28//       CHECK: return
29func.func @sparse_dce_getters(%arg0: tensor<64xf32, #SparseVector>) {
30  %c = arith.constant 0 : index
31  %0 = sparse_tensor.pointers %arg0, %c : tensor<64xf32, #SparseVector> to memref<?xindex>
32  %1 = sparse_tensor.indices %arg0, %c : tensor<64xf32, #SparseVector> to memref<?xindex>
33  %2 = sparse_tensor.values %arg0 : tensor<64xf32, #SparseVector> to memref<?xf32>
34  return
35}
36