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

    <tr>
        <th>Summary</th>
        <td>
            [x86] Opportunity to use shorter encoding for comparisons against powers of two
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            backend:X86,
            missed-optimization
      </td>
    </tr>

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

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

<pre>
    https://godbolt.org/z/hhbsf8she

For the expression `(x >> amt) != 0`, for values of `amt` between 8 and 31, LLVM emits a `cmp` against an immediate instead of a shift right and comparison. The compare against immediate instruction takes 7 bytes to encode; the shift right instruction takes 4 bytes

```asm
src:
        cmp rdi,0x7fffffff ; 48 81 ff ff ff ff 7f
        setae   al            ; 0f 97 c0
        ret                   ; c3

tgt:
        shr     rdi, 0x1f  ; 48 c1 ef 1f
        setne   al         ; 0f 95 c0
        ret ; c3
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJxkU81u8zgMfBr5QjTQT_yTgw_5ms-X7WIvi8VeZZmytbUtQ6LbtE-_kJM2aUsIMGzNkEN6qGN0_YxYs_wXy0-ZXmnwof5jQv3s5qz13Vs9EC2RqSOTDZNN77vWj7TzoWeyeWeyGYY22ioOyPiR8WPjA9CAgOclYIzOz8AKzmR1BqZ-M_Ub9ERMHoBJwdQJ-Hb7CNYHeNHjihG8TZQEKzi0SK-IM1Sg5w6USNinp3_-BJwcRdAJaqYlQXWv3RwJ9AxumrBzmhDSF9RdSqohDs4SBNcPtKUzflp0cNHPO_h7wOs7fmb6miashlI_pJ8xQgntG2EE8oCz8R0y9Wvr_L7IT9r-QrsMK_W-HR0nxo8xmDRofoRrmGmB0DkmH_m5tJeAVGdfQSXA2tsp7R0vImkEAD3CXSQit3AowfA7cECCn5HARl1kUk9fdcUhXKibNuBnYeFDlxGAFsQ3OfM3OR9a8p9abpU_ppN1teoO6qAzrEWpin0hhdhnQ614K3RV5lUuuLZGdUooK2xhSmUlL1TmasllzgU_SKlysd-VQpu2NQdd8Urmh5btOU7ajbtxfJmSqzMX44q1kFJVKht1i2Pc1kPKVptnnDumjv9WBZOSyUcm5eRixO7BL-Qm967Tr053-SkLdUr60K59ZHs-ukjxVoYcjdvenauC5Sf4a1l8oHV29JYstcZkJB8Iw8Vebu63HblZNn7adPGvGLa9oVefrWH8vrSOhrXdGT8x2SQF18fDEvx_aIjJZus6MtlcG3-p5f8BAAD__3BuPGg">