<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/58109>58109</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
likely miscompile of code involving a usub.sat by AArch64 backend
</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>
consider this IR:
```llvm
define i64 @i(i8 signext %0) {
%2 = add i8 %0, 1
%3 = call i8 @llvm.usub.sat.i8(i8 %2, i8 1)
%4 = zext i8 %3 to i64
ret i64 %4
}
; Function Attrs: nocallback nofree nosync nounwind readnone speculatable willreturn
declare i8 @llvm.usub.sat.i8(i8, i8) #0
attributes #0 = { nocallback nofree nosync nounwind readnone speculatable willreturn }
```
if we generate aarch64 and link the result against this driver:
```c
#include <stdio.h>
unsigned long i(unsigned long);
int main(void) {
printf("%lx\n", i(0xffffffffffffff81));
}
```
we get:
```console
$ ~/llvm-project/for-alive/bin/llc foo.ll
$ ~/llvm-project/for-alive/bin/clang foo.c foo.s
$ ./a.out
ffffff81
$
```
I hope it's clear that (1) the chosen input respects the signext constraint on the argument and (2) a function returning a value that's a zext of an i8 should contain zeroes in all of the bits above the first byte
cc @nunoplopes @ryan-berger @nbushehri @Hatsunespica
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJytVNuOozgQ_Rp4sRoRCJA88JDuntHO6_6BMQV427EjX9Kd-fo5NskkvbM70koboWC7ijp1yqdqMOOlF0Y7OZJlfpGOffszqw9Z-ZqVh6wt10ep83E9GmmSmphstyzbljKrdnLHnJw1fXiWVU2ZVXuWdc-rN4tHFcvqV8bHkcF1dXlhmweHOjkIrlTy2Ca4IrgwFI77Qu5WlBgqforlBigPAbYpwPeYwupXM29ijjcfS35NGb5Xat3rdbH-18_sa9DCS6PZwXvrUASmTUxq4OINy8kS4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