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

    <tr>
        <th>Summary</th>
        <td>
            [VectorCombine] foldInsExtVectorToShuffle can't handle length changing shuffles
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

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

<pre>
    The VectorCombine::foldInsExtVectorToShuffle fold `insert (DstVec, (extract SrcVec, ExtIdx), InsIdx) --> shuffle (DstVec, SrcVec, Mask)` is limited to cases where the DstVec/SrcVec are the same vector type, but it might still be cost beneficial to fold these for non matching shuffles assuming any shuffle narrowing/widening for SrcVec is cheap enough.

```ll
define <4 x double> @ins0_v4f64_ext1_v2f64(<4 x double> %a, <2 x double> %b) {
  %ext = extractelement <2 x double> %b, i32 1
  %ins = insertelement <4 x double> %a, double %ext, i32 0
  ret <4 x double> %ins
}
define <2 x double> @ins1_v2f64_ext1_v4f64(<2 x double> %a, <4 x double> %b) {
  %ext = extractelement <4 x double> %b, i32 1
  %ins = insertelement <2 x double> %a, double %ext, i32 1
  ret <2 x double> %ins
}
```

InstCombine will handle some 'easy' cases, but ideally we need VectorCombine to handle this more generally as a cost driven combine.

CC @ParkHanbum who handled something similar recently for #115209
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyMVF1vqzgQ_TXmZdTIGBLCAw-5SaOtViuttlf7WhkYsPcau7KHfPz7lYH0tre5UiOkyB_neObMzJEh6N4iVmz9ja0PiRxJOV_98-ezHpxNatdeq-8K4V9syPm9G2ptkWU7lu06Z9onGx4vNB9-d89q7DqDEE-Abbi2AT0BE9tDiJeY2McFXsjLhuDZN8vm44We2gsTZVw82TAv4OGBZY8QFtYPND-xf8nwIyI3HHQAowdN2AI5aGTAAGeFHoEUwg18nLEgl_0gB4TTlALQ9RUjaT0SaIJB94ogkDYGaoTGBYIaLXa60dLER6ZUSWGIWXuwzsIgqVHa9rfAA8gQxiHuSHt9S8dK791Z256J41m3aOOFyLGEpwM0CuUroHVjr1aM7-K34fNnDOO7FjttEVi2z-ECrRtrg1Eylkft-csp7zb5C14ofTmJbpMzsf18V6zlVJhsL349qGMVWPGN8R3ENV4IWHaApYJocEBLv4PuQWcC0htY2zCB5654h70fz7yzvHoj4xOZx_s4bUOUqDh8kEbckWbRY5Emf5PmUxo3aT699XVp7kG_Ks39eO5Kk76X5hPuvTRvPTS31JMNtAw2nGOnK2lbgxDcEN8oUIYrE8U8T2_D0aI05gpnBIvYfvSHOBgLCSkdYHAeoUeLfsLIAHKepdbrE1poZtjS4vt9LNLf0v_4Q9p6HOCsbnTtFBTN06UHbaQHjw1aMtdpdpjI0nQteJm0VdaWWSkTrNIiy4s024p1oqo8T-s02_KyENscJW7qos2bIt9Kwbd5JxJdCS7yVAiebtYFX6_KoixkyUvMivjrWM5xkNqsjDkNK-f7RIcwYpUKXhQiMbJGEyY_FcLiGaZTJkS0V19F0EM99oHl3OhA4ScNaTKTEX802_UBfm-1jbRMFHST26DtSUGjpO3fW1AyelMpotcQvVscmTj2mtRYrxo3MHGMMSx_D6_e_YcNMXGcIg9MHJfUTpX4PwAA__94__GI">