<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/69862>69862</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Optimization for `pow(x, i1) * pow(x, i2)` (X86 vs ARM)
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
k-arrows
</td>
</tr>
</table>
<pre>
Consider the following:
```cpp
#include <cmath>
double f1(double x)
{
return pow(x, 3) * pow(x, 1);
}
double f2(double x)
{
return pow(x, 4);
}
```
(X86) https://godbolt.org/z/nd3ME13Po
(ARM) https://godbolt.org/z/z5vjnPhrK
On X86, if `-Ofast` is specified, GCC just calculates `x * x * x * x` for `f1` with two `mulsd`, but Clang performs `mulsd` three times. There is no such difference on ARM.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJycU8Fu4zgM_Rr5QiSQqcSxDz6kbr2HRdGi2MNebYuK1ZUlQ5Kbbr9-ICedyQx6GAxgyBKpp0c-PHYh6JMlqtn-ju3vs26Jo_P1f5vOe3cOWe_k_3XjbNCSPMSRQDlj3FnbExNHxu8ZP7KCX75hnq8RFNoOZpEETDTD1MWRiYdrbl2lW3pDoHKG5XX_zrC6XjncXTYAAJ7i4i3M7sywfGfYgGBYAcPjbSxPYHH3ib__igv_gGv39bufHd_SMCz_LYtU2xjjHJI82DJsT072zsSt8yeG7QfD1krx-JCLZ_cdeHx5_B3gx_7t1T6P_u9b3icLK28DWgEr-OZJdSGygoMOEGYatNIkU_6vpoHXJUQYOjMsposUEuB9FfOnNaGV8ymr8nQ46zhCPLsUmRYTZGoeG-iXCI3p7Alm8sr5KdzegDh6Ioh6orCFf0bylIqyDsIyjCC1UuTJDgTOwvHlcZvJWshKVF1GdV5Uh2qX5wXPxlqKneKkynLI1aEvy101lFKVouyLareXeaZr5Chyjsgxr5BvOe-LgySqBMdBkWA7TlOnzdaYtylpmukQFqqLqiwwM11PJqxTgGjpDGuSIaah8HXCbPrlFNiOGx1i-PFK1NFQ_TRHPemPLmpnP5W7sZHOv_CsxmSugsPFOfAW4OKDbPGm_sULOo5Lvx3cxLBN3NffZvbulYbIsF0rDgzbtaNvAQAA__8w-h3c">