<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/58338>58338</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Redundant movzx instructions when operating on i8s
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
krdln
</td>
</tr>
</table>
<pre>
When casting argument from i8 to i32, codegen doesn't seem to leverage the fact that the rest of `edi` is zeroed, emitting `movzx eax, dil` ([playground]). Gcc in similar case [emits simply `mov eax, edi`][gcc].
In the [playground] there's one more case (`ternary_and`), roughly `x < 3 ? 0 : x & 2`, where two redundant cmovx are emitted. (They're redundant, as high bits of eax are already zeroed). The real world case I initially noticed this behaviour was using `sub nuw` instead of `and`. Here also high bits of eax should be zeroed (although `opt` turns this `sub nuw` into `add`, losing `nuw` annotation).
Perhaps related: https://github.com/llvm/llvm-project/issues/56498
[playground]: https://alive2.llvm.org/ce/z/Hi9yux
[gcc]: https://gcc.godbolt.org/z/ndGK8c3MG
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJylU01vnDAQ_TVwGRWxZpeFA4d8aJOoqlRVkXqsjD0Lbo29ss1-5Nd3DGQTJb1VAmPs8Xtv3oxbKy_Nzx4NCO6DMh1w140DmgB7ZwdQFQQLqmAJuwNhJXYUKi16k7BtAI84xACNR3S8Qwg9wp6LQBMepj-HPoDdQ1LmKBWNoDy8oLMoIyYOKky8tDPY48sZkJ_jhlQ6BiesSja3B80vnbOjkcnmPmF1Bg9CgDLg1aA0d1E9AgVGOB9XD_qyQL4Czuzx_Oa2E4ImWZLfJ_nNPD6ZSe5HsrjokJL1YA3CYB0uZCSszAM6w93lF6dgAmd1ZKKzXT_znyEp7qCgcQeUTHEDtMJKYFP0HZwiOoSTJZ8kMXIyXpDoM9UBZ3NQZpHsuccLyXD4FhkBuIdedT20MW-ymZKdjnLtkMvL1Wmy7HmqBtdwsk7LOYsnMlEFxTXJNTYogZIypgq12POjsqODE1GMfimRH1sw42kqo_GBKJbazgZk8IgTubefZfnejsTb4iIqZsV16KNbEcIeQsQNozN-FvGRkDotUkm5uKftq64lhBtKggdlTcz4fXm_o-v5wZMBmpOlsRJ9CAdPk4Tt6OlU6Mc2E3agH62Pr58vB2d_oyCzd8r7ET1NNuW6rt6jf2rRT_BcqyOyLCJm1nW0Iqirdi_0Pqr6Mp6vQHNv_kOgEFlnZWt1WBDiYSMfvlai-PaQYrMqy025Yau8TmVTyLqoeRpU0Nj8uDbXfMdi7dwoolE-9qABe6ALPF1Ea-jW-3R0uvkPh6qiqNK-qfd7Xm2LKq-KCrcrVlbYSpnvcc1buarrVPMWtW8o74QxgyeYIGhOHqSqYTmjfFZFXucVqzK-Riw2dIRv2RrLdbLOceBKX31NXTNJasfO06ZWPvi3Te696gziREf4fKTuc80fJ7VJJ-JmEv4XD1uiIg">