<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/55739>55739</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Failure to optimise shift+and+boolean conversion pattern to simple comparison
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
GabrielRavier
</td>
</tr>
</table>
<pre>
```cpp
int
f3 (int c)
{
return ((2 << c) & 16) != 0;
}
int
f4 (int d)
{
return ((16 << d) & 32) == 0;
}
int
f8 (int h)
{
return ((32 >> h) & 16) == 0;
}
```
These functions can respectively be optimized to `return c == 3;`, `return c != 1;` and `return c != 1`. This transformation is done by GCC, but not by LLVM.
See also [Godbolt comparison](https://godbolt.org/z/969P6849b)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyNUkuPmzAQ_jXmYhWBzSMcOGySbi5bqWpXvdt4CK4cG9kmVfbXd4BFTVdbbaUBZjzDfA-QTt1aUmVrdONIsiPJHrSNa9JzStgOS9oR1qxnpN6vCaUe4uTtPILBKOEHjGUUzyqaV2uWE36kGeH7bcHxNXkDVmxg6kOwvNrQ1IbG2ZLx43-i7Ta04UM0Pmv7jLHM3mv7N9pm6j348wABaD_ZLmpnA-2ERaAwAtZXMDcqgbox6ot-AUWjo_j-K5Fuw-IzFq5lh7-7q8v52qXCqvfbVZbS50EHGr2woXf-ImYuFE-Us0DljZ4Oh3m7nCK1Ls4nT08_vqT3Qr4DUGECEiz3J6ekM_iHuMsovA7OkvKIpg0xjoHwB8IeMc7rVOr8GasXvJqq-VrtikaikYlquWp4I5Koo4H2UWgzeZgtWP1A28Kg-0jYHqXhXTpnAO3rnL2CD7OEUcQIqBZfCvoyGrijlEzetG8Y6ThMMsUZLIy5bo9Po3c_8YtgqUOYIGBSljVvkqHtC1nWXdUUNUheFjslmahVweo8r5q-ZIkREkxo0RbCmIVfdFmBOXqS6JZljGUljtcFK-u0EyU0uRAdk02f1YIUGVxQejrzmK1KfLtQktM5YNPoEMOfpghBny3AAof7xRQH59uTkF6D-SauGnyyEGgXAb8BOEMfJw">