<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/143529>143529</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Missed optimization: propagate not of `trunc nuw ... it1` equalities
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
yashnator
</td>
</tr>
</table>
<pre>
Not of `trunc nuw iN ... to i1` equalities can be propagated.
For example, `store i8 %v, ptr %p, align 8` -> `store i8 0, ptr %p, align 8` in
```ll
define i8 @src(ptr %p, i8 %v, i1 %cond) {
%trunc = trunc nuw i8 %v to i1
%not = xor i1 %trunc, true
%and = and i1 %not, %cond
br i1 %and, label %3, label %common.ret
common.ret:
ret i8 0
3:
store i8 %v, ptr %p, align 8
br label %common.ret
}
```
should be optimized to:
```ll
define i8 @src(ptr %p, i8 %v, i1 %cond) {
%trunc = trunc nuw i8 %v to i1
%not = xor i1 %trunc, true
%and = and i1 %not, %cond
br i1 %and, label %3, label %common.ret
common.ret:
ret i8 0
3:
store i8 0, ptr %p, align 8
br label %common.ret
}
```
[Alive2 and opt](https://alive2.llvm.org/ce/z/AbsgX_)
Discussed in #143273
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzcVE2PozgQ_TXFxWpkyhDCgQPdWW7b572tjKkkXjk2a5v0x68fGejp9Gh6NCPNaaRIuOzn96peOSVD0CdL1EJ1D9Uhk3M8O9--yHC2MjqfDW58aR9dZO7IYMejn61idn5i-pHlec6iY7qAHWf0_yyNjpoCU9Kygdjk3SRPMtKYA--Ad73zjJ7lZTIE-JDoQnSemN4zwOqa9qbo03pKa2n0ybJ9Ir8D8dcHPP8BWFu26sGOrz9jgHcjHbVdxUoevALc3xLcJKGLtFTOjoANg_oeeJd21uJBHNiNDeu1zQfesRRaFxfYs_Mb2XIhcUc_0xtM2nGBpe8Ksy4uzmzqCTe8UciUzgMzciCTYvEhUu5ycTb3FNfab2LRLUSe4urcci7etn-qBVsin6jVh1uzV_5wdrMZ0zNwU9QX_Uoji24V_d2t-fN78-lz590v9gWq-87oK-FSmZsiVAfA_TnGKSRZ7AF7uSByY66X3PkTYK8IsH8F7LshnP75F7BZ6Q46qDkEGtO_jgGKohRYC5aNrRgb0ciM2qIum2rHm6rJzm1THks1DojHfdOgGIpKyRpxLxUnQUfMdIscK74reCF4U-zymooBFScl92NZ1DWUnC5Sm6_pZTqEmdqiFBU22eJFWOYZoqUntpwCYhpvvk2X7ob5FKDkRocY3mmijobav_VSzvZqZdTOgujehxmz3xmGaRLq-M0czGZv2o_GnnQ8z0Ou3AWwT8Lb527y7j9SEbBf0g2A_VbPtcUvAQAA__9VOKRB">