<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/120764>120764</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[VectorCombine] foldShuffleOfShuffles - failure to merge nested shuffles with common operands
</td>
</tr>
<tr>
<th>Labels</th>
<td>
missed-optimization,
llvm:transforms
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
RKSimon
</td>
</tr>
</table>
<pre>
```ll
define <4 x double> @add_v4f64_u123(<4 x double> %a, <4 x double> %b) {
%1 = shufflevector <4 x double> %b, <4 x double> %a, <4 x i32> <i32 poison, i32 0, i32 6, i32 poison>
%2 = shufflevector <4 x double> %b, <4 x double> %a, <4 x i32> <i32 poison, i32 1, i32 7, i32 poison>
%3 = shufflevector <4 x double> %1, <4 x double> %b, <4 x i32> <i32 poison, i32 1, i32 2, i32 6>
%4 = shufflevector <4 x double> %2, <4 x double> %b, <4 x i32> <i32 poison, i32 1, i32 2, i32 7>
%result = fadd <4 x double> %3, %4
ret <4 x double> %result
}
```
All shuffles only have 2 operands, so we should be able to fold to:
```ll
define <4 x double> @add_v4f64_u123(<4 x double> %a, <4 x double> %b) {
%1 = shufflevector <4 x double> %a, <4 x double> %b, <4 x i32> <i32 poison, i32 4, i32 2, i32 6>
%2 = shufflevector <4 x double> %a, <4 x double> %b, <4 x i32> <i32 poison, i32 5, i32 3, i32 7>
%result = fadd <4 x double> %1, %2
ret <4 x double> %result
}
```
Pulled out of #34072
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzMVUFv2zwM_TX0RUggU1LcHHxIk-byHb5hBXYtZIuKNchWYMnpul8_2KnXAkuLthuGAYZNmSL5TL5n6RjdoSMqQV2D2mV6SE3oy8__3bo2dFkVzEMJK36-vAe-MWRdRwzEVrJvzISh8gTihoHk2pi7k7QreTfkKACvft2ESgNuL0SjqgDXDIpr4Bs2rnMGYsdiM1jr6UR1Cv1LcZcTPq_kBE5vxdYJZMfgYuhG97jis7GajUe_uJmx4N_Cks9G8SIW8UYs-SuNfh8WfGrQGQagkm9EgX8eRfGsGT3FwacJi9XGXKwkpkqo5BTUU7q465wJ-AaK3XifSQ98s_F-_tLIQucfWKNPxJCFI_W6M3EsEAO7JxabMHjDKmK68sRSYDZ4w1IAsXme9d-U0msJ3zQs-SJl3qOi34ahZkN8lDP5I2fwo5z5NHhPhoUhsWAZoBCSF5iZUpi1WOuMyrwQsshzLIqsKRVpsa64ltxak6O2SMW6QitrfSWExMyVyFHmiDxf5VIUS1XXhV4JxZWiNaEEyanVzi-9P7XL0B8yF-NAZY68WMnM64p8nH7ziK2LkcwiHJNr3Xed3Ni6cWSAOIaD2KRed9GGvo2jR-2yvhw9i2o4RJDcu5jiU6nkkp_OkC_TVLehrVxHoHYT_W_PE__f3s4iWjCrnR_6SSEt9QdiHcVE5kln9y41rA5tG7qfOsuG3pdNSsc4ygn3gPuDS81QLevQAu4n7OfH4tiHr1QnwP3Uhwi4f2zFqcQfAQAA__93s_cc">