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

    <tr>
        <th>Summary</th>
        <td>
            clang is suboptimal for `-a * (-a * a)`
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang
      </td>
    </tr>

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

    <tr>
      <th>Reporter</th>
      <td>
          k-arrows
      </td>
    </tr>
</table>

<pre>
    Consider the following two functions.
https://godbolt.org/z/Taza3zT3G
```cpp
int foo(int a) {
    return -a * (-a * a);
}

int bar(int a) {
    return (-a * -a) * a;
}
```

I expect the following output for both functions.
```llvm
        mov     eax, edi
        imul    eax, edi
        imul    eax, edi
        ret
```

But interestingly, the output of Clang is better than that of GCC for the following function.
https://godbolt.org/z/17qvs9xcd
```cpp
int foo1(int a, int b, int c) {
    return -a * (-b * c);
}
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJykU9tu2zAM_Rr6RUhg0bf6wQ9tChd77w_IsuJoUyxPonr7-kFy0qwXrAVmGBZhEkc8PIfCez3NSnVQ3UB1m4lAB-u6XxvhnH302WDH525nZ69H5RgdFNtbY-yjnidGj5btwyxJ29lvIb-F_PpAtHgorgF7wH6y42ANba2bAPsXwP5evIji5b64W8uhztdXLsv6R8_E9tYCXsVIALYMmps1xxhjTlFwM9sIBnjNAK9OUayE4lQIze0peMUchPsK8wK2WWsS7EfMc89_X_GDqadFSXo3IhtoCZGQY4Olw4dxvWIZ83C8NBSfo31IpxJPgDumRv02r4_B_E_eKfoHn5tATM-knPKk58k8R4zI7cTI7tnOiHli2rNBESVziDl-UvJut0us347jTP-bZuHN7wffPsnxC7Pwi7I7lsQ-B_Ib_hlSJD_3z_nKbOyKsS1akamO123bNjyvi-zQtbmUFSIv8xalKLgaEQcurvaVasZSVJnuMMeCc17ykvO82PJCNi2XrRqwLsq6gjJXR6HNNnogss-090F1DWLVZkYMyvi0nogyjhwQ46a6LtZvhjB5KHOjPfkLAmkyqpNnhXwY7EL6KEwSBer88_2p8yw4073TRdMhDFtpj4B98ul6bBZnfypJgH1q2AP2qec_AQAA__8IdTzn">