46 lines · plain
1// RUN: mlir-opt %s --lower-sparse-ops-to-foreach="enable-runtime-library=false enable-convert=false" \2// RUN: --lower-sparse-foreach-to-scf --cse --canonicalize | FileCheck %s3 4#SparseMatrix = #sparse_tensor.encoding<{ map = (d0, d1) -> (d0 : compressed, d1 : compressed) }>5 6// CHECK: func.func @sparse_reshape(7// CHECK-SAME: %[[S:.*0]]:8// CHECK-DAG: %[[C25:.*]] = arith.constant 25 : index9// CHECK-DAG: %[[C10:.*]] = arith.constant 10 : index10// CHECK-DAG: %[[C0:.*]] = arith.constant 0 : index11// CHECK-DAG: %[[C1:.*]] = arith.constant 1 : index12// CHECK-DAG: %[[B:.*]] = bufferization.alloc_tensor()13// CHECK-DAG: %[[P0:.*]] = sparse_tensor.positions %[[S]] {level = 0 : index}14// CHECK-DAG: %[[I0:.*]] = sparse_tensor.coordinates %[[S]] {level = 0 : index}15// CHECK-DAG: %[[P1:.*]] = sparse_tensor.positions %[[S]] {level = 1 : index}16// CHECK-DAG: %[[I1:.*]] = sparse_tensor.coordinates %[[S]] {level = 1 : index}17// CHECK-DAG: %[[V:.*]] = sparse_tensor.values %[[S]]18// CHECK: %[[S0:.*]] = memref.load %[[P0]]{{\[}}%[[C0]]] : memref<?xindex>19// CHECK: %[[E0:.*]] = memref.load %[[P0]]{{\[}}%[[C1]]] : memref<?xindex>20// CHECK: %[[RET:.*]] = scf.for %[[I:.*]] = %[[S0]] to %[[E0]] step %[[C1]] iter_args(%[[A0:.*]] = %[[B]])21// CHECK: %[[SI0:.*]] = memref.load %[[I0]]{{\[}}%[[I]]] : memref<?xindex>22// CHECK-DAG: %[[S1:.*]] = memref.load %[[P1]]{{\[}}%[[I]]] : memref<?xindex>23// CHECK-DAG: %[[PE1:.*]] = arith.addi %[[I]], %[[C1]] : index24// CHECK: %[[E1:.*]] = memref.load %[[P1]]{{\[}}%[[PE1]]] : memref<?xindex>25// CHECK: %[[RET_1:.*]] = scf.for %[[J:.*]] = %[[S1]] to %[[E1]] step %[[C1]] iter_args(%[[A1:.*]] = %[[A0]])26// CHECK: %[[SI1:.*]] = memref.load %[[I1]]{{\[}}%[[J]]] : memref<?xindex>27// CHECK: %[[SV:.*]] = memref.load %[[V]]{{\[}}%[[J]]] : memref<?xf64>28// CHECK: %[[T:.*]] = arith.muli %[[SI0]], %[[C25]] : index29// CHECK: %[[DI:.*]] = arith.addi %[[T]], %[[SI1]] : index30// CHECK: %[[D:.*]] = arith.divui %[[DI]], %[[C10]] : index31// CHECK: %[[R:.*]] = arith.remui %[[DI]], %[[C10]] : index32// CHECK: %[[R1:.*]] = tensor.insert %[[SV]] into %[[A1]]{{\[}}%[[D]], %[[R]]]33// CHECK: scf.yield %[[R1]]34// CHECK: }35// CHECK: scf.yield %[[RET_1]]36// CHECK: }37// CHECK: %[[NT1:.*]] = sparse_tensor.load %[[RET]] hasInserts38// CHECK: return %[[NT1]] : tensor<10x10xf64, #sparse{{[0-9]*}}>39//40func.func @sparse_reshape(%arg0: tensor<4x25xf64, #SparseMatrix>) -> tensor<10x10xf64, #SparseMatrix> {41 %shape = arith.constant dense <[ 10, 10 ]> : tensor<2xi32>42 %0 = tensor.reshape %arg0(%shape) :43 (tensor<4x25xf64, #SparseMatrix>, tensor<2xi32>) -> tensor<10x10xf64, #SparseMatrix>44 return %0 : tensor<10x10xf64, #SparseMatrix>45}46