<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/62898>62898</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Inconsistent behaviour between using logical and bitwise `and`/`or` on `smin`/`smax`
</td>
</tr>
<tr>
<th>Labels</th>
<td>
missed-optimization
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Kmeakin
</td>
</tr>
</table>
<pre>
GCC recognises all these functions as equivalent, but LLVM doesn't:
```c
int32_t smin(int32_t x, int32_t y) { return x < y ? x : y; }
int32_t smax(int32_t x, int32_t y) { return x < y ? x : y; }
bool smin_or_bitwise(int32_t x) { return (x < 0) | (smin(x, 1) < 0); }
bool smin_or_logical(int32_t x) { return (x < 0) || (smin(x, 1) < 0); }
bool smin_and_bitwise(int32_t x) { return (x < 0) & (smin(x, 1) < 0); }
bool smin_and_logical(int32_t x) { return (x < 0) && (smin(x, 1) < 0); }
bool smax_or_bitwise(int32_t x) { return (x < 0) | (smax(x, 1) < 0); }
bool smax_or_logical(int32_t x) { return (x < 0) || (smax(x, 1) < 0); }
bool smax_and_bitwise(int32_t x) { return (x < 0) & (smax(x, 1) < 0); }
bool smax_and_logical(int32_t x) { return (x < 0) && (smax(x, 1) < 0); }
```
https://godbolt.org/z/9caPKxz9h
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyslEFvoz4QxT_NcBk1csZA4MChTcVff7Ur7WmvlYEpeNfYXWzapJ9-BUm0m5zCZiUE2Ib3m-cHo7zXrWUuIHmA5DFSY-jcUDz1rH5oG1Wu2Rf_bbc4cO1aqz17VMZg6Ngzvo62DtpZj8oj_xz1uzJsA9AWqzHg8_O3L9g49hZoE0Deg3gEcQ-pOBz1YaxtkPQS0PfaAmWn4W6SOQ32QDnC5gEHDuNgcYcgt7hHkOV8f497kA8Im8dLTbX7V5qHc-WcmUt9ccNLpcOH9nxOOBMFyg664rCwnWaOTudq1vP88YEz3hnJuFbXyiwhLYJdIpVtlruj9G_cTajF9ihdRDtjqt1N2c1f1HXuDqRbsrsGdom8Kbtl7m7N7ip7p37xp9suhDc_tRQqgcrWNZUzYeWGFqj8BCrzWn192n3mXdQUssllriIu1mkWZ1lOaRZ1heC8bmS8zuI8SaqEBb2uuZbrdVw3WdokkS5IkBQJxULEmzhbqURwleT5RshMSsEQC-6VNitj3vuJHWnvRy5SyvIsMqpi4-e-StRr77m5c29B9_pTTU0TiKaGOxTT23fV2HqIhdE--N96QQfDxf-2dtZrH9gGrLhT79qNA1YcPpgtjl7bFo8poLINHsNHSIWyzbRzVEIq3ACpQGen-fm3OS3MOaQiGgdTXGysDt1YrWrXA5VTWcfL3dvgvnMdgMrZswcqZ9u_AgAA___-vczk">