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

    <tr>
        <th>Summary</th>
        <td>
            [InstCombine] Missing fold for 'and' pattern with multiple used 'xor'
        </td>
    </tr>

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

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

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

<pre>
    Hi All,

I noticed that there is a pattern of `and(xor(sext(A), -1), B)` that is not being matched if
the `xor` has multiple uses.
In previous version of clang this pattern was matched to select instruction
as you can see here :
https://godbolt.org/z/M9oG6sa1q

>From what I investigated I think that the check that was added in the patch https://reviews.llvm.org/rGf0071d43e4d30a0bc224020abb52fa77054d2520 
might caused this mismatch because `xor(sext(A), -1)` can't transform into `sext(xor(A, -1))`
and this caused us to mismatch the pattern :
`and(sext(A), B) -> select A, B, 0`
which was matched in the previous version of Clang.

@rotateright , Do you maybe have insight about this ?

Thanks very much,
Barak
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx0VE134ygQ_DXo0i9-CH3FBx0cZzWbw9z2DyDRFmwQeKFlT_bX7wMrHmfezsUYUHdXV1UjYzSzQ-xZ88Ka10KupH3oRxnk-2xlMXr10f9p4GAtE0fGXxk_3H7fwHkyEyogLQlIY0AwESScJREGB_4ErOXSKSaef_jAxHPEH8TE84GJPRNHeCq3Py9pbfktk4kpM4xo3AyLpEmjAnO6VSWNKWlK13LQMsKyWjJni7BGjLsNm4NzwIvxa4QLhmh8RjNZ6WYgbeId4zVl2GqQh4gWJwLjIoV1IuPdLaGM8OFXmKSDiAi5V1ZtTGiic0w7MTAxzF6N3tLOh5mJ4V8mhu97_62Nsvznkb4h-AWuqd83MO6CkcwsCRW8JYDu_c4qTBqnbZvQSqUSHy7fnRN0-AogNY7XuLP2smwowrcT512p6gprVXHJx0mImgsux7ERJ9l1vKmVaASHG7rFzJpgkmvM-poIi4mZJxgxH3-q8BtRW57IYqIjoCBdPPmwgHHkU9wWcQs_PDghxW2Eu63uhmGNSZ47iK33LOFdh7vZfkGU3AVPrPrjU97DdnoEfi941WbSX-zwSfH_GOmYjLR7lJPVPHiShCEzl3K_-uyZRX6MCFpeMNkq38rRr3Rrj1XDY5q_tHTvudQHLOuk7zP3kgayUH2l9tVeFtiXbSeaZ9G2daF73ijV1hXyclJNO55Kria-F7ytJlXVe1GYXnBR8ZKXZV12db2rEet25GVTlmJfiprVHBdp7N01hYlxxb7Zd11VWDmijfmNEMLhFfIlEyI9GaFPMU_jOkdWc2si_fReQYZsflzeXKSjX0bjkDWv8N3EmOb75K2Ckw_ARJfF636OpiH9ZbpV-iibpivWYPtf5s6QXsfd5BcmhlR_W57Owf-NEzExZNSRiSF39V8AAAD__06bkGI">