<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - [SLPVectorizer] Failure to keep complex math vectorized"
   href="https://bugs.llvm.org/show_bug.cgi?id=44008">44008</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[SLPVectorizer] Failure to keep complex math vectorized
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Windows NT
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Scalar Optimizations
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>llvm-dev@redking.me.uk
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>a.bataev@hotmail.com, craig.topper@gmail.com, dtemirbulatov@gmail.com, llvm-bugs@lists.llvm.org, spatel+llvm@rotateright.com, v.porpodas@gmail.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre><a href="https://godbolt.org/z/YgBdFz">https://godbolt.org/z/YgBdFz</a>

#include <complex>

std::complex<float> mul_f32(std::complex<float> &A) {
    return (2.0f * A);
}

std::complex<float> fma_f32(std::complex<float> &A, float B) {
    return (2.0f * A) + B;
}

for the simple mul case we manage to keep the real+imag components vectorized
as a <2 x float>:

clang -g0 -O3 -march=btver2

mul_f32:
  vmovsd (%rdi), %xmm0 # xmm0 = mem[0],zero
  vaddps %xmm0, %xmm0, %xmm0
  retq

but with the fma case, we end up scalarizing:

fma_f32:
  vmovsd (%rdi), %xmm1 # xmm1 = mem[0],zero
  vmovshdup %xmm1, %xmm2 # xmm2 = xmm1[1,1,3,3]
  vaddss %xmm1, %xmm1, %xmm1
  vaddss %xmm2, %xmm2, %xmm2
  vaddss %xmm0, %xmm1, %xmm0
  vinsertps $16, %xmm2, %xmm0, %xmm0 # xmm0 = xmm0[0],xmm2[0],xmm0[2,3]
  retq

Ideally this would be:

fma_f32:
  vmovsd (%rdi), %xmm1 # xmm1 = mem[0],zero
  vaddps %xmm1, %xmm1, %xmm1
  vaddss %xmm0, %xmm1, %xmm1 # xmm1[0] += xmm0[0]
  vmovaps %xmm1, %xmm0
  retq</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>