<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/83414>83414</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [X86] Failure to merge X86ISD::CVTPH2PS nodes
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            backend:X86,
            missed-optimization
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          RKSimon
      </td>
    </tr>
</table>

<pre>
    ```ll
define <4 x i32> @fptosi_2f16_to_4i32(<2 x half> %a) {
  %cvt = fptosi <2 x half> %a to <2 x i32>
  %ext = shufflevector <2 x i32> %cvt, <2 x i32> zeroinitializer, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
  ret <4 x i32> %ext
}
```
llc -mcpu=x86-64-v3
```asm
fptosi_2f16_to_4i32: # @fptosi_2f16_to_4i32
        vpshufb .LCPI0_0(%rip), %xmm0, %xmm1    # xmm1 = xmm0[2,3],zero,zero,zero,zero,zero,zero,xmm0[u,u,u,u,u,u,u,u]
        vcvtph2ps       %xmm1, %xmm1
        vpmovzxwq       %xmm0, %xmm0            # xmm0 = xmm0[0],zero,zero,zero,xmm0[1],zero,zero,zero
        vcvtph2ps       %xmm0, %xmm0
        vunpcklps       %xmm1, %xmm0, %xmm0     # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
        vcvttps2dq      %xmm0, %xmm0
        vmovq   %xmm0, %xmm0                    # xmm0 = xmm0[0],zero
        retq
```
Latest trunk now gives the above assembly, ideally we would only have a single vcvtph2ps node, and avoid all the shuffles which are just trying to move elements into the lowest element:
```asm
fptosi_2f16_to_4i32:                    # @fptosi_2f16_to_4i32
        vcvtph2ps       %xmm0, %xmm0
        vcvttps2dq      %xmm0, %xmm0
        vmovq   %xmm0, %xmm0                    # xmm0 = xmm0[0],zero
        retq
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMVU1zozgQ_TXi0uWUaIENBw6JWddO7RxSm62tuaVkaBtNBGKQwE5-_ZYwHrNZeyZ7m1RcNOrXrfeePpDWqn1DlLH4gcV5IHtXmS77848nVZsm2JryNWNLfvrXmvGc8fuSdqohYGIdwRGUQCZ-AxbxXeuMVc-4C5fPzjxHPoMJE2uEI1RS70YcxpJhCmz1cOoGfqgYHDCRw6kFXKkBZ87Dpxln1XQ8Vduq3-00DVQ40_0bPU3CcP1u_I06oxrllNTqjboJMBcm1kogcJ_xQXgO8ByIGZuO3Pv6kd8pz1b5FJw9Pb1qXcCiLtqeifyYLBfLaDGId0hp69PINZvFPTAUtxbh1IinQ-sd2jKe3n1eP37iz9yvD8adahmmo3SMj3XNL2EIAGPrMfYmj_n4wasXLM4Zrr2FH3tMtT3D9e1fnF8IF4NrK2wt4-nEZ0Ztpqs2w9vx8O07bKaAw-xvUsLnSvgPVEyQ8CbkNtM5hQusb9riRV8X9B_SP2A7Vs7fZjSnXPjeSddaLK97dMHVZvi5jR-189y1I_ft6sb_LB1ZB67rmxdozAH2aiALriKQWzMQSGup3urX8ayVJLV-hQPBwfS6BNPoV6ikh4FVzV4TfF8HaExJvko2JcjBqBKk1mPn6ZqwcKhUUYHsCL72I4tX1ez9RVP7qUlTTY2zoBpnxkJtDp7tlGDi_n8e0RsO_uzUfnBr_WorHJSZKFORyoCycMVT5CtMeVBl6Y6WIt6Fq4JkvAplvCyLJOVyhVESY5IEKkOOEUdMwzBKeHq3K3lYhtsIsRCcYs4iTrVU-k7rob4z3T5Q1vaUJSIKo0DLLWk7ftIQt7J4oaZk4v5LsmTory2GWCtrqVyY1qlavUmnTONzcR50me-52PZ7yyKulXX2MotTTo_fSt8rzmEjle47GrcMdXuCL8ny01Pud4a4X__91-Pv-Pg07kQb9J3OKr9CPosbhpu9clW_vStMzXDj55gei7YzX6lwDDejLMtwMyr7JwAA__9n-SsL">