<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/55988>55988</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[InstCombine] optimize test for same-signed values
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
rotateright
</td>
</tr>
</table>
<pre>
The naive pattern for checking if 2 values have the same sign should be reduced:
```
define i1 @src(i32 %x, i32 %y) {
%a = and i32 %x, %y
%lt = icmp slt i32 %a, 0
%o = or i32 %x, %y
%gt = icmp sgt i32 %o, -1
%r = or i1 %lt, %gt
ret i1 %r
}
define i1 @tgt(i32 %x, i32 %y) {
%a = xor i32 %x, %y
%r = icmp sgt i32 %a, -1
ret i1 %r
}
```
https://alive2.llvm.org/ce/z/qXxEFP
This isn't matched in codegen either, so we get sub-optimal asm:
https://godbolt.org/z/aWf9c6j74
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyVVMFymzAQ_Rpx2bFHCGPwgUMS1zO99ZCZ9irEAkoFciXhOPn6rgh1nKSTTmcErKSnp7e7b6ht81Td9wij1CeEowwB3QitdaB6VD_12IFuQcBJmgk99JJQgfBeDvTS3Qi-t5NpoEZw2EwKG5bdML5n_IZt-TLmaYOtHhF0CmzDvVNMlDoTwER-ZuIOlviJiR2w4vblDMQlCSzbgxwbuMbP2FeQCTNKq-EIniYLVEYov8LZGUb5fcLVXXN1Fy4boav0CuguZOmLhoWsC39ADsOy6ZaiFPsl-FiUQOf-ryjnzxNxf81Dvs3jXxLftbEP4ehjj8WBhjTkG7E25jSsretoRSG9nun59eP85fDtmum-1x60H5koAgwykMWopyMo22CHI6Ama7mozlt4ROhImZ_qlT0GPUgD0g8Xc72V0dmmtiYsEuLt8nu7U9uHYpM0Vdbssp1Mgg4GK5bffh19uLNDTZVnOfUv0utnMjb6MHs_unsV3U36XpyfTM5U7-4ktVO9VnagSSzA8lkdnX1ARa08aO_pLAV5vivLpK9kWma8LfK82GWqFAJFXm5FzbebMsvLFBMjazQ-imRCjPgIMwXFJDTRleBC8G2appng2WatirTFvOSNzNq85pI8hIPU5tKPxFWzpHrqPG0a7YN_3ZR-znGuSeSXU-itq5wNkn4DuutDMl9fzfJ_AxK3MYc">