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

    <tr>
        <th>Summary</th>
        <td>
            [AArch64] Two large shifts and a combine can be a single combine and shift
        </td>
    </tr>

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

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

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

<pre>
    https://godbolt.org/z/1d3969GrG

```
#include <arm_neon.h>

/*
        ushr    v0.4s, v0.4s, #20
        ushr v1.4s, v1.4s, #20
        uzp1    v0.8h, v0.8h, v1.8h
*/
uint16x8_t foo(uint32x4_t a, uint32x4_t b) {
    a = vshrq_n_u32(a, 20);
    b = vshrq_n_u32(b, 20);
    return vcombine_u16(vmovn_u32(a), vmovn_u32(b));
}

/*
        uzp2    v0.8h, v0.8h, v1.8h
 ushr    v0.8h, v0.8h, #4
*/
uint16x8_t bar(uint32x4_t a, uint32x4_t b) {
    uint16x4_t a_u16 = vshrn_n_u32(a, 16);
    uint16x4_t b_u16 = vshrn_n_u32(b, 16);
    uint16x8_t r = vcombine_u16(a_u16, b_u16);
 return vshrq_n_u16(r, 4);
}
```
The two shifts and combine in `foo` can be compiled to the same as `bar`. GCC also lacks this optimisation.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVM1y2jAQfpr1RROPtLKNdfCBQMkDNHdGshWsxraoJJOUp-_ImAAZmkwZBq1X37c_3-KV3pvdoHUF-SPk60SOobWu-in7Z62U5zxRtvlTtSHsPfAl4AZws7ONsl1IrdsBbo6AG9ZwUYgn9wR0DXQ5_xZ0_p4ekZuh7sZGE-Ar6frtoO2QtsB_3LBiitkm82f0rYvngaaZB1xdDECO9A74wM5I9gXyuGdz2LKdw84Gi8Zcz1TSZI9mCKx4L7eBvFgLWEYHx_dsG4iMvKtnBSgILB4vKSUBviYH37rf22E7cgQsJxZSQAH8CqruQNV9qNNhdAM51LZXZtDbkRWA5aG3h6scYmrqyqcm3yUSLNbfDuG4x2_Vuh7VJxQgz76UVEn3v5LO7AkcO_-QbbhVOGpyK9sVU_2Dqb5kxordiXUrvTydq1PcG_Z5Vue5TngXsdn9Ydy-Qc-tJuHNEt-al-CJHBoypyZmIFDQ-KcsKKnlQJSOd3vT6YYES0KriZe9JtJHYJS6oCl5Wq2I7LwlnaxfPQmt8cTug-mNl8HYIU2aijeCC5noihULKnIqhEjaChcF47ViuXphqi7yrM4XTFEtuKwbUS8SUyFFZMg4W1DORCqyQhUlb5jKaJmLEjKqe2m6tOsOfdwlifF-1FUucopJJ5Xu_LSWEJWsX_XQAF8ul65uiwwQAVeA2BvvdfNwqvk41Rzv8nXiqhj3QY07DxntjA_-kimY0E077xwvX5PntyiD2-lrfeWHwrOokngz7Dr94Y-oiZCMrvu8KE1oR5XWtgfcxOTz8bB39peuA-Bm6tkDbqa2_wYAAP__hyCRpQ">