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

    <tr>
        <th>Summary</th>
        <td>
            [X86] Use X86ISD::BSF/BSR fall through operands to be used for general values
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            backend:X86
      </td>
    </tr>

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

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

<pre>
    Followup to #123623 which added a fall through operand to X86ISD::BSF/BSR nodes to handle 'src is zero' behavior on supported CPUs.

We can use the fall through for other cases than the bitwidth constant values which we currently handle.

There are a couple of gotchas to address:

- [ ] Must still be limited to CPUs that support fall through on BSF/BSR instructions
- [ ] The "REP BSF" -> TZCNT performance hack in X86MCInstLower::Lower will need adjusting to only work for undef / correct constants
- [ ] Additional tests (both for constant and variable fall through values) will be necessary as we can't guarantee that 32-bit BSR/BSF instructions correctly zero the upper 32-bits of a register
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJx0U1-P2jgQ_zTmZQQKDgHykAfYLVJ111O1bHXVvU3sIXbX2JE9BnGf_uRAW211fYgSKfPn92d-mJIdPFEnmr1onmeY2YTYvfxxtOfgZ33Qt-4QnAvXPAIHELJeynota7gaqwyg1qQB4YTOAZsY8mAgjBTR61L_dbv-eHwW9U7Uu_3xIORhf3wBHzSl8tug145AyE2KCmyCfykGITfQk8GLDRGCh5THMUQmDU-fv6SFqHai2v1NoNBDTgRs6P3-U-ljQxEUprLIoJ-qestXq9mACj4xeoYLukzpQeZKoHKM5NndHtAe214NRQIsD6iQR0cQTjAEVgYnIqh1pJQK0alhDqLZg2ie4VNODImtc9ATOHu2hQmHiUyBxt8J_iKih5-CWZ84ZsU2-PRu-qsp6smXD5_v1RLmov4Ar_88_fUKI8VTiGf0isCgegPriyGfnj76xH-GK8W7MdMnXAtET8VO_S0ntn4oMIN3N7iG-DbJmr2mEwh5ABViJMU_pHyPa6e1LWjRAVPiBEJu-8B3b36oX47kgtFi736x8O6LkO0dVk_gSVFKGG-AaXIKvZAbhiFjRM9Edy1rOe8tw_74Mkl3eCfdd9DuNh3adBN5HCk-2lJxFSHSYBNTnOmu1m3d4oy65abeNE1VrVcz061ku91uthr7dd-2Sjf1qe2rBus1Em6q1cx2spJNtZRyKVeb1Wqh1Wm93a4lqiW2p0qJVUVntG7h3OW8CHGY2ZQydUtZt_V25rAnl6ZQStmjeiOvRb37ul0LKUtOY1ca530eklhVziZOP0exZTclutQ3z_Al0W-C-H-xne65pxItPdk1kKeI7uHJLEfXGeZxOnZZJg2WTe4XKpyFPBQUj9d8jOEbKRbyMLFLQh4eBC-d_C8AAP__DZh7ng">