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

    <tr>
        <th>Summary</th>
        <td>
            [MLIR] `getRegisteredOperationsByDialect` comparator lambdas return int instead of bool, causing incorrect operation filtering
        </td>
    </tr>

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

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

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

<pre>
    The implementation of `MLIRContext::getRegisteredOperationsByDialect` uses std::lower_bound and std::upper_bound with comparator lambdas that return the result of StringRef::compare() directly (an int), instead of a boolean. Since these standard algorithms require comparators returning bool representing a strict weak ordering, returning an int causes undefined behavior and leads to incorrect or empty results when filtering operations by dialect.

Proposed fix:
```
// lower_bound comparator
[](const RegisteredOperationName &lhs, StringRef dialectName) {
  return lhs.getDialect().getNamespace() < dialectName;
}

// upper_bound comparator
[](StringRef dialectName, const RegisteredOperationName &rhs) {
  return dialectName < rhs.getDialect().getNamespace();
}
```

</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyMVF2L6zYQ_TXyy3CDrCRO_OCH7C6BQr_Yu-9Flsa2WllyNePszb8vcpJNLt3SC4GARzo6c86Z0USuD4iN2D6J7UuhZx5iatKkTz6enHl7K9poz83bgODGyeOIgTW7GCB2ICr5y88_vT7HwPiNxfog1oce-RV7R4wJ7W8TpuU0PZ1fnPZoWFQSZkICYnu54eM7pj_aOAcLOth7YZ6mj8K74wFMHCedNMcEXo-t1QQ8aIaEPKcAPCAkpNlzJveVkwv9K3YXsMtdFGovVA3WJTTszyDUXgdwgYWqhXoGF4hR2wygoY3Row4r-OqCwYxPCMQ6WJ0saN_H5HgYCRL-PbuEDwTpSsqFfoGBhFNCwsD5iwbi5AzDO-q_ICaLmWt-_37rQguMXtSag8XOBbTQ4qBPLqZFK4_aEnAEF0xMuSeICXCc-HyVguB9wACd87w8AvHDE2jPYC-urIQ8CHn4PcUpElro3LcsmzyISl5_8iDUUagjPPp1bzjXlwwJtTcxEMMnMfhVjwhCVX6g3OyHRTcauZ7tEbsnIQ9wM9YPtOqRbwlaLMwf8nGatLm5KtbP3yGtM4rYvVyau9J_TNXn9P-D1jP8b18p9_Uv-g8oC8X0Y-18R__BhsI2a1uva11gU-625baqd9uqGBqjjalaXe7LsttUppO6rFuLu7q11X5d2cI1Sqqt3Ml1Wcu6rFZSGtnuu11Zb9tuV6HYSBy18yvvT-Mqpr5wRDM25aaqN7LwukVPy65QavQuCaXy1khNPv-lnXsSG-kdMd0R2LFf9kteFWL7krfGjyyJT4b9qmcei4c5zeO1uKNnygF_GIUb8j3-xZx8MzBPlPO9JKJ3PMztysRRqGOmff37MqX452LQcVGBhDpehTg16p8AAAD__7Bxwi4">