<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/116019>116019</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[InstCombine] missed optimization: sext(trunc(x)) is transformed to ashr(shl(trunc(x)))) when there is no chance to fold
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
wenju-he
</td>
</tr>
</table>
<pre>
Please check opt output in https://alive2.llvm.org/ce/z/faj-Rl
instcombine transforms
```
define void @src10(i64 %src1) {
entry:
%1 = trunc i64 %src1 to i16
%2 = sext i16 %1 to i32
call void @use.i32(i32 %2)
ret void
}
```
into
```
define void @tgt10(i64 %src1) {
entry:
%1 = trunc i64 %src1 to i32
%2 = shl i32 %1, 16
%3 = ashr exact i32 %2, 16
call void @use.i32(i32 %3)
ret void
}
```
which should not be desired as the number of instructions increases.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysk9Fq4zwQhZ9mfDMkWGM7ji980TYY_ruffQNZHsfqylKQ5KTt0y9y0qZll2UXFgJBzHeMztEcGYI-WuYWqkeoDplc4uR8e2H7vGwmzno3vLb_G5aBUU2svqM7RXRLPC0RtcUpxlOA4gGoA-qk0WemrTHneev8EahTDNS9AXWjfN58M5AfIH_QNkTl5l5bxuilDaPzc7jOYJfffutx4DFRZ6cHhDIPXokcaK93JQJV6QjUINSPV5xt9K_pOusJEyMQigNGv1iFn2QYHWqx-wTSCgZ-iWlwlSaooHdISWM-rrIE3qYZ7XVBqx6oeSc9xxW8eaoPvzSnbXR_4joe4790fTd0dz0ZvNkQQE_4JZhiRWSYPPKLVBHvhj-Tv0-n-Ot0LpNWE4bJLWZA6yL2jAMH7XlAGTBOjHaZe_boRkwr5RcVtbMBtVU-bWzYZkNbDE3RyIxbUReibEpR1NnUDuPQlzuhGq5Uz9yUldrVNQk5yibPG8p0SzmVQohC5EVV1NtK1qJo6mHPY1lWO4Yy51lq87HtmQ5h4VaIXS6azMieTVhrRWT5gusUiFLLfJtEm345Bihzo0MM989EHc3ax_9siE_XmkB1wFmHwEPqn571m0xWoXhYFxZovz410P4l5UwN6nCvFg_p3dMDAu3DZH7Gb6LLxDYF6znprUM1Sas4qUdnhmzxpv3a-KOO09JvlZuBumTh9rc5effMKgJ1q_EA1N2SObf0IwAA__-qR0ya">