<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/55253>55253</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Miscompilation on aarch64
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
kazutakahirata
</td>
</tr>
</table>
<pre>
It looks like 13403a70e45b2d22878ba59fc211f8dba3a8deba is triggering miscompilation on Aarch64. I don't know if the bug is caused by the patch or exposing a latent bug elsewhere.
Consider:
```
target triple = "aarch64-grtev4-linux-gnu"
define i128 @foo(i128 %x, i128 %y) {
entry:
%0 = tail call i128 @llvm.usub.sat.i128(i128 %x, i128 %y)
ret i128 %0
}
declare i128 @llvm.usub.sat.i128(i128, i128)
```
Compile this like so:
```
$ clang --target=aarch64-grtev4-linux-gnu -O2 -S reduced.ll -o reduced.s
```
Here is the body of the function in assembly:
Before 13403a70e45b2d22878ba59fc211f8dba3a8deba:
```
foo:
subs x8, x0, x2
sbcs x9, x1, x3
cmp x8, x0
cset w10, hi
cmp x9, x1
cset w11, hi
csel w10, w10, w11, eq
cmp w10, #0
csel x0, xzr, x8, ne
csel x1, xzr, x9, ne
ret
```
At or after 13403a70e45b2d22878ba59fc211f8dba3a8deba:
```
foo:
subs x8, x0, x2
sbcs x9, x1, x3
cset w10, hs
cmp w10, #0
csel x0, xzr, x8, ne
csel x1, xzr, x9, ne
ret
```
Here is the trace without the culprit patch with x == 0 and y == 1:
```
# x0 x1 x2 x3 x8 x9 x10 x11 c z
# 00 00 01 00 ?? ?? ?? ?? ? ?
subs x8, x0, x2 # ff 0 0
sbcs x9, x1, x3 # ff 0 0
cmp x8, x0 # 1 0
cset w10, hi # 01
cmp x9, x1 # 1 0
cset w11, hi # 01
csel w10, w10, w11, eq # 01
cmp w10, #0 # 1 0
csel x0, xzr, x8, ne # 00
csel x1, xzr, x9, ne # 00
ret
```
Here is the trace with the culprit patch with x == 0 and y == 1:
```
# x0 x1 x2 x3 x8 x9 x10 x11 c z
# 00 00 01 00 ?? ?? ?? ?? ? ?
subs x8, x0, x2 # ff 0 0
sbcs x9, x1, x3 # ff 0 0
cset w10, hs # 00
cmp w10, #0 # 1 1
csel x0, xzr, x8, ne # ff
csel x1, xzr, x9, ne # ff
ret
```
Note that the result is wrong with the culprit patch. It should be 0.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJztV82S4jYQfhpzUUFJsj3YBx9mdmore0hyyBPIdtsoCItI8g7M06clMBizwOxUDnsIpbJoqfX1v9wudb0vvjmitF5bouQaCIsTGoslhSQtec15tsxKkeZNxRlrsroUschqKAWRljgj2xaM7FqykbbSm61UwkndERzPwlSrp2RByDdS6y7iS0fWnX4jsiFuBaTsW49Rid5CTcp9WNwKV62INgR2W209sCAICZ0L_KAsvK3AwCKirxF9Pjy_6M7KGkwUP4-Xoyd6HIF0wrTgvM5bBSSKX0nEuTgoOW-Ng-_JXMmu383brsetMVQNjeyASMYzEiW00Tri2YHi6S7iX8hA7COek2j5cjiHepv9SS3iGWgQ7YRUaLpSJ0ylvm8Wve3LhRVu4VfviRgADVo0rB_tjJavl6pXShh4LGcQcUKf-G_wtQ8yYLDkMWGsvu_3iCcEVcBQzueHGKADbvmdzP_kZP4X2lX3FdQLdNBcnyh7R7HfwBtpD6mFaU30Ic2avqtCSsqOCGthU6r9ROEXaLT5eObfN9fnxpkhR0ej1vkuuHdHw5Ofd8sq7OZhnYVnfNqtNtvx0dOyRRfS_I0FtJWc8g9gV_xsym9BnYFOU2CDfyawx-2Ix3QKcDTr3YQpqNvBFRMbM-UTJuNVvBnbZ-evBNE4ML9glC7DYX8hv41rwhlRAXmTbqV7F1aqXm2NdMc71--Qnb-c_P1Eiehqsh9I9qDEaX4xeIxORE-hE9FTaBoqjqRfYqQi7zdPURoG888o_opjmKbzsPUgggPw-Nc0YwrFPQr0j0AuccYg06rNbwKMfozcq-_7EJ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