Issue 58109
Summary likely miscompile of code involving a usub.sat by AArch64 backend
Labels backend:AArch64, llvm:codegen, miscompilation
Assignees
Reporter regehr
    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
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to