Skip to content

Commit d4e1617

Browse files
committed
[mlir][sparse] add dce test for all sparse tensor ops
Reviewed By: ThomasRaoux Differential Revision: https://reviews.llvm.org/D109992
1 parent d01e0c8 commit d4e1617

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

mlir/test/Dialect/SparseTensor/fold.mlir

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// RUN: mlir-opt %s --canonicalize --cse | FileCheck %s
22

3+
#DenseVector = #sparse_tensor.encoding<{dimLevelType = ["dense"]}>
34
#SparseVector = #sparse_tensor.encoding<{dimLevelType = ["compressed"]}>
45

56
// CHECK-LABEL: func @sparse_nop_convert(
@@ -18,3 +19,28 @@ func @sparse_dce_convert(%arg0: tensor<64xf32>) {
1819
%0 = sparse_tensor.convert %arg0 : tensor<64xf32> to tensor<64xf32, #SparseVector>
1920
return
2021
}
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
29+
func @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
42+
func @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+
}

0 commit comments

Comments
 (0)