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

    <tr>
        <th>Summary</th>
        <td>
            [VectorCombine] foldShuffleOfShuffles - failure to fold shuffle(shuffle(x,y),undef) length changing masks
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            llvm:instcombine,
            missed-optimization
      </td>
    </tr>

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

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

<pre>
    ```ll
define <8 x float> @shuffle(<4 x float> %a0, <4 x float> %a1) {
  %x = shufflevector <4 x float> %a0, <4 x float> %a1, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>
  %y = shufflevector <8 x float> %x, <8 x float> poison, <8 x i32> <i32 0, i32 4, i32 1, i32 5, i32 2, i32 6, i32 3, i32 7>
  ret <8 x float> %y
}
```

foldShuffleOfShuffles currently fails to merge "permute of shuffle" patterns if the vector length changes

But it will happily fold:

```ll
define <4 x float> @shuffle2(<4 x float> %a0, <4 x float> %a1) {
  %x = shufflevector <4 x float> %a0, <4 x float> %a1, <4 x i32> <i32 0, i32 4, i32 5, i32 3>
  %y = shufflevector <4 x float> %x, <4 x float> poison, <4 x i32> <i32 0, i32 3, i32 1, i32 2>
  ret <4 x float> %y
}
->
define <4 x float> @shuffle2(<4 x float> %a0, <4 x float> %a1) {
  %y = shufflevector <4 x float> %a0, <4 x float> %a1, <4 x i32> <i32 0, i32 3, i32 4, i32 5>
  ret <4 x float> %y
}
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzMVU2PozgQ_TXFxUoEZSBw4JAmncseVtqW9s5HGbxrMMKmJ5lfPzIJSX8w3S2NRhoJwZNddj1XPT8KY2TTE2UQPUB08IrJtnrM_vnrSXa690pdnzOI_cujFPj7moTsiQHPE3ZiQunCAn9kEPqmnYRQBJgAz8NXkxgVPmDO1iYCwJTB7gH8PXMDJwb8wK6bPVNl9bi67qMN84Wf5DgP81xyZPMSB4IF4AL4AsIFRAuIF7AD_riwPK-zTN6QOb3gchsftDS6_5xl-I5u9I53_O4AN5Yj2TVKZ_D3sDu499JYh_290Kp-uhzob3EFhlXTOFJv1ZmJQirDrGYdjQ0xQBxo7CZLTAt2az6yobCWxt4wKZhtiV2ro6hvbMuqtugbMpeUD5Nl0rJvUinWFsMgXRqtauD7S8DPtBeuaw__GPGFX2hrdO_dp8J6m-i0RuCVsD5gwFfuwWvRvE13F83mEvn7W_HFQvxSK9Zu_VcLcZOmV2e8TnlaeJQFu8hHvkvDxGszjGMS4U7UaZj4hLWfBFQQj8tdLRIMhCcz9DHy4yDx0wAx2dZlFVQpp0RUNYoyhtCnrpBqq9Rzt9Vj40ljJsqCMIyj2FNFScrM3o3oQoDvZW9spbtS9u4yAuaA2EljqN7owcpOfi-sdCJB5_dj5pZtyqkxEPpKGmvuuay0av4z_DtXP7_uGh3YulVsZouYRnIm4ULurpDckVPuGTAFzKe-JuHa_tIbZN-wrjD_G28aVdZaOxhnB3gEPDbStlO5rXQHeJwPfPlshlH_R5UFPM4FMoDHa42eM_wRAAD__6hT76g">