<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/64599>64599</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[x86] Suboptimal expansion of `icmp` on `i1`
</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/rPsqjTezr
```c
bool lt(bool a, bool b) { return a < b; }
bool le(bool a, bool b) { return a <= b; }
bool gt(bool a, bool b) { return a > b; }
bool ge(bool a, bool b) { return a >= b; }
bool eq(bool a, bool b) { return a == b; }
bool ne(bool a, bool b) { return a != b; }
```
clang output:
```
lt: # @lt
mov eax, edi
not al
and al, sil
ret
le: # @le
mov eax, edi
xor al, 1
or al, sil
ret
gt: # @gt
mov eax, esi
not al
and al, dil
ret
ge: # @ge
mov eax, esi
xor al, 1
or al, dil
ret
eq: # @eq
mov eax, edi
xor eax, esi
xor al, 1
ret
ne: # @ne
mov eax, edi
xor eax, esi
ret
```
GCC output:
```
lt:
cmp dil, sil
setb al
ret
le:
cmp sil, dil
setnb al
ret
gt:
cmp sil, dil
setb al
ret
ge:
cmp dil, sil
setnb al
ret
eq:
cmp dil, sil
sete al
ret
ne:
mov eax, esi
xor eax, edi
ret
```
GCC's output is both smaller (one byte less for each function) and, according to LLVM-MCA, faster than clang's.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJycVk1v6joQ_TWTjQVKnA_CIgsK5S1eKz3pXV3dre1MglvHhtipaH_9VUJKoRCa1kI48TDnnLFnzDBrZakRM4jvIF55rHEbU2f_Vsiepfa4yV-zjXNbC-EC6BroujQ5N8pNTV0CXb8BXdf_2d3TL3yrwV-Bv-i_E__wEYd3bowiygFNuycGdEm6Jw50TmB2R2p0Ta0JIxAuCYfwjsBsdeqMI50hXF3zL0eS3191Hkl-P0COu3H-qwF_PY6fBpf-x5M4PR6hmC6Jady2ce3RXvulai1kzAAaEoh85Q6OpDIv3TqyfasWc9kb-qGN62amzteZzt_X6ZJY-W6usUdW-F1JeM7wlbK9qU8UBOfG3nYhrx9HlWW3cb2C0t1WYN8VjNuUfJgVT1m_iNv-PO5hBbg7UYC7n-38hcKb0o7c-ruZoX-YGRf6jhKuFto_y-WYMjvnEtW2m9utPss0i45fy5HzArkOZuWn47PoNL8FVg4ruwDrRydwGHBY3UWoH4D6BmKXct9GxGFAfSlxbO0MZc6XCQJ0ZvskIdISbtyG2IophTUBmhqNhL86JAqtJYWpCTKxIUWjhZNGt_8CTOctNRPC1LnUJXGGPDz8fpw8LhetoWDWYU3chmnSXf0t5dTLszCfh3PmYRYk8yCZpeks9TZZwaLAT-J4RjEMOGc0SkQRFbwIi7nPROrJjPo09NPAD6JoFqfTMGaxnxSiSAQVUULbC6BiUk2VeqnaXsGT1jaYJVE8n3uKcVS26zko5Uw8o84hXPxJE6AU6BIoraS1mE_M1slKvrFDoLRtUeqsxZzwprTtBS-tsx8sTjrVNTP7NIF4Rf5veAfBFMH9lmkrjSamIJD4UlRbSHxidPcWQOJ7Ta0-tzvSbRo-FaYCum5p-mmyrc0TCgd03UVmga674P4GAAD__7juarg">