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

    <tr>
        <th>Summary</th>
        <td>
            [X86] `and`/`or` could use 8-bit immediate for more constant arguments
        </td>
    </tr>

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

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

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

<pre>
    The functions:
```c
void f1(long* dst, long x) {
    *dst = x | 200;
}
void f2(long* dst, long x) {
    *dst = x & -200;
}
```
for x86-64 with `-O3` (or even `-Oz`) compile to:
```asm
or rsi, 0xc8               ; 48 81 ce c8 00 00 00
and    rsi, 0xffffffffffffff38 ; 48 81 e6 38 ff ff ff
```
whereas they could be:
```asm
or     sil, 0xc8 ; 40 80 ce c8
and    sil, 0x38 ; 40 80 e6 38
```
This applies to `|` for immediate arguments of 128..255, and for `&` with -256..-129. (`x & -256` can furthermore be `xor sil,sil`)

([uops.info](https://uops.info/table.html?search=and%20r%20i%208&cb_lat=on&cb_tp=on&cb_ports=on&cb_CON=on&cb_NHM=on&cb_SNB=on&cb_HSW=on&cb_SKX=on&cb_TGL=on&cb_ADLP=on&cb_BNL=on&cb_GLP=on&cb_ADLE=on&cb_ZENp=on&cb_ZEN2=on&cb_ZEN3=on&cb_ZEN4=on&cb_measurements=on&cb_base=on) says that the `(R8l, I8)` and `(R64, I32)` variants in question are largely equivalent)

</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJycVE-P47YP_TTMhYih0P-Ugw_OZLP7w286W3QH6KKXQrbpWIVtZSU5M7OfvpCTZpwBeqkgyHimSD2Rj1LO6ePIXEC6g3S_UpPvjC2an0oPalWZ5q147hjbaay9NqODuARRQiYuswZRno1usN0Ayd6MR6ASG-eBHjBAfAXaIuQ7ECUiIlDZOI8Q7_EVIX9AEgLiYIV8fwtG_yUY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