<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/69803>69803</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
clang is suboptimal for `(~a ^ b) < ~a`
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
k-arrows
</td>
</tr>
</table>
<pre>
Consider the following two functions:
```cpp
int foo(int a, int b)
{
return (~a ^ b) < ~a;
}
int bar(int a, int b)
{
return (a ^ b) > a;
}
```
Clang vs GCC:
https://godbolt.org/z/rxK1nr794
Alive2:
https://alive2.llvm.org/ce/z/aUhKRe
```llvm
define i32 @src(i32 %0, i32 %1) {
2:
%3 = xor i32 %0, 4294967295
%4 = xor i32 %3, %1
%5 = icmp slt i32 %4, %3
%6 = zext i1 %5 to i32
ret i32 %6
}
=>
define i32 @tgt(i32 %0, i32 %1) {
2:
%3 = xor i32 %1, %0
%4 = icmp sgt i32 %3, %0
%5 = zext i1 %4 to i32
ret i32 %5
}
Transformation seems to be correct!
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysVM1u5CwQfBp8aWUEjX8PPiQz8XfI7dPuA2AP9rCLzQhwks0hz74Cz493kkh7WMmS21BddJXpFs6pYZKyJtkDyXaJmP3B2PrnnbDWvLikNftf9dZMTu2lBX-Q0ButzYuaBvAvBvp56rwykyP8ntAdofckp8vTHY_Lipo89MYQLEMkCG4hBC3B6pRSPCwBWOlnOwHB8l0AyR4jCAjfwrsg_OEM352CC30r7N_Qw-qAP_gf4TP6s5L1aVstpgGeHfy33V40H7w_RgewIdgMZt8a7TfGDgSbN4KNfX1iky2qdM10r9WzxC84RNzcaP08nng6eSIT3w9P_8s106XQAF-W9rJXkwTFEUhKne2CPeEDMxodWmIW5Z_9uRYDYZMD4Tt4NRbWmSlWaZUXWGUraHoL5QEaD7iCsghS3XgEp_0ZmZ6QfIXMI_JNvnpQbEn1JiRcr8k5Pb_9aXxH-ONnJvjB_wsT2Kle-kH-omzwtx7QDx6slKVfKstulH2zYnK9saMIDQdOytGF5FZCZ6yVnSfIbi5Esq_5vuKVSGTN8qooM06rIjnUJaUdb7lkFZMZ7XkmeFFg2pVYYFrmXaJqpMgZRUZZxnixQWQVYpHlBaWyRU5SKkeh9OWOJsq5WdZ5VVKeaNFK7eJUQexCzxDEMGBsHfB37Tw4klKtnHdXBq-8lnWEg3Lg5tYcvRqFht5YCJI-HQw5TWar65suVP4wt5vOjASb2BjL6-5ozY9oVhMLdgSbWPPvAAAA___e-1Y-">