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

    <tr>
        <th>Summary</th>
        <td>
            [x86-64 BMI2] Missed BLSR emit when AND is factored out of ternary conditional
        </td>
    </tr>

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

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

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

<pre>
    [Godbolt link](https://c.godbo.lt/#z:OYLghAFBqd5QCxAYwPYBMCmBRdBLAF1QCcAaPECAMzwBtMA7AQwFtMQByARg9KtQYEAysib0QXACx8BBAKoBnTAAUAHpwAMvAFYTStJg1AB9U8lJL6yAngGVG6AMKpaAVxYM9DgDJ4GmADl3ACNMYhAAdlIAB1QFQlsGZzcPPVj4mwFffyCWUPCoy0xrRKECJmICZPdPLgtMK0yGMoqCbMCQsL0Fcsrq1Lqe1vbc/IkASgtUV2Jkdg4AUgAmAGY/ZDcsAGoFlcce/EEAOgRd7AWNAEELy9c/AgA2SWMCLeDaBWIXzB7jZBZUAA3TAQO6CJ4vLbEfCkLZgx7PV7EeLjHYRABCNy22Lh9whSKYqh2KwAIlD8Dslg8thBoXgtgBaLZcca7TFXHFQzAEGYMGnI%2BlgMC7MkaVG7ABiUMJWxA5LwbJuCwiJJuHEmtE4AFZeJ4OFpSKhOI4tgpprNMJSVjxSARNOrJgBrEBajT6TiSXX2w2cXgKEBuu369WkOCwGCIFCoFjROhhciUNAxuPhZAbQzAF7EVwMR18OgEML%2BiDBb3BPwVACenBt5eYxErAHlgtpikGbUm2IJGwxaNXg6QsMFXMBHGIPjXeFgWBnxAP8MQ23hgf6B5hVMVXIXJ%2BRBA1vbQ8MFiFXnFhvQRiHgWDvgcRgnFMCTMDOjIejPbJlQDMAFAA1PBMAAd0baJGB3fhBBEMR2CkGRBEUFR1AHXQln0DMQFMP59CPf1IEmVBoiaVcGUbFZGRnWZTlJAAvBg7x1Q07yvLA8IgSYihKOwIAcfpajQnw/A6PIuiidIEgEPiJDQ8SmhGToCnqRpSl6KoXBqboGiXAQWkqeSRPCQZVKkozhiE0YuhZKYZjmCZ3Q4Ri9QNI0OC2VQAA4HgZJ4tnTIwaUvHNHVRCBcEIEgrRZXggy0cZJgQTAmCwcJ2NIZ1XXsz1SBvDKnN4Fy/QDW1P1DCMICQJNY3oMgKAgSqUxQX9mGiBQEFQAh81oQtkUoUsBzrKsdwGhtm1bawd07RgCB7PtvSHEcx1oCduCnF9Z3mA0FyXFdvXXTdtxW3dC01AdD2PU8MA26KrxvQ67wfJRn1fYB31AYMvx/f9AJAsC9RtSDhFEcQ4IBxC1G9XQ6gMD8sPMM62IIojEhIsiKIqZBqJJOiGPy5i8FY%2BAOK0rjPB4hgnHUgYBPJ/SxgeGI4gkpJKf4hmMkSWmunpziml0tSUlqJTtOaVTOcMixjJZ7pRfMhS7LNGzYI1bUvQHFy3M87zJC2YA0wC7NcxCsKiGISLxmiz94sS5LKGVjgspyt08p9DhCsDS20pdN0TpWVXnN9Yr3rtpZeBvLgNCd70CsD2LJjveI7EkIA)
```c
#include <stdint.h>

uint64_t blsr_test_cmove(uint64_t rdi, uint64_t rsi) {
 uint64_t rax = rdi & (rdi - 1);
    return (rsi != 0) ? rax : rdi;
}
```

Emits:

```asm
blsr_test_cmove:
        cmp     rsi, 1
 lea     rcx, [rdi - 1]
        sbb     rax, rax
        or      rax, rcx
        and     rax, rdi
        ret
```

Should be:

```asm
blsr_test_cmove:
        blsr    rax, rdi
        test rsi, rsi
        cmove   rax, rdi
        ret
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJycVlmvqkwW_TWcF3JPoECBh_NQVQyCogwOwMsXJotSBoVS0F_f0Xu_757bnU46bUy2u9Zam7VMJex0GChpy_KLmyFupn-kN1Z1_dc-rWmR9uePrCseL8zqiqyrGV_T9szNdA6oFWOXgZMgB0wOmPkne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