<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/91569>91569</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[AggressiveInstCombine] Missed optimization: a reversed chain of contiguous unsigned icmps could be merged
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
FLZ101
</td>
</tr>
</table>
<pre>
Assuming the machine is little-endian, a reversed chain of contiguous unsigned icmps could be merged. For example,
```c
struct Foo {
unsigned short n;
unsigned char o;
unsigned char p;
};
int compare(struct Foo *f1, struct Foo *f2) {
if (f1->p > f2->p)
return 1;
if (f1->p < f2->p)
return -1;
if (f1->o > f2->o)
return 1;
if (f1->o < f2->o)
return -1;
if (f1->n > f2->n)
return 1;
if (f1->n < f2->n)
return -1;
return 0;
}
```
the function `compare()` could be transformed as below,
```c
int compare(struct Foo *f1, struct Foo *f2) {
unsigned int a = *(unsigned int *)&(f1->n);
unsigned int b = *(unsigned int *)&(f2->n);
return a > b ? 1 : a < b ? -1 : 0;
}
```
This kind of pattern is found in [velvet](https://github.com/dzerbino/velvet/tree/master) (a de novo genome assembler), more specificly the hot function `compareKmers()`.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJykVUGP6jYQ_jXDZQRyJgSSQw4svEhV21tPvTnJJHEb25Ht8Prer68c6AK7aLXVSijEM_7mG_v7GKT3qjfMJWQvkJ1Wcg6DdWX125-JSFa1bX-UB-9nrUyPYWDUshmUYVQeRxXCyGs2rZIG6IgSHZ_ZeW6xGaQyaDtsrAmqn-3scTYLVYuq0ZPHxs5jizWjZtdzu8HKOuR_pJ5GjtVAnEAcrs-duHyay9oHNzcBK2sR9i-XGN4I_GBdQAPp-1QzSIf2lnlMTK8J2J9u78tTmYCN1ZN0DJTfd0CHLokdv4kRUHHXnuoQKO-SNaTfJoT0G3a0vAMV_7WJjsPsDCa3Bt_Cjh_A1smbnvEBbu9Y7T38Ce074PE98HOs5o7V_B9Wc8f6FPiE-JoRDzo-WugeEB3dzaYJyhqM9nrVN_LtxM2kwUnjO-s0tyg91jza70DHj0z6VcPc_WBMQImQnuI2oPwhsYQKoN3t4uL6iffj7vpTZehJmevVykXOWKbCBCE9LJHjNYLrS-yzAvwxKI9_K9PGWTHJENiZOFs6O5vYF0L2cubxzAGyE1A-hDB5SA9AFVDVqzDM9aaxGqhqf7KrlbFA1RVBVXDMQJWWPrBbbpdyiS2jsWeLPRurGaX3rOtx2RBV0dYx-okb1alm_LGMvcGGZ0b5VbPzr27ZXM60asu0LdJCrrhM9klGW8opWQ1ll7UkuJFZnjNtBSVCZLXM23y_F7LeNitVkqCtyEQhchKUbHbdvmBZp1m2E227q2ErWEs1bsbxrDfW9Svl_cxlkWS7YjXKmke_THIiw99xSQJRHOyujJh1PfcetmJUPvhblaDCuPwFHPresffqzL8YH45W18owZCf8Xfk41-0UlFY_ZbyHi_ZfGPmr2Y3lB4rG9q5f68nZv7iJmi6H8kDVcuh_AwAA__-no_S_">