Open
Description
If my understanding of the freeze instruction is correct, given n
, the following code should always return a number that is of the form n + 2 * k
where k
can be anything.
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:
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.