<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/72475>72475</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
AArch64 miscompile of i1 arithmetic with global isel
</td>
</tr>
<tr>
<th>Labels</th>
<td>
backend:AArch64,
miscompilation,
llvm:globalisel
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
regehr
</td>
</tr>
</table>
<pre>
Here's a function that should always return true:
```llvm
define i1 @f(i1 %0) {
%2 = shl i1 true, %0
%3 = select i1 %0, i1 true, i1 %2
ret i1 %3
}
```
if %0 is true then it returns true (select blocks poison from its not-selected operand, so the intermediate poison value is not relevant here).
if %0 is false then it returns a not-shifted true value, so it returns true this time too.
the SDAG backend gives:
```
_f:
mov w0, #1
ret
```
on the other hand llc with global isel gives:
```
_f:
and w8, w0, #0x1
mov w9, #1
lsl w8, w9, w8
and w0, w8, #0x1
ret
```
this returns 0 when the input is 1
cc @hatsunespica
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMVMGuqzYQ_RqzGd3INhDCggXvRmn3_YDKwBC7z-DIHpLev6-MSXKVtNWLogSPZ845wxlbhWDOM2LDyh-sPGZqIe184_GM2medG76a39Ejk1UABeMy92TcDKQVQdBusQMoe1NfATzS4mcgvyDLW8aPjLdsz9PX2uuUQgOOZkYwAljBRyYP8UmWnMkaWPUjJUEMSWD5EYK2MXmFlZ8p9ZmTpxy02BM8kD6_V6SovBd5vCfmm8bq-CI2Lc24ooEJKxSQxhkMbX1uQSYPG3lnXf8zwMWZ4GYYvZvAUIDZ0UfKwAHcBb2ah6gquAgIZib0Ew5GEd5rr8ouGGlnF9ksXtVMoFcX6t2m9VXiqGx416gSvzZjpF8Vr-ibgtduSMdmzYRAzu3gO1UU-8ex_Q061f_EeYCzuWJ4Nzot_xxZ3sL_fu7g9eSujNc3ntzNxWPDI_0rePpdhxDBkUYPWs0DWNvDzZCGs3WdsmAC2l-R-SCM1vD6dohKHnr43-JVan2X-iy1wT5L1_3b4RWXb-F33P_qdPXj7hCHW3Q3Tc1loei6-P5G-j4eKa0oLDOGi-lVimdDkw91XqsMG1FxLoTMi32mm2rMx67oRFVXXbkvBBeHXPTxoaqrWvDMNJLLXAix56Usi_3u0Cm5V4Kj6uouPwhWcJyUsbt4vnfOnzMTwoJNJYuqzKzq0Ib1ZpFymxuWt23re70vmJRMfjIpJxN6N12MVfFqeYTXKyNvk5nRy7hTHjPfxJ2PbjkHVnBrAoUnPRmy2GwM8EBGcGM89cob0hOSeZ-UbPG20USXdVrkicnT2ZBeul3vJiZPq5z093Hx7i_sicnT2m5g8rR2_E8AAAD__1-ti5c">