<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/155040>155040</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[Reassociate?] Optimizing redundant common factor multiplications
</td>
</tr>
<tr>
<th>Labels</th>
<td>
llvm:optimizations,
missed-optimization
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
vzakhari
</td>
</tr>
</table>
<pre>
Is there a pass in LLVM that can optimize this pattern https://godbolt.org/z/hdKsj4nc4?
The expression `a*b + a*c + a*b*d` may be optimized into `a*(b + c + b*d)` saving one multiplication.
It looks like ReassociatePass cannot optimize this due to the single-use check for adding the expression into the tree. Is this a hard limitation?
@RKSimon can you please comment?
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJxcklFvo0oMhX_N8GIlAgNJeOAhvRVS1V7dq-5q34cZJ0wzzKCxibb99StIt9vtExbm4HM-WzO7cyBqVX2n6vtMzzLE1F7f9GXQyWV9tK_tA4MMlAg0TJoZXICnpx__ggxawOgAcRI3ujcCGRzDpEUoBRhEJlblUWGnsDtH20cv25jOCrs3hd1gH_mlCqZSZafyo8qP3wcC-jklYnYxgNrlWuGxB4V3sFTmo-oVHq3a5TDqV-jpw4EFFyT-Vio83MQ34U2EzaJjfXXhDDEQjLMXN3lntLgYtjcrDwI-xguDdxeCZ9LM0Tgt9P9CwOgQonzJbWcCiQsqYBfOnjYzE5iBzAVOMYG2dhkpf4dc_S7vJBFtAVbYjkHDoJMF70Ynq7EPSqrKnx-_uTGGFf5rnGHypJdZcRwpiCq7zLalbcpGZ9QW-7pu8vzQFNnQ4n5f7Czq2uybU1mWfbPbFXXVkCXSBvvMtZhjnR8QEYuqLrb1_tCbsul3BzztKypVldOond96fx2XdWaOeaa2qOu8yjOve_K83hPi8okqj--c1hisEBX-oxBHx0x287m59Or7LLWLcNPPZ1ZV7h0L_5kmTvx6r5-WsrCp7-G_268WyonsHKwOskKJAU7aSExfls3ZnHz75VCdDHO_NXFU2K0Bbo_NlOILGVHYrYFZYfee-drirwAAAP__O_sT9Q">