<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/92887>92887</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Miscompile with opt -passes="instcombine"
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
mikaelholmen
</td>
</tr>
</table>
<pre>
llvm commit: 502bea25bdc07d1
Reproduce with:
```opt -passes="instcombine" bbi-95633_2.ll -S -o -```
Result:
```
define i16 @foo() {
entry:
store i16 0, ptr @bit, align 2
store i16 0, ptr getelementptr inbounds (i8, ptr @bit, i64 2), align 2
store i16 0, ptr getelementptr inbounds (i8, ptr @bit, i64 4), align 2
store i16 0, ptr getelementptr inbounds (i8, ptr @bit, i64 6), align 2
store i16 2, ptr getelementptr inbounds (i8, ptr @bit, i64 8), align 2
store i16 0, ptr getelementptr inbounds (i8, ptr @bit, i64 10), align 2
ret i16 poison
}
```
Note the poison return value which I think is wrong.
Before commit e93d324adb4ff8
```
[InstCombine] Preserve poison in evaluateInDifferentElementOrder()
Don't unnecessarily replace poison with undef.
```
we instead got
```
define i16 @foo() {
entry:
store i16 0, ptr @bit, align 2
store i16 0, ptr getelementptr inbounds (%struct.bit, ptr @bit, i64 0, i32 1), align 2
store i16 0, ptr getelementptr inbounds (%struct.bit, ptr @bit, i64 0, i32 2), align 2
store i16 0, ptr getelementptr inbounds (%struct.bit, ptr @bit, i64 0, i32 3), align 2
store i16 2, ptr getelementptr inbounds (%struct.bit, ptr @bit, i64 0, i32 4), align 2
store i16 0, ptr getelementptr inbounds (%struct.bit, ptr @bit, i64 0, i32 5), align 2
ret i16 1
}
```
where we return 1 instead of poison.
I tried to use Alive2 on the input/output in
https://alive2.llvm.org/ce/z/1GVkRh
and it says
```
Transformation doesn't verify!
ERROR: Target is more poisonous than source
```
[bbi-95633_2.ll.gz](https://github.com/llvm/llvm-project/files/15387836/bbi-95633_2.ll.gz)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMVk2P4zYM_TXKhUhg098HH2Y2m2IO7RbpotdCtmmbHVkyJDlB9tcXjjPpBhPsYooZoECQQLH4HknzkZTOcaeJSpE8imS7kpPvjS0HfpakeqMG0qvKNKdSqcMAtRkG9iJ6gCTAiiQmVVMHWROKYCuCh-V7T6M1zVQTHNn3Irr8LdJg-ZjRw3qUzpET0VYgsna-NkPFmgQiVBWviySNor9woxSs_4C1gfXV_JbKTcq_pliODbWsCThMQcRBa4zAXGABIntcLpD29nS1BnDe2OV-IPATjN7OhhX7-SQVdxrwB3c78qRoIO3nE-vKTLpxIDDn_DUepzGgwOKjsOMPxE5_ho3_HTv_QL_D4D64JX-GHg07oy_FlG3vVtVvxhP4ni6XZ9vJajhINREce657eALfs34GdnC0Rneb72v2kdo5kkVKQEXURBjLporbNr9LKJLHJ-38p4tCki38bsmRPVxdYA0080tPT3rLbUuWtP-85OaLbcgulf-9G1ujBWYeJq2pJuekZXUCS6OS9RV4FjBMuqF2c9e1I8EsXpINdMb_z0UoMHHeTrXfXMBe18cZhSOE8G6dfBjde_SBt_BF76Dft_C9Ry96C19yl-9F5eGPBX7syRIc6UXZ4bXGTXsRxo2gn8Bbpga8gckRPCg-EILR5ybBepy8wJ2Z_Dh54Etzgd770c1VjzuBO3m22cwzdmNsJ3BXk8DdN4G78Jc_n_f9YiV1A-zByZO76_lXK7VrjR2kZ6OhMeQWkR_IcnsSeDOnP-_3X_bzLP8qbTenxsEwv48lRDM58L3U4Mxka7rfmV760-3I3nTfRLIVmN8G2bHvp2pTm0Hgbg718rMerfmb6jlLLStyc9BJlGd5lArcvYZ-6WOrpoyaIirkisowC1PM4yjIVn2JVZFnBaZhmoVNFqRFk6ZYyBxlHDShzFZcYoBxkGAYFFGO2SamJCdq67hIojYMKxEHNEhW1zeyYucmKgvM82ylZEXKnTcmRE1HOD8UiPMCZc-b0rqaOifiQLHz7l8Uz15R-Su72gwjq2VDgp8sRKvJqvLNqTz7NOfy7PM_AQAA___NQ_Fn">