Issue 144780
Summary [llvm] Miscompilation of freeze instruction with llc -O1
Labels new issue
Assignees
Reporter 8051Enthusiast
    If my understanding of the freeze instruction is correct, the following code should always return a number that is of the form `n + 2 * k` where `k` can be anything.
```llvm
define i32 @preserve_parity(i32 %n) {
    %2 = freeze i32 poison
    %3 = add i32 %n, %2
    %4 = add i32 %3, %2
    ret i32 %4
}
```
However, for example on x86_64 `llc` (with optimization level at least 1) outputs the following code:
```asm
preserve_parity:                        # @preserve_parity
 mov     eax, edi
        add     eax, eax
        add     eax, eax
 ret
```
Given that this always outputs an even number, but `n + 2 * k` is always odd for odd `n`, this function seems to behave incorrectly for odd n.
This does not only happen on x86_64, but a bunch of other backends too: https://godbolt.org/z/nzM4Mo98v.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to