<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/69965>69965</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Miscompile in x86 backend, incorrectly removed bit mask
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
meheff
</td>
</tr>
</table>
<pre>
https://godbolt.org/z/h4cWeWqP6
Input IR:
```
source_filename = "__module"
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
define i16 @test(i8 %_in) local_unnamed_addr #0 {
%_1 = and i8 %_in, 127
%_2 = xor i8 %_1, 127
%_3 = or i8 %_2, -128
%_4 = zext i8 %_3 to i16
%_6 = shl nuw i16 %_4, 8
%_7 = shl nuw i8 %_2, 1
%_8 = zext i8 %_7 to i16
%_9 = or i16 %_6, %_8
ret i16 %_9
}
```
Resulting assembly with llc (trunk):
```
test: # @test
not dil
mov eax, edi
or al, -128
movzx ecx, al
shl ecx, 8
add dil, dil
movzx eax, dil
or eax, ecx
ret
```
It looks like the initial mask `and i8 %_in, 127` is being incorrectly optimized away. -O0 looks correct.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyElM2OozgQx5_GXEpEYBPABw6ZiSL1YbWr2cMcI4MrwRuDs9h0J3n6lQ2kk55oFkX-ql-V_-VyLKxVxx6xIutvZL2NxOhaM1Qdtng4RLWR16p17mwJ2xC6I3R3NLI22q3McCR0dyN012bNT_z57185SbYk2UztW38eHbz98H4PyyRP5l-YWjMODe4PSmMvOgTCtkAo3e87I0eNhNKJc2I4ogMpnNDiaka3kBh3hG0wPtMiIWzDaGj8NH2e-lGehSZW90FKS8I2KS3jQ5nMoz4s5Yt7nsV_e2yRMrUSD6pHUGkOJEscWkdoqUogdL1XPaEctGmE3o-9z0vuhZQDEMoSIMW3KQQEOA2ZiF7Cg_d3SGkxU36NBuhihgVKn5mwxgL0yVDPxF76A5QF6IYXt2AMnPF5PFJ5oGyroR8_piS9rw_4FK145h72TR-x8pdNixeb8rv-eb_cBwr-Czagu1v5XI5i-_JmTe0PtKN2qj-CsBa7Wl_hQ7kWtG6A0NINY38ilP_-kobqsg38_0cou1-HSXJvXLBIpZckpq8z76FHcfFpolTPdjNMvdBfytiZ99vFOzbBUXyJ64sBn-by2SqkvMuh31-qmoJPqn6xL6oW1c1ltg_oflOGNwfamJMFrU4IrkVQvXJKaOiEPQHJk5d_gDwBZaFGXz_VN2YYsHH6CubsVKduKEF8iOsK4j-TOf7MrCJZMckZFxFWac7LhFNe8Kit8lQWmJZYrDMmMsmbdYo1L5Ef5KFAziNV0YSyNKGMJpQzvipZVhSyFqLGoimbkmQJdkLpldbvnX8FI2XtiFXOeb6OtKhR2_CYUtrjBwSjfzzW22iovE9cj0dLskQr6-xnFKecxuoPZRvTnZX2RwSXModaNCfspT-TxzMYsDPvKKFWLhxiNA7660utXDvWq8Z0hO78PnMXnwfzDzaO0F1QZwndBfX_BQAA__-T-qL0">