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

    <tr>
        <th>Summary</th>
        <td>
            `addsubpd` not generated in complex multiplication since LLVM 13
        </td>
    </tr>

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

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

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

<pre>
    Consider the following program that multiplies double complex numbers.

```
__m128d _mm_complexmult_pd(__m128d a, __m128d b)
{
    __m128d A;
    A[0] = a[0]*b[0];
    A[1] = a[0]*b[1];

    __m128d B;
    B[0] = a[1]*b[1];
    B[1] = a[1]*b[0];

    return _mm_addsub_pd(A, B);
}

__m128d _mm_complexmult_pd_naive(__m128d a, __m128d b)
{
    __m128d A;
    A[0] = a[0]*b[0] - a[1] * b[1];
    A[1] = a[0]*b[1] + a[1] * b[0];
    return A;
}
```

The first one use explicit addsubpd, the second one not.
In LLVM 12, `_mm_complexmult_pd_naive` is faster.
In LLVM 13, `_mm_complexmult_pd` is faster because addsubpd is not generated anymore unless in simpler cases.

Godbolt: https://cpp.godbolt.org/z/sMdh7eG4s
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy9VEtv2zAM_jX2hWggy4_EBx-cBisGtLdh10C2GEeDLBmS3Md-_Wgn7pqmwW4z_KBE8uOnT7QaK9-qe2u8kuggHBEOVmv7okwHg7OdEz3NigD9qIMatEIP0o6NRmhtP2h8BTP2DTq_itguYvX5XbDzPQ_3-z7hGwn7vt-f0ya8_SAjvlmcIuL3sAyaiJdnqPX2ZABdi7uO0g-zdZRvWZTvIEp3BHMaRLxuFvNzcHIjOPkYfF11ewG0_Vw1uQG0BCc3gtnXVR2G0ZlZMyGlH5uTXPUk03aS5z1lvfuYe1vsvRHqGf-L5HD3vkqgafhSlH9tBWVur2GudvQsVP2FIJdteHr_mJpcOR_AGoTRI-ArNXarApx0nmS-n_8Fj601co4zNpw7_LuBx8efT5DwKYzAbwpdMFAeDsIHdJ-T05vJF2nQYCsmjgu1yUVcoEODTgSkTTRvvXW0EqPRe1AGvJrwHLTC4-V_-WBlY3WI0hqOIQyejIh_o7sdhlV3cq6s62jmNz3-SR7X-JD5GKukKLLNukyLPJZVKsu0FHFQQWNFhN-FI-6X7IjOclAsR0grgrITS9PiokY8Ol1dUupUOI7NirJpoPXz8rmjc-kXtoGGyvsRPRn5JknL-FjJpBWCHRqBLMuzsmWykHnBMU1Ysi7FIdaiQe0raqOIc4MvMEOQTU0Vq4ozzhPGsoTxkuerw0HILE95m-YTQBplDHuh9GriMekUu2qm1IydJ6dWPvi_TuG96gziXI7wxRiO1lUDo4XHc-FqJv4HfeeR2Q">