<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/58431>58431</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
miscompile from aarch64 backend with global isel
</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>
let's take this function:
```llvm
define i32 @f(i64 %0) {
%2 = trunc i64 %0 to i32
%3 = freeze i32 %2
%4 = zext i32 %3 to i64
%5 = urem i64 %4, 10
%6 = trunc i64 %5 to i32
ret i32 %6
}
```
when `0xa8552d4928501120`is passed as an argument, the selection dag backend and also alive2 believe that it returns 4. on the other hand, the global isel backend generates code that returns 0.
sdag gives:
```
f: // @f
mov x8, #-3689348814741910324
and x9, x0, #0xffffffff
movk x8, #52429
umulh x8, x9, x8
mov w9, #10
lsr x8, x8, #3
msub w0, w8, w9, w0
ret
```
whereas global isel gives:
```
f: // @f
mov w8, #10
udiv x9, x0, x8
msub x0, x9, x8, x0
ret
```
https://gcc.godbolt.org/z/xM44TYnbb
test driver:
```
#include <stdio.h>
unsigned f(unsigned long);
int main(void) {
printf("%x\n", f(0xa8552d4928501120L));
}
```
cc @aemerson @ornata @nunoplopes @ryan-berger @nbushehri @efriedma-quic
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy9VUGToyoQ_jXkQk0KQR05eMjMvD29d3uXPaISZQchC5hk59dvgybjJDtVu5elFIXu_rr5um0b2_2otQyIPnocxKvEYVAe7yfTBmUNYjtEXhDZoZLMl9bHcd7q5F4ZiRWjGOVkj2ilyhwjWhBEOUaPT7Majlugwl5wcACLL1o42Gi80mJJa--kfFtwwXIlz5P8TZ7DRcoSSJmvlIqkNDk5XjzliD7jjKx0yvtwiptwnLw6KRcKHl9uuJiXp0EaDCtyFlVR0C7ntCpIltGoAlweh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