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

    <tr>
        <th>Summary</th>
        <td>
            [InstCombine] Should we canonicalize max(min(x, C1), C2) to min(max(x, C2), C1)
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

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

<pre>
    
We have some common pattern like max(min(x, -128),127) to quantize a value to int8_t in AI.
And these two patterns should be the same: max(min(x, -128),127), min(max(x, -128), 127)
Maybe we can add a pattern for it?

https://alive2.llvm.org/ce/z/WjmAjz

</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyEkj9v2zAQxT_NaTnEIE-iJQ0aVAcCMnTqkLGgpItFl39ckbITf_pCtuuizdCJwL1H3t37Ucdo9p65AfUF1HOmlzSFuekHq-pKZH0YPxoQ7SvjpE-MMTjGITgXPB51Sjx7tOYHo9PvQJUzHqh6B9rhk6QKqAbaSSqBakwBfy7aJ3Nh1HjSduG1Znyqvic0HtuXDYi29SOmiSNjOoffPSLGKSx2xJ5XEaN2DHn7_65r7SbfrP-Y8O4S7Vf90TOeGQftUY8j6sd-b2FGkyDvQLQg2imlY4S8BeqAOm3NiWlj7cltwrwH6gYG6i5A3evBtYcLiDYbm3ys81pn3Mgy35JUqsqzqSlKMVRKyUKpolDlqJmqvCrqUo_DdhzqzDQkSAkpSkFiS_lGvhW5UNtcb-Ugy7caCsFOG_sYIDMxLtxIklUpMqt7tvHKlsjzGa8qEK2o52a99NQv-wiFsCam-OeZZJK9fooXH9MuuN54BvWM324cbkEFbwZtV6CfQOzkPeEd3eF_wnBVHt5smW3zd7Z7k6al3wzBAXXrZPfj6TiHAw8JqLvuE4G6-8Knhn4FAAD__y0W2U4">