<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/112666>112666</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[InstCombine] `nsw` flag should be dropped in Negator
</td>
</tr>
<tr>
<th>Labels</th>
<td>
miscompilation,
llvm:instcombine
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
dtcxzyw
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
dtcxzyw
</td>
</tr>
</table>
<pre>
Reproducer: https://alive2.llvm.org/ce/z/ZFF_QK
```
define i8 @src(i8 %x, i8 %y, i1 %c) {
%t0 = sub nsw i8 0, %x
%t1 = select i1 %c, i8 %t0, i8 %x
%t2 = sub i8 %y, %t1
ret i8 %t2
}
define i8 @tgt(i8 %x, i8 %y, i1 %c) {
%t0 = sub nsw i8 0, %x
%1 = select i1 %c, i8 %x, i8 %t0
%t2 = add i8 %1, %y
ret i8 %t2
}
```
```
Transformation doesn't verify!
ERROR: Target is more poisonous than source
Example:
i8 %x = #x80 (128, -128)
i8 %y = #x00 (0)
i1 %c = #x0 (0)
Source:
i8 %t0 = poison
i8 %t1 = #x80 (128, -128)
i8 %t2 = #x80 (128, -128)
Target:
i8 %t0 = poison
i8 %#1 = poison
i8 %t2 = poison
Source value: #x80 (128, -128)
Target value: poison
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0VE-Pmz4Q_TTDxdrIDGDIgUN280P6qVKrpnvqpTLgEFcGI9tkk_30FeD8oatu91IpCmPPm-f37NFwa2XTCZFD8giItatOr-cXQIRkG_DBHbTJ_WZQ6vqc70RvdD1UwkC0IQfnegvRBrAALLiSR4ErpY7tSpsGsKgEYPEKWHwvih9fPwHdAt0Ao_43LWuxl50gMiMQU2sqwGyMMTkBPpE5PE9hOIYV4JpA-jgXk3HLUQLRltihJJ19GUvoiJ8o7lDhjBJKVO5GdjnC0Vt8KRu38cp9J2Wiu3Ab4S4c6B2mWx-8dega968cvm_wtPB6xz075HXts6GnPn_E4PItf1s-G97ZvTYtd1J3pNbCdoCpI0dh5P4MGN5f03-73Zfd2FXP3DTjkZa02gjSa2l1pwdL3IF3xOrBVGJReOJtr8TYh9Pa-51sAUanjBLALMRsNPYwfdf3yPMVSSckveXnS7zll-n5_9ssaHm6f7FZ-yIRfliXf5n3of6mpyv7qAbAKPyTPHyTmP2RI1fD6PIvevzjXdH3TNf2COo8qtfRmgciD1NchzFL4jQ45BGle5FVaZIwWrJSMMZ4yCqGPBOUxvtA5kgxDmmYUoZrmq5SzLJkncZpGdcVFSXEVLRcqusYCqS1g8jDEBljgeKlUNaPu1baSre9VFN_jlMPnwBxrIRoIzvrKt2WshN-IJp8TD2UQ2MhpkpaZ2_HOOnUNEf_76x78nXJlgCjnX0BRsle8YbYgx5UTUpBaqP7XtREduSzaLjTJhiMypcztZHuMJSrSreAxSRs_jz0Rv8UlQMsJn8WsPAWjzn-CgAA__9D-JDZ">