<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/59902>59902</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
miscompile by AArch64 backend related to smax.i64
</td>
</tr>
<tr>
<th>Labels</th>
<td>
backend:AArch64,
llvm:codegen,
miscompilation
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
regehr
</td>
</tr>
</table>
<pre>
it is easy to see that this function must return 1:
```llvm
target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
define i1 @f() {
%1 = select i1 false, i64 0, i64 9006649496829950
%2 = call i64 @llvm.smax.i64(i64 %1, i64 9006649496829950)
%3 = icmp eq i64 %2, 9006649496829950
ret i1 %3
}
; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.smax.i64(i64, i64) #0
attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
```
however, the current AArch64 backend gives this code, which ends up returning 0:
```
_f:
mov x8, #9007199254740990
movk x8, #65503, lsl #16
movk x8, #65407, lsl #32
cmp x8, x8
cset w0, gt
ret
```
cc @nunoplopes @nbushehri
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysVN2S6igQfhpy06VFICFykYvMsXyBfYAtQtqEPQRcIOP49lug41h19szVsTSG5qP5-udrFaOZHWJP2jfSHiu1pcWHPuCMS6hGP916k8BEQBVvkDxEREiLSpAWE-G8OZ2Md7BuMUHAtAUHNeEDoUdCByLo_Wvt-3o3JRVmTDCppKy6-S0B4UcgjOFuJXzAnTkQPuQfZztTC8KH8sgr0RA-iGZnapYBNTvsHGd321_Zxtjj3vKc8GwcgqmBNPRM8r4E0r3ddwEIa-tye0SLOmXgWdmIhP0AIxqgny-SUiEa2UhxYFK29MUBKw60srYgSVNC3cdVfewzX3YoZtbWv3XG5Is_XvwZvV4A_4XHWZbP_o5EwMI8n30E3x1fs0D4G5w-yzSkFCLhAzifOY9K_wTnzwERnI83p8H5zV2NmyBeUG9WJTVahKux9lHdFVcfboQdnHf4JD-htirgN0l4xF9qwDh9pahSCmbcEsayde-I7u0PkoSvpHy25CuBxV_xHUOmmBYEvYWALsEwBL2IBjIDdBPM5h3jvfG1n0qfXBejF0A3RdguDwEYNwP9VQP35d_nnP7__3xSkqt_J1R-HPINhHFJaVdLydqma6iU9BX38xUo2pby_G6jzetafANtaPcC5U_pSL1ensiPw5c5YiJUXoss5vS0B0zfpFbr3A9uc_5i_SVXuKFu3OKCSzB3SDX1fJJcqgr7WnScHVrRNNXSn7EZu3MzcUHPGkc5KdFJjoeWiYlNdVuZnlHGaU1l3fGGNnvRUSrrkSMK2goUpKG4KmP3pSF9mCsT44Z9KyVllVUj2lhGH2OPIhM-PMqepwn7QRgrw4sPueQzuqd5NVH79WKsytLK5vZYhT6jd-M2xywDE1P8ujuZZLF_nkMYb7_0WECrEk5l1D70U23B9ktKl6xcwk6EnWaTlm3ca78Sdir87n-7S_D_oE6EnUqgkbBTifW_AAAA___YFq21">