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

    <tr>
        <th>Summary</th>
        <td>
            [Optimisations] [X86] Storing an `i4 zeroext` into an `i8` then loading that `i8` still creates code to store the `i8` even when not used
        </td>
    </tr>

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

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

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

<pre>
    C code:

```c
bool f(const unsigned _BitInt(4) x) {
  return __builtin_bit_cast(unsigned char, x) == 3;
}
```

Output https://godbolt.org/z/xPjWsYYPj: (x86-64)

```asm
f:                                      # @f
 mov     byte ptr [rsp - 1], dil
        cmp     dil, 3
        sete al
        ret
```

With an unused store on the stack.

And since the parameter is an `i4 noundef zeroext` (i.e., it has 4 padding bits that are all 0), it should also be able to optimize:

```c
bool f(const unsigned _BitInt(4) x) {
  return __builtin_bit_cast(unsigned char, x) == 0b01110000;
}
```

... to become `return false`, but it becomes:

```asm
f: # @f
        mov     byte ptr [rsp - 1], dil
 cmp     dil, 112
        sete    al
        ret
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMlM1u4zYQx5-GugwiUNSHrYMOSQwDPRS7QA_bPRmkOLKYpUiBHGWzefqCkuNmjW2R3koYks358MwfvxkZozk7xI7VD6w-ZHKh0Yfud0PS3sfRf8uU1z-6R-i9RlbeM35g_O3Z8O3Tb7-V9xYGJva9d5FgcWtqDacHQ785YmJfMdHCS3qw3cMWBBCQluDgdFKLsWTcSRk69TKmgGuOfpSBicdLcHlg5QFKVl6SsN3hpqT3dX5aaF4IRqI5phbEkYnj2WvlLeU-nJk4vjJxfPn89CV-_fr5iZX3wMT-Zd_cNaniX_Ys47TdDMn9Q4eJEljFh0vjk39er9UPQpgpAKsfQpzhDgpWH1Kz2tg3kbbTT_P6TgbxCOXP1oiEIG9CAtK_SPPF0AjSweKWiBoi-YDgHdCIEEn23_L33vdOQzSux9U-yyAnJAxgYsrBGm4qcH5xGgd4xeDxhVjDk5YmxzxVbAhGGaGCWWpt3BmUoQg0SgIZUvEWeFJ8c42jX6wGaaMHhSCVRSAPfiYzmdf_G45c8aIoOOf8g1zmeZ7aUdj7CZN8l78epI2YfMUjqIWSEptP_KeOf4bxhrPL-S-43XBWFOIXpAF8ALZMd6Vuy1Zm2BW7ot01u6ousrGTbaP3g5Zl2w611qrdDW2BjWwF7tWgRWY6wUXFm5IXu4LXRY510zYl1zWv-6LiglUcJ2lsbu3zlOY4MzEu2LU7IarMSoU2rmtNCIffYTUyIdKWC12KuVPLObKKWxMp_p2FDNl1H35aOYuSjHeR1Yek2J_7Jn37g3xI-F6xf4e7ceTfDPt0QSM6sF6uwK-sX02RjLXQB5SEcd2xiYhtDNOMXR3xGR18T4mcJ0jDmi3Bdjc7zdC4qLz3ExPH1M_ldTcH_4Q9MXFcVYhMHDeVnjvxVwAAAP__Eimzsg">