<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/112476>112476</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[InstCombine] `samesign` flag should be dropped in `InstCombinerImpl::foldICmpAndConstConst`
</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:
```
define i1 @src(i32 %x, i32 %y) {
%shf = lshr i32 %x, %y
%or = or i32 %shf, %x
%and = and i32 %or, 1
%ret = icmp samesign ne i32 %and, 0
ret i1 %ret
}
define i1 @tgt(i32 %x, i32 %y) {
%shf1 = shl nuw i32 1, %y
%or2 = or i32 %shf1, 1
%and3 = and i32 %x, %or2
%ret = icmp samesign ne i32 %and3, 0
ret i1 %ret
}
```
```
Transformation doesn't verify!
ERROR: Target is more poisonous than source
Example:
i32 %x = #x80000000 (2147483648, -2147483648)
i32 %y = #x0000001f (31)
Source:
i32 %shf = #x00000001 (1)
i32 %or = #x80000001 (2147483649, -2147483647)
i32 %and = #x00000001 (1)
i1 %ret = #x1 (1)
Target:
i32 %shf1 = #x80000000 (2147483648, -2147483648)
i32 %or2 = #x80000001 (2147483649, -2147483647)
i32 %and3 = #x80000000 (2147483648, -2147483648)
i1 %ret = poison
Source value: #x1 (1)
Target value: poison
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyklcGOozgQhp_GXKxu2WUIcOCQSTZSn1bqnRcw2ASvjI1sk0n26VcGkiZMa6SZjqKAyfer6v9dcbj36mykrFD2DQGI0Fz_u_1AACg7JnwMnXXV8jCprbhV73JwVoyNdIjtETkiskc7srynpZCtMhIrilFKvGsQFIoBRpBdERzwcn9DUGKUf5s1OD7yXYsRO2LtO4fXkgn_4KybMPuAfNcu2HWFcSMmLl4X0LrI0RXkZJgg1fQD9ryXMQ4c258V3IgoWazhiEdjk3Bxnx-Xm5_dh3P4Hfd0asV3Gpvxx4TST-3Dz_7p1hg3gm3t38O0Dn4vArbO4NchPM_CZvndceNb63oelDVYWOkNgjzgi3SqvSGg6yj_en__-x2xPf7O3TnW9Li3TuLBKm-NHT0OHTfY29E18kl45f2g5WNA7_YnmwjYtSDzCyMogKZ5WrBdWkSTL-tl-SS_PeSzmLZRzuiDmz__mdvZ1L7P9oecxAQLuq2yDPeqS_rUZfncZb7V36f-F4XoetcjtwGWvZpC_8QH_VqM9_H9ikP2py08WZ_naL1r-ML1GPfus1iWKXwga_lmzhNRMVGykieyojmUJGMMiqSrQEjWtpksGkKhlK0oBclYzkE0NS0lJKoCAikldEdSlkH-SjnhVGY1K0leclajlMieK_2q9aV_te6cKO9HWVEKab5LNK-l9stp3ivf2H5Qevq5xUMdDgggKhHbK-NDY_taGbmc966KX73U49mjlGjlg_8oE1TQ09_Em_HhsOiyI0Y7cj800I7gVvMz9p0dtcC1xMLZYZACKxPBldS99YOO08X2rdXi7dAPeyMOdiKMD2hHktHpqgth8JGDE4LTWYVurF8b2yM4TT7my8vg7L-yCQhOUxwewWlJ5FLB_wEAAP__HnnRUQ">