<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/144780>144780</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [llvm] Miscompilation of freeze instruction with llc -O1
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          8051Enthusiast
      </td>
    </tr>
</table>

<pre>
    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.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyEVE2P4jgQ_TXOpdTIcT4Ihxzo6WV3D6297H3kxBXiHceO7Epo-tevbJoGIaSJkCJSr75evSoZgj5axJZVr6x6y-RCo_Ntw6v8D0vjErQMlHVOndu_B5jOsFiFPpC0StsjuAFoRBg84ieCtoH80pN2FnSA3nmPPTHx4wJyxrhT9OqdQgijW4wCaU7yHMAjLd6CBLtMHXqgUVKMcU3g_ASs5haYeAUBTOzhF6s5nEb0GC3pXy8tdAjSnmnU9rhhfM9qfvkZs06M7xUO2iLoQgAr-ewxoF_x5yy9pjMTTTKIyjKxA7Z9ZXwPAPGLAFa8fXdaCJidDs7eAEUCSKXgFuNH8rxhykdM8YDxSFdTGavfvt33wPj-L3fCFX10G5wH_JDTbBCchY-m_lmXkFrtIxtMNCdNI7iZ9KQ_ZZqLwRUNSAKDMhDksU-30LxQeDIlVuzv88sQKXwkrUiVP3uYKJ6xzPcwuTUhUH7EVlDpLwLiE_m5N8qP3xo90gNRf-oV7UVHNOpwFdq1V2kBI-CitxipW-ipxO58lUqkx3dExkRJ3DrAsNiL8APiFIAcdDjKNS7F1x6Y87ezjcr8N7ophwGsI3DWnGGU84z2NsxrWRK6xfZj3AZHI3roZP8LrYp5XOR_JJpDHJY4MHE4OtU5Qxvnj0wcPpk42M_38t3tmnWTqbZQu2InM2zzbcXFVlS7PBtbWZVdXxeyL1TZ7JTKux45Dnk5lBUOfZ3pVnBR8Tpv8qbcVflmK1Q5NFUnmqHc5ihYyXGS2mziqsXkmQ5hwTYvy23DMyM7NCEdGiEsniBZmRDx7vg2Or10yzGwkhsdKNzCkCaTLlTa4eoN3nXo3TRrc9G0G55doKR9Y3p4-SfPFm_aB5I0jUu36d3ExCEFvrxeZu_-S2frkAoMTBy-Olhb8X8AAAD__8D5mZc">