Issue 61549
Summary AArch64 miscompile
Labels backend:AArch64, llvm:codegen, miscompilation
Assignees
Reporter regehr
    here's a function:
```llvm
define i35 @f(i35 %0) {
  %2 = srem i35 1, %0
  %3 = call i35 @llvm.ctlz.i35(i35 %2, i1 false)
  %4 = lshr i35 %3, 5
  ret i35 %4
}

declare i35 @llvm.ctlz.i35(i35, i1 immarg) #0
```
when passed `8` as an argument, it should return `1` because:
```
%2 = 1
%3 = 34
%4 = 1
```
however, when compiled to AArch64 by latest llc we get:
```
_f:
	mov	w8, #1 
	sbfx	x9, x0, #0, #35
	sdiv	x10, x8, x9
	msub    x8, x10, x9, x8
	eor	x0, x8, #0x1
	ret
```
and this returns `0` for the same input, verified using this driver:
```
unsigned long f(unsigned long);

#include <stdio.h>

int main(void) {
  unsigned long res = f(8UL);
  printf("%lu\n", res);
}
```

cc @nunoplopes 
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to