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

    <tr>
        <th>Summary</th>
        <td>
            [InstCombine][SDAG] Add range attributes to shamts on fshl/fshr in `matchFunnelShift`
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            llvm:instcombine,
            missed-optimization,
            llvm:SelectionDAG
      </td>
    </tr>

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

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

<pre>
    In https://reviews.llvm.org/D88783, we fold `or(shl(a,x),lshr(b,sub(bw,x))) -> fshl(a,b,x)` iff `x < bw`. This constraint on shamts is added to avoid redundant `and x, 2^bw - 1` in the codegen. However, this may increase the complexity of ISel and produce inefficient code. See an example from https://github.com/cyyself/hwprobe/blob/master/ifunc_example/ror32.c: https://godbolt.org/z/fxEb1f65h.

To address this issue, we can add attribute `range(iN 0, N)` to the shamt in InstCombine. Then we use `assertzext` in `SelectionDAGBuilder` to   eliminate unnecessary and insts.

Looking forward to your inputs.
cc @nikic @topperc @RKSimon @asb @preames @cyyself 

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx8lE2PozgQhn9NcSklAhMIOXBIJ81ua1dz2Mx95Y8ieMfYyDb56F-_Ms32jPqwUiRKqfJL-Xmr4CHoqyVqoXqB6pzxOQ7OtyrKx_vzngmnnu2bxSHGKUB5BNYB6zzdNN3D1pjbuHX-Cqw7N82-KYGd8E7YO6MQ6tx5YE0YDLCGAzs9gB2AnUwY0v8C2CnMIkX3z2T64QbKV-x_nhP_pescdd8n5QdCeUJxhzrf4vdBB5TOhui5thGdxTDwMQbUAblSpDA65DenFXpSs1XcxqTCrcJH6plB9SruuMFieYfFOBBKp-hKdou_uzvdyKfCmF418idqKz3xQGvlOBl66PhE1-PbhQwm6ck7NUtCbanvtdRk4yK6xQsRcov04Okg9t6NXxBfdRxmsZVuBNbJ5zOQ6YF1w33yThCwThgngHUjDzG11ul-tvLvVTF55HzJthLK41dlp4QzcfXtHVjXP15F0dfVsIX8CPnxu0vUPIXwcV8dwkyrtZLblEQeo9dijpQ4em6vBKzR3zBPdd9Ws6Jb8CxmJKpvNsSTG4W2lFwjmxTnsGjwEMjHd3rE1QKo8wsZklE7ez7-9jJro8ivsohk9Kgtj4SztSQpBO6fC3ZtQwzrVf507oe2V-ydv3O_zMHTzR61neaPIikRdrnVP_QSRDdN5Jfwrz8uenQ2hTyI9Jg88ZFCCldLEPJjptpSHcoDz6gt9mWZ78qK1dnQlrJuml2_z2VdSkGHnpfNYc_3ku_ynSxEpluWs13B8iJvqmZXb6VUQuyrWhT7viwaAbucRq7N56ZlixdtUTQszzPDBZmwrC5jqQTKY7q9_GAMjAE7AWOjDoHUxk1Rj_qdJ6KfufXYr6hTrjpnvk25jZivAXa50YnqZx9RR7N8NH7xFKozVC-XpFCd8agULoPxc1ZC4r-uprPrind9GPxq-MijHLpkqLkMuk-jkM3etP-zG0v_H4_N5N0_JGPahoQpAOtWUreW_RsAAP__yxeVYg">