<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/117853>117853</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Missed optimization: per-byte comparisons are not always combined properly
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
purplesyringa
</td>
</tr>
</table>
<pre>
Reproducer: https://godbolt.org/z/6caGGoo1e
```c
int is_all_ones(unsigned char *p) {
unsigned char a = p[0];
unsigned char b = p[1];
return a == 255 && b == 255;
}
```
I've expected this to compile to a single read + comparison on platforms that support unaligned accesses. Instead, this happened:
```x86asm
is_all_ones:
movzx ecx, byte ptr [rdi + 1]
and cl, byte ptr [rdi]
xor eax, eax
cmp cl, -1
sete al
ret
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJxsU8GOozAM_RpzsVpBKFAOHNqtOprDXvYHRoa4JauQREnotPP1K6DatruDIhnZz8_2k00hqLNhbqDYQ3FIaIy99Y0bvdMcbl6ZMyWtlbfmFztv5dixh3yHfYwuQL4DcQRxPFvZWh3X1p9BHL9AHMuO3t6szRjS3fTKdHkdpDtlIqrwQVp_WMMBxHY0cxcSu548gtg5EDVCtYd0h4j4GieE_IAOin0KxQHy71HtX1T2gvIcR28WkgkhigJBlCDKJeXuWxKgOjx3vwzzDqK6MPLVcRdZYuxVwGixs4NTmqdfwqDMWTN6Jokg9nOQvArWoDXoNMWT9UPA2FPEMDpnfcTRkF5GoK7jEDis8d2EyCRB_FgK9eQcG5aT-K_aXrclhWES-EncGYX3b7CXrysicned-NpbZHTRIxR7L9Xc5yzWI4OMnG2nv0l4hV6tny3TTD6ZR7Ab3J1jlT25A0eey-gnp-f4v-iJbHJZ5zUl3GRVLsp6U5d10jei3tCpIJmR2BanNqe0lCRqUbR1seUyT1QjUrHJMlGl27QW9fpUVZ2syhPX-UaeNlvYpDyQ0mutL8O0w4kKYeQmy6ptkSeaWtZhPhAhDH_iHAUhpnvxzZS0asdzgE2qVYjhQRNV1Nz8VCGwROuiGtQXRWXNdEGO_WrW87EZAckzGhuR9CfdwhRq1bQOzlvHXt-S0evmn9tTsR_bdWcHEMep9N2snLe_uYsgjnPDAcTxPtGlEX8CAAD__3tiMSc">