1// RUN: mlir-opt %s --canonicalize --cse | FileCheck %s 2 3#DenseVector = #sparse_tensor.encoding<{dimLevelType = ["dense"]}> 4#SparseVector = #sparse_tensor.encoding<{dimLevelType = ["compressed"]}> 5 6// CHECK-LABEL: func @sparse_nop_convert( 7// CHECK-SAME: %[[A:.*]]: tensor<64xf32, #{{.*}}>) 8// CHECK: return %[[A]] : tensor<64xf32, #{{.*}}> 9func @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 @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 @sparse_dce_getters(%arg0: tensor<64xf32, #SparseVector>) { 30 %c = 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 37// CHECK-LABEL: func @sparse_dce_reconstruct( 38// CHECK-SAME: %[[A:.*]]: tensor<64xf32, #sparse_tensor.encoding<{{{.*}}}>>) 39// CHECK-NOT: sparse_tensor.values 40// CHECK-NOT: sparse_tensor.tensor 41// CHECK: return 42func @sparse_dce_reconstruct(%arg0: tensor<64xf32, #DenseVector>) { 43 %0 = sparse_tensor.values %arg0 : tensor<64xf32, #DenseVector> to memref<?xf32> 44 %1 = sparse_tensor.tensor %0 : memref<?xf32> to tensor<64xf32, #DenseVector> 45 return 46} 47