106a65ce5SPeiming Liu// RUN: mlir-opt %s --sparse-reinterpret-map -sparsification | FileCheck %s 236b66ab9SAart Bik 336b66ab9SAart Bik#CSR = #sparse_tensor.encoding<{ 4e2e429d9SYinying Li map = (d0, d1) -> (d0 : dense, d1 : compressed), 536b66ab9SAart Bik}> 636b66ab9SAart Bik 736b66ab9SAart Bik#DCSR = #sparse_tensor.encoding<{ 82a07f0fdSYinying Li map = (d0, d1) -> (d0 : compressed, d1 : compressed) 936b66ab9SAart Bik}> 1036b66ab9SAart Bik 117d4da4e1SAart Bik#SparseTensor = #sparse_tensor.encoding<{ 123dc62112SYinying Li map = (d0, d1, d2) -> (d0 : compressed, d1 : compressed, d2 : compressed) 137d4da4e1SAart Bik}> 147d4da4e1SAart Bik 151ce77b56SAart Bik#trait_scale_inpl = { 1636b66ab9SAart Bik indexing_maps = [ 1736b66ab9SAart Bik affine_map<(i,j) -> (i,j)> // X (out) 1836b66ab9SAart Bik ], 1936b66ab9SAart Bik iterator_types = ["parallel", "parallel"], 200e85232fSAart Bik doc = "X(i,j) *= 2 or X(i,j) += X(i,j)" 2136b66ab9SAart Bik} 2236b66ab9SAart Bik 23a3610359SAart Bik// CHECK-LABEL: func.func @sparse_simply_dynamic1( 24c5a67e16SYinying Li// CHECK-SAME: %[[VAL_0:.*]]: tensor<32x16xf32, #sparse{{[0-9]*}}>) -> tensor<32x16xf32, #sparse{{[0-9]*}}> { 255661647eSAart Bik// CHECK-DAG: %[[VAL_1:.*]] = arith.constant 0 : index 265661647eSAart Bik// CHECK-DAG: %[[VAL_2:.*]] = arith.constant 1 : index 275661647eSAart Bik// CHECK-DAG: %[[VAL_3:.*]] = arith.constant 2.000000e+00 : f32 28c5a67e16SYinying Li// CHECK-DAG: %[[VAL_4:.*]] = sparse_tensor.positions %[[VAL_0]] {level = 0 : index} : tensor<32x16xf32, #sparse{{[0-9]*}}> to memref<?xindex> 29c5a67e16SYinying Li// CHECK-DAG: %[[VAL_5:.*]] = sparse_tensor.positions %[[VAL_0]] {level = 1 : index} : tensor<32x16xf32, #sparse{{[0-9]*}}> to memref<?xindex> 30c5a67e16SYinying Li// CHECK-DAG: %[[VAL_6:.*]] = sparse_tensor.values %[[VAL_0]] : tensor<32x16xf32, #sparse{{[0-9]*}}> to memref<?xf32> 315661647eSAart Bik// CHECK: %[[VAL_7:.*]] = memref.load %[[VAL_4]]{{\[}}%[[VAL_1]]] : memref<?xindex> 325661647eSAart Bik// CHECK: %[[VAL_8:.*]] = memref.load %[[VAL_4]]{{\[}}%[[VAL_2]]] : memref<?xindex> 335661647eSAart Bik// CHECK: scf.for %[[VAL_9:.*]] = %[[VAL_7]] to %[[VAL_8]] step %[[VAL_2]] { 345661647eSAart Bik// CHECK: %[[VAL_10:.*]] = memref.load %[[VAL_5]]{{\[}}%[[VAL_9]]] : memref<?xindex> 355661647eSAart Bik// CHECK: %[[VAL_11:.*]] = arith.addi %[[VAL_9]], %[[VAL_2]] : index 365661647eSAart Bik// CHECK: %[[VAL_12:.*]] = memref.load %[[VAL_5]]{{\[}}%[[VAL_11]]] : memref<?xindex> 375661647eSAart Bik// CHECK: scf.for %[[VAL_13:.*]] = %[[VAL_10]] to %[[VAL_12]] step %[[VAL_2]] { 385661647eSAart Bik// CHECK: %[[VAL_14:.*]] = memref.load %[[VAL_6]]{{\[}}%[[VAL_13]]] : memref<?xf32> 395661647eSAart Bik// CHECK: %[[VAL_15:.*]] = arith.mulf %[[VAL_14]], %[[VAL_3]] : f32 405661647eSAart Bik// CHECK: memref.store %[[VAL_15]], %[[VAL_6]]{{\[}}%[[VAL_13]]] : memref<?xf32> 4136b66ab9SAart Bik// CHECK: } 4236b66ab9SAart Bik// CHECK: } 43c5a67e16SYinying Li// CHECK: %[[VAL_16:.*]] = sparse_tensor.load %[[VAL_0]] : tensor<32x16xf32, #sparse{{[0-9]*}}> 44c5a67e16SYinying Li// CHECK: return %[[VAL_16]] : tensor<32x16xf32, #sparse{{[0-9]*}}> 4536b66ab9SAart Bik// CHECK: } 46c66303c2SMatthias Springerfunc.func @sparse_simply_dynamic1(%argx: tensor<32x16xf32, #DCSR>) -> tensor<32x16xf32, #DCSR> { 47a54f4eaeSMogball %c = arith.constant 2.0 : f32 481ce77b56SAart Bik %0 = linalg.generic #trait_scale_inpl 4936b66ab9SAart Bik outs(%argx: tensor<32x16xf32, #DCSR>) { 5036b66ab9SAart Bik ^bb(%x: f32): 51a54f4eaeSMogball %1 = arith.mulf %x, %c : f32 5236b66ab9SAart Bik linalg.yield %1 : f32 5336b66ab9SAart Bik } -> tensor<32x16xf32, #DCSR> 5436b66ab9SAart Bik return %0 : tensor<32x16xf32, #DCSR> 5536b66ab9SAart Bik} 5636b66ab9SAart Bik 57a3610359SAart Bik// CHECK-LABEL: func.func @sparse_simply_dynamic2( 58c5a67e16SYinying Li// CHECK-SAME: %[[VAL_0:.*]]: tensor<32x16xf32, #sparse{{[0-9]*}}>) -> tensor<32x16xf32, #sparse{{[0-9]*}}> { 590e85232fSAart Bik// CHECK-DAG: %[[VAL_1:.*]] = arith.constant 0 : index 600e85232fSAart Bik// CHECK-DAG: %[[VAL_2:.*]] = arith.constant 1 : index 61c5a67e16SYinying Li// CHECK-DAG: %[[VAL_3:.*]] = sparse_tensor.positions %[[VAL_0]] {level = 0 : index} : tensor<32x16xf32, #sparse{{[0-9]*}}> to memref<?xindex> 62c5a67e16SYinying Li// CHECK-DAG: %[[VAL_4:.*]] = sparse_tensor.positions %[[VAL_0]] {level = 1 : index} : tensor<32x16xf32, #sparse{{[0-9]*}}> to memref<?xindex> 63c5a67e16SYinying Li// CHECK-DAG: %[[VAL_5:.*]] = sparse_tensor.values %[[VAL_0]] : tensor<32x16xf32, #sparse{{[0-9]*}}> to memref<?xf32> 640e85232fSAart Bik// CHECK: %[[VAL_6:.*]] = memref.load %[[VAL_3]]{{\[}}%[[VAL_1]]] : memref<?xindex> 650e85232fSAart Bik// CHECK: %[[VAL_7:.*]] = memref.load %[[VAL_3]]{{\[}}%[[VAL_2]]] : memref<?xindex> 660e85232fSAart Bik// CHECK: scf.for %[[VAL_8:.*]] = %[[VAL_6]] to %[[VAL_7]] step %[[VAL_2]] { 670e85232fSAart Bik// CHECK: %[[VAL_9:.*]] = memref.load %[[VAL_4]]{{\[}}%[[VAL_8]]] : memref<?xindex> 680e85232fSAart Bik// CHECK: %[[VAL_10:.*]] = arith.addi %[[VAL_8]], %[[VAL_2]] : index 690e85232fSAart Bik// CHECK: %[[VAL_11:.*]] = memref.load %[[VAL_4]]{{\[}}%[[VAL_10]]] : memref<?xindex> 700e85232fSAart Bik// CHECK: scf.for %[[VAL_12:.*]] = %[[VAL_9]] to %[[VAL_11]] step %[[VAL_2]] { 710e85232fSAart Bik// CHECK: %[[VAL_13:.*]] = memref.load %[[VAL_5]]{{\[}}%[[VAL_12]]] : memref<?xf32> 720e85232fSAart Bik// CHECK: %[[VAL_14:.*]] = memref.load %[[VAL_5]]{{\[}}%[[VAL_12]]] : memref<?xf32> 730e85232fSAart Bik// CHECK: %[[VAL_15:.*]] = arith.addf %[[VAL_13]], %[[VAL_14]] : f32 740e85232fSAart Bik// CHECK: memref.store %[[VAL_15]], %[[VAL_5]]{{\[}}%[[VAL_12]]] : memref<?xf32> 7536b66ab9SAart Bik// CHECK: } 7636b66ab9SAart Bik// CHECK: } 77c5a67e16SYinying Li// CHECK: %[[VAL_16:.*]] = sparse_tensor.load %[[VAL_0]] : tensor<32x16xf32, #sparse{{[0-9]*}}> 78c5a67e16SYinying Li// CHECK: return %[[VAL_16]] : tensor<32x16xf32, #sparse{{[0-9]*}}> 7936b66ab9SAart Bik// CHECK: } 80c66303c2SMatthias Springerfunc.func @sparse_simply_dynamic2(%argx: tensor<32x16xf32, #DCSR>) -> tensor<32x16xf32, #DCSR> { 810e85232fSAart Bik %0 = linalg.generic #trait_scale_inpl 8236b66ab9SAart Bik outs(%argx: tensor<32x16xf32, #DCSR>) { 830e85232fSAart Bik ^bb(%x: f32): 840e85232fSAart Bik %1 = arith.addf %x, %x : f32 8536b66ab9SAart Bik linalg.yield %1 : f32 8636b66ab9SAart Bik } -> tensor<32x16xf32, #DCSR> 8736b66ab9SAart Bik return %0 : tensor<32x16xf32, #DCSR> 8836b66ab9SAart Bik} 891ce77b56SAart Bik 901ce77b56SAart Bik#trait_scale = { 911ce77b56SAart Bik indexing_maps = [ 921ce77b56SAart Bik affine_map<(i,j) -> (i,j)>, // A 931ce77b56SAart Bik affine_map<(i,j) -> (i,j)> // X (out) 941ce77b56SAart Bik ], 951ce77b56SAart Bik iterator_types = ["parallel", "parallel"], 961ce77b56SAart Bik doc = "X(i,j) = A(i,j) * 2.0" 971ce77b56SAart Bik} 981ce77b56SAart Bik 99a3610359SAart Bik// CHECK-LABEL: func.func @sparse_truly_dynamic( 100c5a67e16SYinying Li// CHECK-SAME: %[[VAL_0:.*]]: tensor<10x20xf32, #sparse{{[0-9]*}}>) -> tensor<10x20xf32, #sparse{{[0-9]*}}> { 101a3610359SAart Bik// CHECK-DAG: %[[VAL_1:.*]] = arith.constant 10 : index 102a3610359SAart Bik// CHECK-DAG: %[[VAL_2:.*]] = arith.constant 0 : index 103a3610359SAart Bik// CHECK-DAG: %[[VAL_3:.*]] = arith.constant 1 : index 104a3610359SAart Bik// CHECK-DAG: %[[VAL_4:.*]] = arith.constant 2.000000e+00 : f32 105c5a67e16SYinying Li// CHECK-DAG: %[[VAL_5:.*]] = tensor.empty() : tensor<10x20xf32, #sparse{{[0-9]*}}> 106c5a67e16SYinying Li// CHECK-DAG: %[[VAL_6:.*]] = sparse_tensor.positions %[[VAL_0]] {level = 1 : index} : tensor<10x20xf32, #sparse{{[0-9]*}}> to memref<?xindex> 107c5a67e16SYinying Li// CHECK-DAG: %[[VAL_7:.*]] = sparse_tensor.coordinates %[[VAL_0]] {level = 1 : index} : tensor<10x20xf32, #sparse{{[0-9]*}}> to memref<?xindex> 108c5a67e16SYinying Li// CHECK-DAG: %[[VAL_8:.*]] = sparse_tensor.values %[[VAL_0]] : tensor<10x20xf32, #sparse{{[0-9]*}}> to memref<?xf32> 109c5a67e16SYinying Li// CHECK: %[[VAL_9:.*]] = scf.for %[[VAL_10:.*]] = %[[VAL_2]] to %[[VAL_1]] step %[[VAL_3]] iter_args(%[[VAL_11:.*]] = %[[VAL_5]]) -> (tensor<10x20xf32, #sparse{{[0-9]*}}>) { 1105661647eSAart Bik// CHECK: %[[VAL_12:.*]] = memref.load %[[VAL_6]]{{\[}}%[[VAL_10]]] : memref<?xindex> 1115661647eSAart Bik// CHECK: %[[VAL_13:.*]] = arith.addi %[[VAL_10]], %[[VAL_3]] : index 1125661647eSAart Bik// CHECK: %[[VAL_14:.*]] = memref.load %[[VAL_6]]{{\[}}%[[VAL_13]]] : memref<?xindex> 113c5a67e16SYinying Li// CHECK: %[[VAL_15:.*]] = scf.for %[[VAL_16:.*]] = %[[VAL_12]] to %[[VAL_14]] step %[[VAL_3]] iter_args(%[[VAL_17:.*]] = %[[VAL_11]]) -> (tensor<10x20xf32, #sparse{{[0-9]*}}>) { 1145661647eSAart Bik// CHECK: %[[VAL_18:.*]] = memref.load %[[VAL_7]]{{\[}}%[[VAL_16]]] : memref<?xindex> 1155661647eSAart Bik// CHECK: %[[VAL_19:.*]] = memref.load %[[VAL_8]]{{\[}}%[[VAL_16]]] : memref<?xf32> 1165661647eSAart Bik// CHECK: %[[VAL_20:.*]] = arith.mulf %[[VAL_19]], %[[VAL_4]] : f32 11794e27c26SPeiming Liu// CHECK: %[[VAL_21:.*]] = tensor.insert %[[VAL_20]] into %[[VAL_17]]{{\[}}%[[VAL_10]], %[[VAL_18]]] : tensor<10x20xf32, #sparse{{[0-9]*}}> 118c5a67e16SYinying Li// CHECK: scf.yield %[[VAL_21]] : tensor<10x20xf32, #sparse{{[0-9]*}}> 1191ce77b56SAart Bik// CHECK: } 120c5a67e16SYinying Li// CHECK: scf.yield %[[VAL_22:.*]] : tensor<10x20xf32, #sparse{{[0-9]*}}> 1211ce77b56SAart Bik// CHECK: } 122c5a67e16SYinying Li// CHECK: %[[VAL_23:.*]] = sparse_tensor.load %[[VAL_24:.*]] hasInserts : tensor<10x20xf32, #sparse{{[0-9]*}}> 123c5a67e16SYinying Li// CHECK: return %[[VAL_23]] : tensor<10x20xf32, #sparse{{[0-9]*}}> 1241ce77b56SAart Bik// CHECK: } 125fb35cd3bSRiver Riddlefunc.func @sparse_truly_dynamic(%arga: tensor<10x20xf32, #CSR>) -> tensor<10x20xf32, #DCSR> { 1261ce77b56SAart Bik %s = arith.constant 2.0 : f32 127c6472f57SAart Bik %xm = tensor.empty() : tensor<10x20xf32, #DCSR> 1281ce77b56SAart Bik %0 = linalg.generic #trait_scale 1291ce77b56SAart Bik ins(%arga: tensor<10x20xf32, #CSR>) 1301ce77b56SAart Bik outs(%xm: tensor<10x20xf32, #DCSR>) { 1311ce77b56SAart Bik ^bb(%a: f32, %x: f32): 1321ce77b56SAart Bik %1 = arith.mulf %a, %s : f32 1331ce77b56SAart Bik linalg.yield %1 : f32 1341ce77b56SAart Bik } -> tensor<10x20xf32, #DCSR> 1351ce77b56SAart Bik return %0 : tensor<10x20xf32, #DCSR> 1361ce77b56SAart Bik} 1377d4da4e1SAart Bik 1387d4da4e1SAart Bik#trait_sumred = { 1397d4da4e1SAart Bik indexing_maps = [ 1407d4da4e1SAart Bik affine_map<(i,j,k) -> (i,j,k)>, // A 1417d4da4e1SAart Bik affine_map<(i,j,k) -> (i,j,k)>, // B 1427d4da4e1SAart Bik affine_map<(i,j,k) -> (i,j)> // X (out) 1437d4da4e1SAart Bik ], 1447d4da4e1SAart Bik iterator_types = ["parallel", "parallel", "reduction"], 1457d4da4e1SAart Bik doc = "X(i,j) = SUM_k A(i,j,k) * B(i,j,k)" 1467d4da4e1SAart Bik} 1477d4da4e1SAart Bik 148a3610359SAart Bik// CHECK-LABEL: func.func @sumred( 149c5a67e16SYinying Li// CHECK-SAME: %[[VAL_0:.*]]: tensor<?x?x?xi32, #sparse{{[0-9]*}}>, 150c5a67e16SYinying Li// CHECK-SAME: %[[VAL_1:.*]]: tensor<?x?x?xi32, #sparse{{[0-9]*}}>) -> tensor<?x?xi32, #sparse{{[0-9]*}}> { 1517d4da4e1SAart Bik// CHECK-DAG: %[[VAL_2:.*]] = arith.constant 0 : index 1527d4da4e1SAart Bik// CHECK-DAG: %[[VAL_3:.*]] = arith.constant 1 : index 153a3610359SAart Bik// CHECK-DAG: %[[VAL_4:.*]] = arith.constant 0 : i32 15481d0d2b2SJim Kitchen// CHECK-DAG: %[[VAL_FALSE:.*]] = arith.constant false 15581d0d2b2SJim Kitchen// CHECK-DAG: %[[VAL_TRUE:.*]] = arith.constant true 156*a02010b3SPeiming Liu// CHECK-DAG: %[[VAL_5:.*]] = tensor.dim %[[VAL_0]], %[[VAL_2]] : tensor<?x?x?xi32, #sparse{{[0-9]*}}> 157*a02010b3SPeiming Liu// CHECK-DAG: %[[VAL_6:.*]] = tensor.dim %[[VAL_0]], %[[VAL_3]] : tensor<?x?x?xi32, #sparse{{[0-9]*}}> 158*a02010b3SPeiming Liu// CHECK-DAG: %[[VAL_7:.*]] = tensor.empty(%[[VAL_5]], %[[VAL_6]]) : tensor<?x?xi32, #sparse{{[0-9]*}}> 159*a02010b3SPeiming Liu// CHECK-DAG: %[[VAL_8:.*]] = sparse_tensor.positions %[[VAL_0]] {level = 0 : index} : tensor<?x?x?xi32, #sparse{{[0-9]*}}> to memref<?xindex> 160*a02010b3SPeiming Liu// CHECK-DAG: %[[VAL_9:.*]] = sparse_tensor.coordinates %[[VAL_0]] {level = 0 : index} : tensor<?x?x?xi32, #sparse{{[0-9]*}}> to memref<?xindex> 161*a02010b3SPeiming Liu// CHECK-DAG: %[[VAL_10:.*]] = sparse_tensor.positions %[[VAL_0]] {level = 1 : index} : tensor<?x?x?xi32, #sparse{{[0-9]*}}> to memref<?xindex> 162*a02010b3SPeiming Liu// CHECK-DAG: %[[VAL_11:.*]] = sparse_tensor.coordinates %[[VAL_0]] {level = 1 : index} : tensor<?x?x?xi32, #sparse{{[0-9]*}}> to memref<?xindex> 163*a02010b3SPeiming Liu// CHECK-DAG: %[[VAL_12:.*]] = sparse_tensor.positions %[[VAL_0]] {level = 2 : index} : tensor<?x?x?xi32, #sparse{{[0-9]*}}> to memref<?xindex> 164*a02010b3SPeiming Liu// CHECK-DAG: %[[VAL_13:.*]] = sparse_tensor.coordinates %[[VAL_0]] {level = 2 : index} : tensor<?x?x?xi32, #sparse{{[0-9]*}}> to memref<?xindex> 165*a02010b3SPeiming Liu// CHECK-DAG: %[[VAL_14:.*]] = sparse_tensor.values %[[VAL_0]] : tensor<?x?x?xi32, #sparse{{[0-9]*}}> to memref<?xi32> 166*a02010b3SPeiming Liu// CHECK-DAG: %[[VAL_15:.*]] = sparse_tensor.positions %[[VAL_1]] {level = 0 : index} : tensor<?x?x?xi32, #sparse{{[0-9]*}}> to memref<?xindex> 167*a02010b3SPeiming Liu// CHECK-DAG: %[[VAL_16:.*]] = sparse_tensor.coordinates %[[VAL_1]] {level = 0 : index} : tensor<?x?x?xi32, #sparse{{[0-9]*}}> to memref<?xindex> 168*a02010b3SPeiming Liu// CHECK-DAG: %[[VAL_17:.*]] = sparse_tensor.positions %[[VAL_1]] {level = 1 : index} : tensor<?x?x?xi32, #sparse{{[0-9]*}}> to memref<?xindex> 169*a02010b3SPeiming Liu// CHECK-DAG: %[[VAL_18:.*]] = sparse_tensor.coordinates %[[VAL_1]] {level = 1 : index} : tensor<?x?x?xi32, #sparse{{[0-9]*}}> to memref<?xindex> 170*a02010b3SPeiming Liu// CHECK-DAG: %[[VAL_19:.*]] = sparse_tensor.positions %[[VAL_1]] {level = 2 : index} : tensor<?x?x?xi32, #sparse{{[0-9]*}}> to memref<?xindex> 171*a02010b3SPeiming Liu// CHECK-DAG: %[[VAL_20:.*]] = sparse_tensor.coordinates %[[VAL_1]] {level = 2 : index} : tensor<?x?x?xi32, #sparse{{[0-9]*}}> to memref<?xindex> 172*a02010b3SPeiming Liu// CHECK-DAG: %[[VAL_21:.*]] = sparse_tensor.values %[[VAL_1]] : tensor<?x?x?xi32, #sparse{{[0-9]*}}> to memref<?xi32> 173a3610359SAart Bik// CHECK: %[[VAL_22:.*]] = memref.load %[[VAL_8]]{{\[}}%[[VAL_2]]] : memref<?xindex> 174a3610359SAart Bik// CHECK: %[[VAL_23:.*]] = memref.load %[[VAL_8]]{{\[}}%[[VAL_3]]] : memref<?xindex> 175a3610359SAart Bik// CHECK: %[[VAL_24:.*]] = memref.load %[[VAL_15]]{{\[}}%[[VAL_2]]] : memref<?xindex> 176a3610359SAart Bik// CHECK: %[[VAL_25:.*]] = memref.load %[[VAL_15]]{{\[}}%[[VAL_3]]] : memref<?xindex> 177c5a67e16SYinying Li// CHECK: %[[VAL_26:.*]]:3 = scf.while (%[[VAL_27:.*]] = %[[VAL_22]], %[[VAL_28:.*]] = %[[VAL_24]], %[[VAL_29:.*]] = %[[VAL_7]]) : (index, index, tensor<?x?xi32, #sparse{{[0-9]*}}>) -> (index, index, tensor<?x?xi32, #sparse{{[0-9]*}}>) { 1785661647eSAart Bik// CHECK: %[[VAL_30:.*]] = arith.cmpi ult, %[[VAL_27]], %[[VAL_23]] : index 1795661647eSAart Bik// CHECK: %[[VAL_31:.*]] = arith.cmpi ult, %[[VAL_28]], %[[VAL_25]] : index 1805661647eSAart Bik// CHECK: %[[VAL_32:.*]] = arith.andi %[[VAL_30]], %[[VAL_31]] : i1 181c5a67e16SYinying Li// CHECK: scf.condition(%[[VAL_32]]) %[[VAL_27]], %[[VAL_28]], %[[VAL_29]] : index, index, tensor<?x?xi32, #sparse{{[0-9]*}}> 1827d4da4e1SAart Bik// CHECK: } do { 183c5a67e16SYinying Li// CHECK: ^bb0(%[[VAL_33:.*]]: index, %[[VAL_34:.*]]: index, %[[VAL_35:.*]]: tensor<?x?xi32, #sparse{{[0-9]*}}>): 1845661647eSAart Bik// CHECK: %[[VAL_36:.*]] = memref.load %[[VAL_9]]{{\[}}%[[VAL_33]]] : memref<?xindex> 1855661647eSAart Bik// CHECK: %[[VAL_37:.*]] = memref.load %[[VAL_16]]{{\[}}%[[VAL_34]]] : memref<?xindex> 1865661647eSAart Bik// CHECK: %[[VAL_38:.*]] = arith.cmpi ult, %[[VAL_37]], %[[VAL_36]] : index 1875661647eSAart Bik// CHECK: %[[VAL_39:.*]] = arith.select %[[VAL_38]], %[[VAL_37]], %[[VAL_36]] : index 1885661647eSAart Bik// CHECK: %[[VAL_40:.*]] = arith.cmpi eq, %[[VAL_36]], %[[VAL_39]] : index 1895661647eSAart Bik// CHECK: %[[VAL_41:.*]] = arith.cmpi eq, %[[VAL_37]], %[[VAL_39]] : index 1905661647eSAart Bik// CHECK: %[[VAL_42:.*]] = arith.andi %[[VAL_40]], %[[VAL_41]] : i1 191c5a67e16SYinying Li// CHECK: %[[VAL_43:.*]] = scf.if %[[VAL_42]] -> (tensor<?x?xi32, #sparse{{[0-9]*}}>) { 1925661647eSAart Bik// CHECK: %[[VAL_44:.*]] = memref.load %[[VAL_10]]{{\[}}%[[VAL_33]]] : memref<?xindex> 193a3610359SAart Bik// CHECK: %[[VAL_45:.*]] = arith.addi %[[VAL_33]], %[[VAL_3]] : index 1945661647eSAart Bik// CHECK: %[[VAL_46:.*]] = memref.load %[[VAL_10]]{{\[}}%[[VAL_45]]] : memref<?xindex> 1955661647eSAart Bik// CHECK: %[[VAL_47:.*]] = memref.load %[[VAL_17]]{{\[}}%[[VAL_34]]] : memref<?xindex> 1965661647eSAart Bik// CHECK: %[[VAL_48:.*]] = arith.addi %[[VAL_34]], %[[VAL_3]] : index 1975661647eSAart Bik// CHECK: %[[VAL_49:.*]] = memref.load %[[VAL_17]]{{\[}}%[[VAL_48]]] : memref<?xindex> 198c5a67e16SYinying Li// CHECK: %[[VAL_50:.*]]:3 = scf.while (%[[VAL_51:.*]] = %[[VAL_44]], %[[VAL_52:.*]] = %[[VAL_47]], %[[VAL_53:.*]] = %[[VAL_35]]) : (index, index, tensor<?x?xi32, #sparse{{[0-9]*}}>) -> (index, index, tensor<?x?xi32, #sparse{{[0-9]*}}>) { 1995661647eSAart Bik// CHECK: %[[VAL_54:.*]] = arith.cmpi ult, %[[VAL_51]], %[[VAL_46]] : index 2005661647eSAart Bik// CHECK: %[[VAL_55:.*]] = arith.cmpi ult, %[[VAL_52]], %[[VAL_49]] : index 2015661647eSAart Bik// CHECK: %[[VAL_56:.*]] = arith.andi %[[VAL_54]], %[[VAL_55]] : i1 202c5a67e16SYinying Li// CHECK: scf.condition(%[[VAL_56]]) %[[VAL_51]], %[[VAL_52]], %[[VAL_53]] : index, index, tensor<?x?xi32, #sparse{{[0-9]*}}> 2037d4da4e1SAart Bik// CHECK: } do { 204c5a67e16SYinying Li// CHECK: ^bb0(%[[VAL_57:.*]]: index, %[[VAL_58:.*]]: index, %[[VAL_59:.*]]: tensor<?x?xi32, #sparse{{[0-9]*}}>): 2055661647eSAart Bik// CHECK: %[[VAL_60:.*]] = memref.load %[[VAL_11]]{{\[}}%[[VAL_57]]] : memref<?xindex> 2065661647eSAart Bik// CHECK: %[[VAL_61:.*]] = memref.load %[[VAL_18]]{{\[}}%[[VAL_58]]] : memref<?xindex> 2075661647eSAart Bik// CHECK: %[[VAL_62:.*]] = arith.cmpi ult, %[[VAL_61]], %[[VAL_60]] : index 2085661647eSAart Bik// CHECK: %[[VAL_63:.*]] = arith.select %[[VAL_62]], %[[VAL_61]], %[[VAL_60]] : index 2095661647eSAart Bik// CHECK: %[[VAL_64:.*]] = arith.cmpi eq, %[[VAL_60]], %[[VAL_63]] : index 2105661647eSAart Bik// CHECK: %[[VAL_65:.*]] = arith.cmpi eq, %[[VAL_61]], %[[VAL_63]] : index 2115661647eSAart Bik// CHECK: %[[VAL_66:.*]] = arith.andi %[[VAL_64]], %[[VAL_65]] : i1 212c5a67e16SYinying Li// CHECK: %[[VAL_67:.*]] = scf.if %[[VAL_66]] -> (tensor<?x?xi32, #sparse{{[0-9]*}}>) { 2135661647eSAart Bik// CHECK: %[[VAL_68:.*]] = memref.load %[[VAL_12]]{{\[}}%[[VAL_57]]] : memref<?xindex> 2145661647eSAart Bik// CHECK: %[[VAL_69:.*]] = arith.addi %[[VAL_57]], %[[VAL_3]] : index 2155661647eSAart Bik// CHECK: %[[VAL_70:.*]] = memref.load %[[VAL_12]]{{\[}}%[[VAL_69]]] : memref<?xindex> 2165661647eSAart Bik// CHECK: %[[VAL_71:.*]] = memref.load %[[VAL_19]]{{\[}}%[[VAL_58]]] : memref<?xindex> 2175661647eSAart Bik// CHECK: %[[VAL_72:.*]] = arith.addi %[[VAL_58]], %[[VAL_3]] : index 2185661647eSAart Bik// CHECK: %[[VAL_73:.*]] = memref.load %[[VAL_19]]{{\[}}%[[VAL_72]]] : memref<?xindex> 219c5a67e16SYinying Li// CHECK: %[[VAL_74:.*]]:5 = scf.while (%[[VAL_75:.*]] = %[[VAL_68]], %[[VAL_76:.*]] = %[[VAL_71]], %[[VAL_77:.*]] = %[[VAL_4]], %[[VAL_200:.*]] = %[[VAL_FALSE]], %[[VAL_78:.*]] = %[[VAL_59]]) : (index, index, i32, i1, tensor<?x?xi32, #sparse{{[0-9]*}}>) -> (index, index, i32, i1, tensor<?x?xi32, #sparse{{[0-9]*}}>) { 2205661647eSAart Bik// CHECK: %[[VAL_79:.*]] = arith.cmpi ult, %[[VAL_75]], %[[VAL_70]] : index 2215661647eSAart Bik// CHECK: %[[VAL_80:.*]] = arith.cmpi ult, %[[VAL_76]], %[[VAL_73]] : index 2225661647eSAart Bik// CHECK: %[[VAL_81:.*]] = arith.andi %[[VAL_79]], %[[VAL_80]] : i1 223c5a67e16SYinying Li// CHECK: scf.condition(%[[VAL_81]]) %[[VAL_75]], %[[VAL_76]], %[[VAL_77]], %[[VAL_200]], %[[VAL_78]] : index, index, i32, i1, tensor<?x?xi32, #sparse{{[0-9]*}}> 2247d4da4e1SAart Bik// CHECK: } do { 225c5a67e16SYinying Li// CHECK: ^bb0(%[[VAL_82:.*]]: index, %[[VAL_83:.*]]: index, %[[VAL_84:.*]]: i32, %[[VAL_201:.*]]: i1, %[[VAL_85:.*]]: tensor<?x?xi32, #sparse{{[0-9]*}}>): 2265661647eSAart Bik// CHECK: %[[VAL_86:.*]] = memref.load %[[VAL_13]]{{\[}}%[[VAL_82]]] : memref<?xindex> 2275661647eSAart Bik// CHECK: %[[VAL_87:.*]] = memref.load %[[VAL_20]]{{\[}}%[[VAL_83]]] : memref<?xindex> 2285661647eSAart Bik// CHECK: %[[VAL_88:.*]] = arith.cmpi ult, %[[VAL_87]], %[[VAL_86]] : index 2295661647eSAart Bik// CHECK: %[[VAL_89:.*]] = arith.select %[[VAL_88]], %[[VAL_87]], %[[VAL_86]] : index 2305661647eSAart Bik// CHECK: %[[VAL_90:.*]] = arith.cmpi eq, %[[VAL_86]], %[[VAL_89]] : index 2315661647eSAart Bik// CHECK: %[[VAL_91:.*]] = arith.cmpi eq, %[[VAL_87]], %[[VAL_89]] : index 2325661647eSAart Bik// CHECK: %[[VAL_92:.*]] = arith.andi %[[VAL_90]], %[[VAL_91]] : i1 233c5a67e16SYinying Li// CHECK: %[[VAL_93:.*]]:3 = scf.if %[[VAL_92]] -> (i32, i1, tensor<?x?xi32, #sparse{{[0-9]*}}>) { 2345661647eSAart Bik// CHECK: %[[VAL_94:.*]] = memref.load %[[VAL_14]]{{\[}}%[[VAL_82]]] : memref<?xi32> 2355661647eSAart Bik// CHECK: %[[VAL_95:.*]] = memref.load %[[VAL_21]]{{\[}}%[[VAL_83]]] : memref<?xi32> 2365661647eSAart Bik// CHECK: %[[VAL_96:.*]] = arith.muli %[[VAL_94]], %[[VAL_95]] : i32 2375661647eSAart Bik// CHECK: %[[VAL_97:.*]] = arith.addi %[[VAL_84]], %[[VAL_96]] : i32 238c5a67e16SYinying Li// CHECK: scf.yield %[[VAL_97]], %[[VAL_TRUE]], %[[VAL_85]] : i32, i1, tensor<?x?xi32, #sparse{{[0-9]*}}> 2397d4da4e1SAart Bik// CHECK: } else { 240c5a67e16SYinying Li// CHECK: scf.yield %[[VAL_84]], %[[VAL_201]], %[[VAL_85]] : i32, i1, tensor<?x?xi32, #sparse{{[0-9]*}}> 2417d4da4e1SAart Bik// CHECK: } 2425661647eSAart Bik// CHECK: %[[VAL_98:.*]] = arith.cmpi eq, %[[VAL_86]], %[[VAL_89]] : index 2435661647eSAart Bik// CHECK: %[[VAL_99:.*]] = arith.addi %[[VAL_82]], %[[VAL_3]] : index 2445661647eSAart Bik// CHECK: %[[VAL_100:.*]] = arith.select %[[VAL_98]], %[[VAL_99]], %[[VAL_82]] : index 2455661647eSAart Bik// CHECK: %[[VAL_101:.*]] = arith.cmpi eq, %[[VAL_87]], %[[VAL_89]] : index 2465661647eSAart Bik// CHECK: %[[VAL_102:.*]] = arith.addi %[[VAL_83]], %[[VAL_3]] : index 2475661647eSAart Bik// CHECK: %[[VAL_103:.*]] = arith.select %[[VAL_101]], %[[VAL_102]], %[[VAL_83]] : index 248c5a67e16SYinying Li// CHECK: scf.yield %[[VAL_100]], %[[VAL_103]], %[[VAL_104:.*]]#0, %[[VAL_104]]#1, %[[VAL_104]]#2 : index, index, i32, i1, tensor<?x?xi32, #sparse{{[0-9]*}}> 2497d4da4e1SAart Bik// CHECK: } 250c5a67e16SYinying Li// CHECK: %[[VAL_202:.*]] = scf.if %[[VAL_74]]#3 -> (tensor<?x?xi32, #sparse{{[0-9]*}}>) { 25194e27c26SPeiming Liu// CHECK: %[[VAL_105:.*]] = tensor.insert %[[VAL_74]]#2 into %[[VAL_74]]#4{{\[}}%[[VAL_39]], %[[VAL_63]]] : tensor<?x?xi32, #sparse{{[0-9]*}}> 252c5a67e16SYinying Li// CHECK: scf.yield %[[VAL_105]] : tensor<?x?xi32, #sparse{{[0-9]*}}> 2537d4da4e1SAart Bik// CHECK: } else { 254c5a67e16SYinying Li// CHECK: scf.yield %[[VAL_74]]#4 : tensor<?x?xi32, #sparse{{[0-9]*}}> 25581d0d2b2SJim Kitchen// CHECK: } 256c5a67e16SYinying Li// CHECK: scf.yield %[[VAL_202]] : tensor<?x?xi32, #sparse{{[0-9]*}}> 25781d0d2b2SJim Kitchen// CHECK: } else { 258c5a67e16SYinying Li// CHECK: scf.yield %[[VAL_59]] : tensor<?x?xi32, #sparse{{[0-9]*}}> 2597d4da4e1SAart Bik// CHECK: } 2605661647eSAart Bik// CHECK: %[[VAL_107:.*]] = arith.cmpi eq, %[[VAL_60]], %[[VAL_63]] : index 2615661647eSAart Bik// CHECK: %[[VAL_108:.*]] = arith.addi %[[VAL_57]], %[[VAL_3]] : index 2625661647eSAart Bik// CHECK: %[[VAL_109:.*]] = arith.select %[[VAL_107]], %[[VAL_108]], %[[VAL_57]] : index 2635661647eSAart Bik// CHECK: %[[VAL_110:.*]] = arith.cmpi eq, %[[VAL_61]], %[[VAL_63]] : index 2645661647eSAart Bik// CHECK: %[[VAL_111:.*]] = arith.addi %[[VAL_58]], %[[VAL_3]] : index 2655661647eSAart Bik// CHECK: %[[VAL_112:.*]] = arith.select %[[VAL_110]], %[[VAL_111]], %[[VAL_58]] : index 266c5a67e16SYinying Li// CHECK: scf.yield %[[VAL_109]], %[[VAL_112]], %[[VAL_113:.*]] : index, index, tensor<?x?xi32, #sparse{{[0-9]*}}> 2677d4da4e1SAart Bik// CHECK: } 268c5a67e16SYinying Li// CHECK: scf.yield %[[VAL_114:.*]]#2 : tensor<?x?xi32, #sparse{{[0-9]*}}> 2697d4da4e1SAart Bik// CHECK: } else { 270c5a67e16SYinying Li// CHECK: scf.yield %[[VAL_35]] : tensor<?x?xi32, #sparse{{[0-9]*}}> 2717d4da4e1SAart Bik// CHECK: } 2725661647eSAart Bik// CHECK: %[[VAL_115:.*]] = arith.cmpi eq, %[[VAL_36]], %[[VAL_39]] : index 2735661647eSAart Bik// CHECK: %[[VAL_116:.*]] = arith.addi %[[VAL_33]], %[[VAL_3]] : index 2745661647eSAart Bik// CHECK: %[[VAL_117:.*]] = arith.select %[[VAL_115]], %[[VAL_116]], %[[VAL_33]] : index 2755661647eSAart Bik// CHECK: %[[VAL_118:.*]] = arith.cmpi eq, %[[VAL_37]], %[[VAL_39]] : index 2765661647eSAart Bik// CHECK: %[[VAL_119:.*]] = arith.addi %[[VAL_34]], %[[VAL_3]] : index 2775661647eSAart Bik// CHECK: %[[VAL_120:.*]] = arith.select %[[VAL_118]], %[[VAL_119]], %[[VAL_34]] : index 278c5a67e16SYinying Li// CHECK: scf.yield %[[VAL_117]], %[[VAL_120]], %[[VAL_121:.*]] : index, index, tensor<?x?xi32, #sparse{{[0-9]*}}> 2797d4da4e1SAart Bik// CHECK: } 280c5a67e16SYinying Li// CHECK: %[[VAL_122:.*]] = sparse_tensor.load %[[VAL_123:.*]]#2 hasInserts : tensor<?x?xi32, #sparse{{[0-9]*}}> 281c5a67e16SYinying Li// CHECK: return %[[VAL_122]] : tensor<?x?xi32, #sparse{{[0-9]*}}> 2827d4da4e1SAart Bik// CHECK: } 283fb35cd3bSRiver Riddlefunc.func @sumred(%arga: tensor<?x?x?xi32, #SparseTensor>, 2847d4da4e1SAart Bik %argb: tensor<?x?x?xi32, #SparseTensor>) -> tensor<?x?xi32, #DCSR> { 2857d4da4e1SAart Bik %c0 = arith.constant 0 : index 2867d4da4e1SAart Bik %c1 = arith.constant 1 : index 2877d4da4e1SAart Bik %d0 = tensor.dim %arga, %c0 : tensor<?x?x?xi32, #SparseTensor> 2887d4da4e1SAart Bik %d1 = tensor.dim %arga, %c1 : tensor<?x?x?xi32, #SparseTensor> 289c6472f57SAart Bik %xinit = tensor.empty(%d0, %d1) : tensor<?x?xi32, #DCSR> 2907d4da4e1SAart Bik %0 = linalg.generic #trait_sumred 2917d4da4e1SAart Bik ins(%arga, %argb: tensor<?x?x?xi32, #SparseTensor>, 2927d4da4e1SAart Bik tensor<?x?x?xi32, #SparseTensor>) 2937d4da4e1SAart Bik outs(%xinit: tensor<?x?xi32, #DCSR>) { 2947d4da4e1SAart Bik ^bb(%a: i32, %b: i32, %x: i32): 2957d4da4e1SAart Bik %0 = arith.muli %a, %b : i32 2967d4da4e1SAart Bik %1 = arith.addi %x, %0 : i32 2977d4da4e1SAart Bik linalg.yield %1 : i32 2987d4da4e1SAart Bik } -> tensor<?x?xi32, #DCSR> 2997d4da4e1SAart Bik return %0 : tensor<?x?xi32, #DCSR> 3007d4da4e1SAart Bik} 301e1b9d805SAart Bik 302e1b9d805SAart Bik#trait_matmat = { 303e1b9d805SAart Bik indexing_maps = [ 304e1b9d805SAart Bik affine_map<(i,j,k) -> (i,k)>, // A 305e1b9d805SAart Bik affine_map<(i,j,k) -> (k,j)>, // B 306e1b9d805SAart Bik affine_map<(i,j,k) -> (i,j)> // C (out) 307e1b9d805SAart Bik ], 308e1b9d805SAart Bik iterator_types = ["parallel", "parallel", "reduction"], 309e1b9d805SAart Bik doc = "C(i,j) = SUM_k A(i,k) * B(k,j)" 310e1b9d805SAart Bik} 311e1b9d805SAart Bik 312a3610359SAart Bik// CHECK-LABEL: func.func @matmat( 313c5a67e16SYinying Li// CHECK-SAME: %[[VAL_0:.*]]: tensor<?x?xf32, #sparse{{[0-9]*}}>, 314c5a67e16SYinying Li// CHECK-SAME: %[[VAL_1:.*]]: tensor<?x?xf32, #sparse{{[0-9]*}}>) -> tensor<?x?xf32, #sparse{{[0-9]*}}> { 3155661647eSAart Bik// CHECK-DAG: %[[VAL_2:.*]] = arith.constant 0 : index 3165661647eSAart Bik// CHECK-DAG: %[[VAL_3:.*]] = arith.constant 1 : index 3175661647eSAart Bik// CHECK-DAG: %[[VAL_4:.*]] = arith.constant false 3185661647eSAart Bik// CHECK-DAG: %[[VAL_5:.*]] = arith.constant true 319*a02010b3SPeiming Liu// CHECK-DAG: %[[VAL_6:.*]] = tensor.dim %[[VAL_0]], %[[VAL_2]] : tensor<?x?xf32, #sparse{{[0-9]*}}> 320*a02010b3SPeiming Liu// CHECK-DAG: %[[VAL_7:.*]] = tensor.dim %[[VAL_1]], %[[VAL_3]] : tensor<?x?xf32, #sparse{{[0-9]*}}> 321*a02010b3SPeiming Liu// CHECK-DAG: %[[VAL_8:.*]] = tensor.empty(%[[VAL_6]], %[[VAL_7]]) : tensor<?x?xf32, #sparse{{[0-9]*}}> 322*a02010b3SPeiming Liu// CHECK-DAG: %[[VAL_9:.*]] = sparse_tensor.positions %[[VAL_0]] {level = 0 : index} : tensor<?x?xf32, #sparse{{[0-9]*}}> to memref<?xindex> 323*a02010b3SPeiming Liu// CHECK-DAG: %[[VAL_10:.*]] = sparse_tensor.coordinates %[[VAL_0]] {level = 0 : index} : tensor<?x?xf32, #sparse{{[0-9]*}}> to memref<?xindex> 324*a02010b3SPeiming Liu// CHECK-DAG: %[[VAL_11:.*]] = sparse_tensor.positions %[[VAL_0]] {level = 1 : index} : tensor<?x?xf32, #sparse{{[0-9]*}}> to memref<?xindex> 325*a02010b3SPeiming Liu// CHECK-DAG: %[[VAL_12:.*]] = sparse_tensor.coordinates %[[VAL_0]] {level = 1 : index} : tensor<?x?xf32, #sparse{{[0-9]*}}> to memref<?xindex> 326*a02010b3SPeiming Liu// CHECK-DAG: %[[VAL_13:.*]] = sparse_tensor.values %[[VAL_0]] : tensor<?x?xf32, #sparse{{[0-9]*}}> to memref<?xf32> 327*a02010b3SPeiming Liu// CHECK-DAG: %[[VAL_14:.*]] = sparse_tensor.positions %[[VAL_1]] {level = 0 : index} : tensor<?x?xf32, #sparse{{[0-9]*}}> to memref<?xindex> 328*a02010b3SPeiming Liu// CHECK-DAG: %[[VAL_15:.*]] = sparse_tensor.coordinates %[[VAL_1]] {level = 0 : index} : tensor<?x?xf32, #sparse{{[0-9]*}}> to memref<?xindex> 329*a02010b3SPeiming Liu// CHECK-DAG: %[[VAL_16:.*]] = sparse_tensor.positions %[[VAL_1]] {level = 1 : index} : tensor<?x?xf32, #sparse{{[0-9]*}}> to memref<?xindex> 330*a02010b3SPeiming Liu// CHECK-DAG: %[[VAL_17:.*]] = sparse_tensor.coordinates %[[VAL_1]] {level = 1 : index} : tensor<?x?xf32, #sparse{{[0-9]*}}> to memref<?xindex> 331*a02010b3SPeiming Liu// CHECK-DAG: %[[VAL_18:.*]] = sparse_tensor.values %[[VAL_1]] : tensor<?x?xf32, #sparse{{[0-9]*}}> to memref<?xf32> 332a3610359SAart Bik// CHECK: %[[VAL_19:.*]] = memref.load %[[VAL_9]]{{\[}}%[[VAL_2]]] : memref<?xindex> 333a3610359SAart Bik// CHECK: %[[VAL_20:.*]] = memref.load %[[VAL_9]]{{\[}}%[[VAL_3]]] : memref<?xindex> 334c5a67e16SYinying Li// CHECK: %[[VAL_21:.*]] = scf.for %[[VAL_22:.*]] = %[[VAL_19]] to %[[VAL_20]] step %[[VAL_3]] iter_args(%[[VAL_23:.*]] = %[[VAL_8]]) -> (tensor<?x?xf32, #sparse{{[0-9]*}}>) { 3355661647eSAart Bik// CHECK: %[[VAL_24:.*]] = memref.load %[[VAL_10]]{{\[}}%[[VAL_22]]] : memref<?xindex> 336c5a67e16SYinying Li// CHECK: %[[VAL_25:.*]], %[[VAL_26:.*]], %[[VAL_27:.*]], %[[VAL_28:.*]] = sparse_tensor.expand %[[VAL_8]] : tensor<?x?xf32, #sparse{{[0-9]*}}> to memref<?xf32>, memref<?xi1>, memref<?xindex> 3375661647eSAart Bik// CHECK: %[[VAL_29:.*]] = memref.load %[[VAL_11]]{{\[}}%[[VAL_22]]] : memref<?xindex> 3385661647eSAart Bik// CHECK: %[[VAL_30:.*]] = arith.addi %[[VAL_22]], %[[VAL_3]] : index 3395661647eSAart Bik// CHECK: %[[VAL_31:.*]] = memref.load %[[VAL_11]]{{\[}}%[[VAL_30]]] : memref<?xindex> 3405661647eSAart Bik// CHECK: %[[VAL_32:.*]] = memref.load %[[VAL_14]]{{\[}}%[[VAL_2]]] : memref<?xindex> 3415661647eSAart Bik// CHECK: %[[VAL_33:.*]] = memref.load %[[VAL_14]]{{\[}}%[[VAL_3]]] : memref<?xindex> 342c5a67e16SYinying Li// CHECK: %[[VAL_34:.*]]:4 = scf.while (%[[VAL_35:.*]] = %[[VAL_29]], %[[VAL_36:.*]] = %[[VAL_32]], %[[VAL_37:.*]] = %[[VAL_28]], %[[VAL_38:.*]] = %[[VAL_23]]) : (index, index, index, tensor<?x?xf32, #sparse{{[0-9]*}}>) -> (index, index, index, tensor<?x?xf32, #sparse{{[0-9]*}}>) { 3435661647eSAart Bik// CHECK: %[[VAL_39:.*]] = arith.cmpi ult, %[[VAL_35]], %[[VAL_31]] : index 3445661647eSAart Bik// CHECK: %[[VAL_40:.*]] = arith.cmpi ult, %[[VAL_36]], %[[VAL_33]] : index 3455661647eSAart Bik// CHECK: %[[VAL_41:.*]] = arith.andi %[[VAL_39]], %[[VAL_40]] : i1 346c5a67e16SYinying Li// CHECK: scf.condition(%[[VAL_41]]) %[[VAL_35]], %[[VAL_36]], %[[VAL_37]], %[[VAL_38]] : index, index, index, tensor<?x?xf32, #sparse{{[0-9]*}}> 347e1b9d805SAart Bik// CHECK: } do { 348c5a67e16SYinying Li// CHECK: ^bb0(%[[VAL_42:.*]]: index, %[[VAL_43:.*]]: index, %[[VAL_44:.*]]: index, %[[VAL_45:.*]]: tensor<?x?xf32, #sparse{{[0-9]*}}>): 3495661647eSAart Bik// CHECK: %[[VAL_46:.*]] = memref.load %[[VAL_12]]{{\[}}%[[VAL_42]]] : memref<?xindex> 3505661647eSAart Bik// CHECK: %[[VAL_47:.*]] = memref.load %[[VAL_15]]{{\[}}%[[VAL_43]]] : memref<?xindex> 3515661647eSAart Bik// CHECK: %[[VAL_48:.*]] = arith.cmpi ult, %[[VAL_47]], %[[VAL_46]] : index 3525661647eSAart Bik// CHECK: %[[VAL_49:.*]] = arith.select %[[VAL_48]], %[[VAL_47]], %[[VAL_46]] : index 3535661647eSAart Bik// CHECK: %[[VAL_50:.*]] = arith.cmpi eq, %[[VAL_46]], %[[VAL_49]] : index 3545661647eSAart Bik// CHECK: %[[VAL_51:.*]] = arith.cmpi eq, %[[VAL_47]], %[[VAL_49]] : index 3555661647eSAart Bik// CHECK: %[[VAL_52:.*]] = arith.andi %[[VAL_50]], %[[VAL_51]] : i1 356c5a67e16SYinying Li// CHECK: %[[VAL_53:.*]]:2 = scf.if %[[VAL_52]] -> (index, tensor<?x?xf32, #sparse{{[0-9]*}}>) { 3575661647eSAart Bik// CHECK: %[[VAL_54:.*]] = memref.load %[[VAL_13]]{{\[}}%[[VAL_42]]] : memref<?xf32> 3585661647eSAart Bik// CHECK: %[[VAL_55:.*]] = memref.load %[[VAL_16]]{{\[}}%[[VAL_43]]] : memref<?xindex> 3595661647eSAart Bik// CHECK: %[[VAL_56:.*]] = arith.addi %[[VAL_43]], %[[VAL_3]] : index 3605661647eSAart Bik// CHECK: %[[VAL_57:.*]] = memref.load %[[VAL_16]]{{\[}}%[[VAL_56]]] : memref<?xindex> 3615661647eSAart Bik// CHECK: %[[VAL_58:.*]] = scf.for %[[VAL_59:.*]] = %[[VAL_55]] to %[[VAL_57]] step %[[VAL_3]] iter_args(%[[VAL_60:.*]] = %[[VAL_44]]) -> (index) { 3625661647eSAart Bik// CHECK: %[[VAL_61:.*]] = memref.load %[[VAL_17]]{{\[}}%[[VAL_59]]] : memref<?xindex> 3635661647eSAart Bik// CHECK: %[[VAL_62:.*]] = memref.load %[[VAL_25]]{{\[}}%[[VAL_61]]] : memref<?xf32> 3645661647eSAart Bik// CHECK: %[[VAL_63:.*]] = memref.load %[[VAL_18]]{{\[}}%[[VAL_59]]] : memref<?xf32> 3655661647eSAart Bik// CHECK: %[[VAL_64:.*]] = arith.mulf %[[VAL_54]], %[[VAL_63]] : f32 3665661647eSAart Bik// CHECK: %[[VAL_65:.*]] = arith.addf %[[VAL_62]], %[[VAL_64]] : f32 3675661647eSAart Bik// CHECK: %[[VAL_66:.*]] = memref.load %[[VAL_26]]{{\[}}%[[VAL_61]]] : memref<?xi1> 3685661647eSAart Bik// CHECK: %[[VAL_67:.*]] = arith.cmpi eq, %[[VAL_66]], %[[VAL_4]] : i1 3695661647eSAart Bik// CHECK: %[[VAL_68:.*]] = scf.if %[[VAL_67]] -> (index) { 3705661647eSAart Bik// CHECK: memref.store %[[VAL_5]], %[[VAL_26]]{{\[}}%[[VAL_61]]] : memref<?xi1> 3715661647eSAart Bik// CHECK: memref.store %[[VAL_61]], %[[VAL_27]]{{\[}}%[[VAL_60]]] : memref<?xindex> 3725661647eSAart Bik// CHECK: %[[VAL_69:.*]] = arith.addi %[[VAL_60]], %[[VAL_3]] : index 3735661647eSAart Bik// CHECK: scf.yield %[[VAL_69]] : index 374e1b9d805SAart Bik// CHECK: } else { 3755661647eSAart Bik// CHECK: scf.yield %[[VAL_60]] : index 376e1b9d805SAart Bik// CHECK: } 3775661647eSAart Bik// CHECK: memref.store %[[VAL_65]], %[[VAL_25]]{{\[}}%[[VAL_61]]] : memref<?xf32> 3785661647eSAart Bik// CHECK: scf.yield %[[VAL_70:.*]] : index 379e1b9d805SAart Bik// CHECK: } 380c5a67e16SYinying Li// CHECK: scf.yield %[[VAL_71:.*]], %[[VAL_45]] : index, tensor<?x?xf32, #sparse{{[0-9]*}}> 381e1b9d805SAart Bik// CHECK: } else { 382c5a67e16SYinying Li// CHECK: scf.yield %[[VAL_44]], %[[VAL_45]] : index, tensor<?x?xf32, #sparse{{[0-9]*}}> 383e1b9d805SAart Bik// CHECK: } 3845661647eSAart Bik// CHECK: %[[VAL_72:.*]] = arith.cmpi eq, %[[VAL_46]], %[[VAL_49]] : index 3855661647eSAart Bik// CHECK: %[[VAL_73:.*]] = arith.addi %[[VAL_42]], %[[VAL_3]] : index 3865661647eSAart Bik// CHECK: %[[VAL_74:.*]] = arith.select %[[VAL_72]], %[[VAL_73]], %[[VAL_42]] : index 3875661647eSAart Bik// CHECK: %[[VAL_75:.*]] = arith.cmpi eq, %[[VAL_47]], %[[VAL_49]] : index 3885661647eSAart Bik// CHECK: %[[VAL_76:.*]] = arith.addi %[[VAL_43]], %[[VAL_3]] : index 3895661647eSAart Bik// CHECK: %[[VAL_77:.*]] = arith.select %[[VAL_75]], %[[VAL_76]], %[[VAL_43]] : index 390c5a67e16SYinying Li// CHECK: scf.yield %[[VAL_74]], %[[VAL_77]], %[[VAL_78:.*]]#0, %[[VAL_78]]#1 : index, index, index, tensor<?x?xf32, #sparse{{[0-9]*}}> 391e1b9d805SAart Bik// CHECK: } 392c5a67e16SYinying Li// CHECK: %[[VAL_79:.*]] = sparse_tensor.compress %[[VAL_25]], %[[VAL_26]], %[[VAL_27]], %[[VAL_80:.*]]#2 into %[[VAL_80]]#3{{\[}}%[[VAL_24]]] : memref<?xf32>, memref<?xi1>, memref<?xindex>, tensor<?x?xf32, #sparse{{[0-9]*}}> 393c5a67e16SYinying Li// CHECK: scf.yield %[[VAL_79]] : tensor<?x?xf32, #sparse{{[0-9]*}}> 394e1b9d805SAart Bik// CHECK: } 395c5a67e16SYinying Li// CHECK: %[[VAL_81:.*]] = sparse_tensor.load %[[VAL_82:.*]] hasInserts : tensor<?x?xf32, #sparse{{[0-9]*}}> 396c5a67e16SYinying Li// CHECK: return %[[VAL_81]] : tensor<?x?xf32, #sparse{{[0-9]*}}> 397e1b9d805SAart Bik// CHECK: } 398fb35cd3bSRiver Riddlefunc.func @matmat(%arga: tensor<?x?xf32, #DCSR>, 399e1b9d805SAart Bik %argb: tensor<?x?xf32, #DCSR>) -> tensor<?x?xf32, #DCSR> { 400e1b9d805SAart Bik %c0 = arith.constant 0 : index 401e1b9d805SAart Bik %c1 = arith.constant 1 : index 402e1b9d805SAart Bik %d0 = tensor.dim %arga, %c0 : tensor<?x?xf32, #DCSR> 403e1b9d805SAart Bik %d1 = tensor.dim %argb, %c1 : tensor<?x?xf32, #DCSR> 404c6472f57SAart Bik %cinit = tensor.empty(%d0, %d1) : tensor<?x?xf32, #DCSR> 405e1b9d805SAart Bik %0 = linalg.generic #trait_matmat 406e1b9d805SAart Bik ins(%arga, %argb: tensor<?x?xf32, #DCSR>, 407e1b9d805SAart Bik tensor<?x?xf32, #DCSR>) 408e1b9d805SAart Bik outs(%cinit: tensor<?x?xf32, #DCSR>) { 409e1b9d805SAart Bik ^bb(%a: f32, %b: f32, %c: f32): 410e1b9d805SAart Bik %1 = arith.mulf %a, %b : f32 411e1b9d805SAart Bik %2 = arith.addf %c, %1 : f32 412e1b9d805SAart Bik linalg.yield %2 : f32 413e1b9d805SAart Bik } -> tensor<?x?xf32, #DCSR> 414e1b9d805SAart Bik return %0 : tensor<?x?xf32, #DCSR> 415e1b9d805SAart Bik} 416