<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/66664>66664</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            MLIR Sparsifier sorts unordered COO in a wrong order.
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            mlir:sparse
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
            bixia1,
            PeimingLiu,
            aartbik
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          PeimingLiu
      </td>
    </tr>
</table>

<pre>
    To reproduce, simply apply the attached patch and run test `sparse_rewrite_sort_coo.mlir`.


The patch to apply:
```
diff --git a/mlir/test/Integration/Dialect/SparseTensor/CPU/sparse_rewrite_sort_coo.mlir b/mlir/test/Integration/Dialect/SparseTensor/CPU/sparse_rewrite_sort_coo.mlir
index c3bdc30e355b..7e03451f1b8e 100644
--- a/mlir/test/Integration/Dialect/SparseTensor/CPU/sparse_rewrite_sort_coo.mlir
+++ b/mlir/test/Integration/Dialect/SparseTensor/CPU/sparse_rewrite_sort_coo.mlir
@@ -99,9 +99,9 @@ module {
     // CHECK: ( 9, 9, 4, 7, 2 )
     // CHECK: ( 7, 8, 10, 9, 6 )
     // CHECK: ( 7, 4, 7, 9, 5 )
-    call @storeValuesToStrided(%x0, %c10, %c2, %c1, %c5, %c1)
+    call @storeValuesToStrided(%x1, %c10, %c2, %c1, %c5, %c1)
       : (memref<?xi32, strided<[4], offset: ?>>, i32, i32, i32, i32, i32) -> ()
- call @storeValuesToStrided(%x1, %c1, %c1, %c3, %c10, %c3)
+    call @storeValuesToStrided(%x0, %c1, %c1, %c3, %c10, %c3)
       : (memref<?xi32, strided<[4], offset: ?>>, i32, i32, i32, i32, i32) -> ()
 call @storeValuesToStrided(%x2, %c2, %c4, %c9, %c7, %c9)
       : (memref<?xi32, strided<[4], offset: ?>>, i32, i32, i32, i32, i32) -> ()
@@ -127,9 +127,9 @@ module {
     // CHECK: ( 9, 9, 4, 7, 2 )
     // CHECK: ( 8, 7, 10, 9, 6 )
     // CHECK: ( 4, 7, 7, 9, 5 )
-    call @storeValuesToStrided(%x0, %c10, %c2, %c1, %c5, %c1)
+    call @storeValuesToStrided(%x1, %c10, %c2, %c1, %c5, %c1)
       : (memref<?xi32, strided<[4], offset: ?>>, i32, i32, i32, i32, i32) -> ()
- call @storeValuesToStrided(%x1, %c1, %c1, %c3, %c10, %c3)
+    call @storeValuesToStrided(%x0, %c1, %c1, %c3, %c10, %c3)
       : (memref<?xi32, strided<[4], offset: ?>>, i32, i32, i32, i32, i32) -> ()
 call @storeValuesToStrided(%x2, %c2, %c4, %c9, %c7, %c9)
       : (memref<?xi32, strided<[4], offset: ?>>, i32, i32, i32, i32, i32) -> ()
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsVtFvpLYT_muGFwtkxsDCAw9ZEvQ7_a66Uy_ta2Rg2HULeGWbXu6_rwzsbqSobS5Srn0IsoZhMjPfjLP69Elr1WEiKiHdA2KjHpWMARGwAsTPpEY1HT6q-RKS0rhG_e6_09tAzu6oTXnNCxrdfSvvNTN0MrqbWwKsmFXjafjG5MlbdyQmnZPtkTp2kq49Mjl1zMwTc2Qdg4zbkzSWHgx9NcrRg9XGPbRaR-OgDGQ8An4L_OapvT_S1svpFQfEOSHj21k-O9X3LAwPyjEJWC8tsfbIgPWHydHBSKf0BFjfKjlQ6-NfloHuabLaZ1effwGs_25K1rxd73UPNXX0yFrRdK3gJNK0iaIdcZGkcR83ObGY8yxJ1uQwDN9y2-2icb-et18eEg4JZ2FRAFYFA9yfvfUPo-7mgRjs9ms-8w9gDViz6n931f9B3DDAnPmq1STe7LxBBlj8Q92SmHsT80uL7KWFV6ylLr3Whb6ulcPgN7FOG_pVDjPZe_3FGdVRB5gDpo8LKGDaxhcPL6Gzkz6JFJf_0QsR4lcisPXZ9h1pNNSDqEDUj0osHeyGIypI9wmktz6o-96SW6pEDeLOH6zYVvLXr4KFIO7YMvTlDr9rvWeOeL65eMUF8lci_PsX-JLt8NmPIjk7xdnZPYn8Z5Y7U0eMuzN3XNwfRB75Jfs7yeMK804e7-TxTh4_njzOWjLoStEVopABlXFWpDwVcZEGxzJLmp0s8k4KzJM-I9HmqSyypk3Svqc2CVSJHAUv4jzOeCbSaMeTTnYc24KIx7sGEk6jVEM0DH-MkTaHQFk7U5llWZYEg2xosJtcXwSRuFn10ibJTenrwmY-WEj4oKyz105OuYHKnz5--Jktykv1igzzAsuyedKmI0Mdqz59Ympikn01ejqwJRwFsxnKo3Mn65X1Qk4H5Y5zE7V6BKw9xvYKT0b_tuq7ZXQLWC_T_xkAAP__OydQ4w">